Token.hs revision 72b8c0349a58cf0eb361cb5bb410d95a0372900a
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederModule : $Header$
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerDescription : parser for CASL 'Id's based on "Common.Lexer"
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederCopyright : (c) Christian Maeder and Uni Bremen 2002-2004
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederMaintainer : Christian.Maeder@dfki.de
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederStability : provisional
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederPortability : portable
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederParser for CASL 'Id's based on "Common.Lexer"
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder{- http://www.cofi.info/Documents/CASL/Summary/
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder from 25 March 2001
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder C.2.1 Basic Specifications with Subsorts
20bd79f8844604c145510c616fecdaf47eba2fdbChristian MaederSIMPLE-ID ::= WORDS
20bd79f8844604c145510c616fecdaf47eba2fdbChristian MaederID ::= TOKEN-ID | MIXFIX-ID
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederTOKEN-ID ::= TOKEN
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaederMIXFIX-ID ::= TOKEN-ID PLACE-TOKEN-ID ... PLACE-TOKEN-ID
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder | PLACE-TOKEN-ID ... PLACE-TOKEN-ID
d3f192025f2836285d9705a959542350e057f281Christian MaederPLACE-TOKEN-ID ::= PLACE TOKEN-ID
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederTOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder SIGNS are adapted here and more permissive as in the summary
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder WORDS and NO-BRACKET-SIGNS are treated equally
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder legal are, ie. "{a}", "{+}", "a{}="
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder illegal is "a=" (no two SIMPLE-TOKEN stay beside each other)
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder SIMPLE-TOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder | NO-BRACKET-SIGNS
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder STB ::= SIMPLE-TOKEN BRACKETS
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder BST ::= BRACKETS SIMPLE-TOKEN
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder SIGNS ::= BRACKETS
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder | BRACKETS STB ... STB
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder | BRACKETS STB ... STB SIMPLE-TOKEN
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder | SIMPLE-TOKEN
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder | SIMPLE-TOKEN BST ... BST
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder | SIMPLE-TOKEN BST ... BST BRACKETS
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder A SIMPLE-TOKEN followed by "[" outside nested brackets
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder will be taken as the beginning of a compound list.
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder Within SIGNS brackets need not be balanced,
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder only after their composition to a MIXFIX-ID.
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder BRACKETS = BRACKET ... BRACKET
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder BRACKET ::= [ | ] | { | }
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder 2.4 Identifiers
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian Maeder brackets/braces within MIXFIX-ID must be balanced
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder C.2.2 Structured Specifications
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder TOKEN-ID ::= ... | TOKEN [ ID ,..., ID ]
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder A compound list must follow the last TOKEN within MIXFIX-ID,
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder so a compound list is never nested within (balanced) mixfix BRACKETS.
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder Only PLACEs may follow a compound list.
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder The IDs within the compound list may surely be compound IDs again.
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder-- * Casl keyword lists
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder-- | reserved signs
9f93b2a8b552789cd939d599504d39732672dc84Christian Maedercasl_reserved_ops :: [String]
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maedercasl_reserved_ops = [colonS, colonQuMark, defnS, dotS, cDot, mapsTo]
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder-- | these formula signs are legal in terms, but illegal in declarations
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederformula_ops :: [String]
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maederformula_ops = [equalS, implS, equivS, lOr, lAnd, negS]
d3f192025f2836285d9705a959542350e057f281Christian Maeder-- | all reseverd signs
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedercasl_reserved_fops :: [String]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedercasl_reserved_fops = formula_ops ++ casl_reserved_ops
d3f192025f2836285d9705a959542350e057f281Christian Maeder-- | reserved keywords
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedercasl_basic_reserved_words :: [String]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedercasl_basic_reserved_words =
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder [axiomS, axiomS ++ sS, cogeneratedS, cotypeS, cotypeS ++ sS,
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder esortS, esortS ++ sS, etypeS, etypeS ++ sS,
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder existsS, forallS, freeS, generatedS,
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder opS, opS ++ sS, predS, predS ++ sS,
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder sortS, sortS ++ sS, typeS, typeS ++ sS, varS, varS ++ sS]
66ea26416f702f5e00759ffc767f0f785cc86058Christian Maeder-- | reserved keywords
d3f192025f2836285d9705a959542350e057f281Christian Maedercasl_structured_reserved_words :: [String]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedercasl_structured_reserved_words = libraryS :
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder continuationKeywords ++ otherStartKeywords
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder ++ criticalKeywords
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | keywords terminating a basic spec or starting a new library item
d3f192025f2836285d9705a959542350e057f281Christian MaedercriticalKeywords :: [String]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercriticalKeywords = terminatingKeywords ++ startingKeywords
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | keywords terminating a basic spec
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederterminatingKeywords :: [String]
d3f192025f2836285d9705a959542350e057f281Christian MaederterminatingKeywords =
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder [andS, endS, fitS, hideS, revealS, thenS, withS, withinS]
d3f192025f2836285d9705a959542350e057f281Christian Maeder-- | keywords starting a library item
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederstartingKeywords :: [String]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederstartingKeywords =
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder [ archS, fromS, logicS, newlogicS, refinementS, specS, unitS, viewS
d3f192025f2836285d9705a959542350e057f281Christian Maeder , ontologyS, alignmentS, networkS, equivalenceS, newcomorphismS
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder , interpretationS ]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | keywords that may follow a defining equal sign
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederotherStartKeywords :: [String]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaederotherStartKeywords =
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder [closedS, cofreeS, freeS, localS, unitS ++ sS, combineS]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | other intermediate keywords
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedercontinuationKeywords :: [String]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedercontinuationKeywords =
d3f192025f2836285d9705a959542350e057f281Christian Maeder [ behaviourallyS, getS, givenS, lambdaS, refinedS, resultS, toS, versionS
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder , excludingS ]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder-- | reserved keywords
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedercasl_reserved_words :: [String]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedercasl_reserved_words =
d3f192025f2836285d9705a959542350e057f281Christian Maeder casl_basic_reserved_words ++ casl_structured_reserved_words
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder-- | these formula words are legal in terms, but illegal in declarations
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederformula_words :: [String]
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maederformula_words = [asS, defS, elseS, ifS, inS, whenS, falseS, notS, trueS]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder-- | all reserved words
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedercasl_reserved_fwords :: [String]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedercasl_reserved_fwords = formula_words ++ casl_reserved_words
d3f192025f2836285d9705a959542350e057f281Christian Maeder-- * a single 'Token' parser taking lists of key symbols and words as parameter
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder{- | a simple 'Token' parser depending on reserved signs and words
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder (including a quoted char, dot-words or a single digit) -}
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedersid :: ([String], [String]) -> GenParser Char st Token
-- | like 'varId'. 'Common.Id.SIMPLE_ID' for spec- and view names