Token.hs revision 98890889ffb2e8f6f722b00e265a211f13b5a861
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuModule : $Header$
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerDescription : parser for CASL 'Id's based on "Common.Lexer"
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuCopyright : (c) Christian Maeder and Uni Bremen 2002-2004
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceLicense : GPLv2 or higher, see LICENSE.txt
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuMaintainer : Christian.Maeder@dfki.de
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuStability : provisional
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuPortability : portable
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuParser for CASL 'Id's based on "Common.Lexer"
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu{- http://www.cofi.info/Documents/CASL/Summary/
ed1b8e97e72b2e3e92edaf2eb22a4b5373d705f1Felix Gabriel Mance from 25 March 2001
386bd8214f3137fe84c392cd58338130d2f80607Felix Gabriel Mance C.2.1 Basic Specifications with Subsorts
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian MaederSIMPLE-ID ::= WORDS
386bd8214f3137fe84c392cd58338130d2f80607Felix Gabriel ManceID ::= TOKEN-ID | MIXFIX-ID
386bd8214f3137fe84c392cd58338130d2f80607Felix Gabriel ManceTOKEN-ID ::= TOKEN
386bd8214f3137fe84c392cd58338130d2f80607Felix Gabriel ManceMIXFIX-ID ::= TOKEN-ID PLACE-TOKEN-ID ... PLACE-TOKEN-ID
386bd8214f3137fe84c392cd58338130d2f80607Felix Gabriel Mance | PLACE-TOKEN-ID ... PLACE-TOKEN-ID
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancePLACE-TOKEN-ID ::= PLACE TOKEN-ID
8dd62da91d8ac7cfa80cfaff34dc87bb4c2c855bFelix Gabriel ManceTOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Mance SIGNS are adapted here and more permissive as in the summary
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder WORDS and NO-BRACKET-SIGNS are treated equally
386bd8214f3137fe84c392cd58338130d2f80607Felix Gabriel Mance legal are, ie. "{a}", "{+}", "a{}="
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance illegal is "a=" (no two SIMPLE-TOKEN stay beside each other)
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder SIMPLE-TOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maeder | NO-BRACKET-SIGNS
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maeder STB ::= SIMPLE-TOKEN BRACKETS
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu BST ::= BRACKETS SIMPLE-TOKEN
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu SIGNS ::= BRACKETS
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu | BRACKETS STB ... STB
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder | BRACKETS STB ... STB SIMPLE-TOKEN
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu | SIMPLE-TOKEN BST ... BST
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu | SIMPLE-TOKEN BST ... BST BRACKETS
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu A SIMPLE-TOKEN followed by "[" outside nested brackets
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu will be taken as the beginning of a compound list.
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu Within SIGNS brackets need not be balanced,
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance only after their composition to a MIXFIX-ID.
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance BRACKETS = BRACKET ... BRACKET
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance BRACKET ::= [ | ] | { | }
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance 2.4 Identifiers
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Mance brackets/braces within MIXFIX-ID must be balanced
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance C.2.2 Structured Specifications
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance TOKEN-ID ::= ... | TOKEN [ ID ,..., ID ]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance A compound list must follow the last TOKEN within MIXFIX-ID,
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance so a compound list is never nested within (balanced) mixfix BRACKETS.
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Mance Only PLACEs may follow a compound list.
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance The IDs within the compound list may surely be compound IDs again.
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance-- * Casl keyword lists
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | reserved signs
1f9274bb2aa44ea236327814dce99946be52e348Felix Gabriel Mancecasl_reserved_ops :: [String]
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maedercasl_reserved_ops = [colonS, colonQuMark, defnS, dotS, cDot, mapsTo]
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maeder-- | these formula signs are legal in terms, but illegal in declarations
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maederformula_ops :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceformula_ops = [equalS, implS, equivS, lOr, lAnd, negS]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | all reseverd signs
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancecasl_reserved_fops :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancecasl_reserved_fops = formula_ops ++ casl_reserved_ops
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | reserved keywords
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroedercasl_basic_reserved_words :: [String]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroedercasl_basic_reserved_words =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance [axiomS, axiomS ++ sS, cogeneratedS, cotypeS, cotypeS ++ sS,
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance esortS, esortS ++ sS, etypeS, etypeS ++ sS,
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance existsS, forallS, freeS, generatedS,
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance opS, opS ++ sS, predS, predS ++ sS,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder sortS, sortS ++ sS, typeS, typeS ++ sS, varS, varS ++ sS]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | reserved keywords
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maedercasl_structured_reserved_words :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancecasl_structured_reserved_words = libraryS :
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance continuationKeywords ++ otherStartKeywords
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance ++ criticalKeywords
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | keywords terminating a basic spec or starting a new library item
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancecriticalKeywords :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancecriticalKeywords = terminatingKeywords ++ startingKeywords
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | keywords terminating a basic spec
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceterminatingKeywords :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceterminatingKeywords =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance [andS, endS, fitS, hideS, revealS, thenS, withS, withinS]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | keywords starting a library item
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancestartingKeywords :: [String]
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel MancestartingKeywords =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance [archS, fromS, logicS, newlogicS, refinementS, specS, unitS, viewS]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | keywords that may follow a defining equal sign
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceotherStartKeywords :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceotherStartKeywords =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance [closedS, cofreeS, freeS, localS, unitS ++ sS]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | other intermediate keywords
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancecontinuationKeywords :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancecontinuationKeywords =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance [behaviourallyS, getS, givenS, lambdaS, refinedS, resultS, toS, versionS]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | reserved keywords
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancecasl_reserved_words :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancecasl_reserved_words =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance casl_basic_reserved_words ++ casl_structured_reserved_words
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | these formula words are legal in terms, but illegal in declarations
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceformula_words :: [String]
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Manceformula_words = [asS, defS, elseS, ifS, inS, whenS, falseS, notS, trueS]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | all reserved words
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancecasl_reserved_fwords :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancecasl_reserved_fwords = formula_words ++ casl_reserved_words
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- * a single 'Token' parser taking lists of key symbols and words as parameter
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance{- | a simple 'Token' parser depending on reserved signs and words
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance (including a quoted char, dot-words or a single digit) -}
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancesid :: ([String], [String]) -> GenParser Char st Token
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancesid (kOps, kWords) = pToken (scanQuotedChar <|> scanDotWords
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> scanDigit <|> reserved kOps scanAnySigns
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> reserved kWords scanAnyWords <?> "simple-id")
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- * 'Token' lists parsers
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | balanced mixfix components within braces
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancebraceP :: GenParser Char st [Token] -> GenParser Char st [Token]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancebraceP p = oBraceT <:> p <++> single cBraceT
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> try (oBracketT <:> single cBracketT)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | balanced mixfix components within square brackets
386bd8214f3137fe84c392cd58338130d2f80607Felix Gabriel MancebracketP :: GenParser Char st [Token] -> GenParser Char st [Token]
1f9274bb2aa44ea236327814dce99946be52e348Felix Gabriel MancebracketP p = oBracketT <:> p <++> single cBracketT
-- | like 'varId'. 'Common.Id.SIMPLE_ID' for spec- and view names