Token.hs revision 083679daeba30fce9d60f7170a2cfd9f9c80bfb2
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek{- |
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekModule : $Header$
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekCopyright : (c) Christian Maeder and Uni Bremen 2002-2004
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekLicence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekMaintainer : hets@tzi.de
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekStability : provisional
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekPortability : portable
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek parser for CASL 'Id's based on "Common.Lexer"
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-}
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek{- http://www.cofi.info/Documents/CASL/Summary/
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek from 25 March 2001
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek C.2.1 Basic Specifications with Subsorts
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekSIMPLE-ID ::= WORDS
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekID ::= TOKEN-ID | MIXFIX-ID
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekTOKEN-ID ::= TOKEN
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekMIXFIX-ID ::= TOKEN-ID PLACE-TOKEN-ID ... PLACE-TOKEN-ID
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek | PLACE-TOKEN-ID ... PLACE-TOKEN-ID
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub HrozekPLACE-TOKEN-ID ::= PLACE TOKEN-ID
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek | PLACE
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekPLACE ::= __
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekTOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina | SIGNS
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina SIGNS are adapted here and more permissive as in the summary
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina WORDS and NO-BRACKET-SIGNS are treated equally
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina legal are, ie. "{a}", "{+}", "a{}="
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek illegal is "a=" (no two SIMPLE-TOKEN stay beside each other)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek SIMPLE-TOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek | NO-BRACKET-SIGNS
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek STB ::= SIMPLE-TOKEN BRACKETS
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek BST ::= BRACKETS SIMPLE-TOKEN
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek SIGNS ::= BRACKETS
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek | BRACKETS STB ... STB
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek | BRACKETS STB ... STB SIMPLE-TOKEN
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek | SIMPLE-TOKEN
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek | SIMPLE-TOKEN BST ... BST
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek | SIMPLE-TOKEN BST ... BST BRACKETS
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek A SIMPLE-TOKEN followed by "[" outside nested brackets
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek will be taken as the beginning of a compound list.
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek Within SIGNS brackets need not be balanced,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek only after their composition to a MIXFIX-ID.
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek BRACKETS = BRACKET ... BRACKET
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek BRACKET ::= [ | ] | { | }
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek 2.4 Identifiers
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek brackets/braces within MIXFIX-ID must be balanced
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek C.2.2 Structured Specifications
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek TOKEN-ID ::= ... | TOKEN [ ID ,..., ID ]
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek A compound list must follow the last TOKEN within MIXFIX-ID,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek so a compound list is never nested within (balanced) mixfix BRACKETS.
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek Only PLACEs may follow a compound list.
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek The IDs within the compound list may surely be compound IDs again.
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek-}
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekmodule Common.Token where
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekimport Common.Keywords
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekimport Common.Lexer
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekimport Common.Id (Id(Id), Token(..), Pos, toPos, isPlace)
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekimport Common.Lib.Parsec
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek-- ----------------------------------------------
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- * Casl keyword lists
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek-- ----------------------------------------------
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek-- | reserved signs
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekcasl_reserved_ops :: [String]
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekcasl_reserved_ops = [colonS, colonS++quMark, defnS, dotS, cDot, mapsTo]
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek-- | these formula signs are legal in terms, but illegal in declarations
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekformula_ops :: [String]
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekformula_ops = [equalS, implS, equivS, lOr, lAnd, negS]
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek-- | all reseverd signs
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekcasl_reserved_fops :: [String]
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekcasl_reserved_fops = formula_ops ++ casl_reserved_ops
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek-- | reserved keywords
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekcasl_basic_reserved_words :: [String]
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekcasl_basic_reserved_words =
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek [asS, existsS, forallS, freeS, generatedS,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek inS, opS, opS ++ sS, predS, predS ++ sS,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek sortS, sortS ++ sS, typeS, typeS ++ sS]
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek-- | reserved keywords
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekcasl_structured_reserved_words :: [String]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekcasl_structured_reserved_words =
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek [andS, archS, axiomS, axiomS ++ sS, closedS, endS,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek fitS, freeS, fromS, getS, givenS,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek hideS, lambdaS, libraryS, localS, logicS,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek resultS, revealS, specS, thenS, toS,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek unitS, unitS ++ sS, varS, varS ++ sS, versionS, viewS, withS, withinS]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | reserved keywords
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekcasl_reserved_words :: [String]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekcasl_reserved_words =
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek casl_basic_reserved_words++ casl_structured_reserved_words
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | these formula words are legal in terms, but illegal in declarations
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekformula_words :: [String]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekformula_words = [defS, elseS, ifS, whenS, falseS, notS, trueS]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | all reserved words
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekcasl_reserved_fwords :: [String]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekcasl_reserved_fwords = formula_words ++ casl_reserved_words
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- ----------------------------------------------
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- * a single 'Token' parser
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- pass list of key symbols and keywords as parameter
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- ----------------------------------------------
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | a simple 'Token' parser depending on reserved signs and words
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- (including a quoted char, dot-words or a single digit)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozeksid :: ([String], [String]) -> GenParser Char st Token
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozeksid (kOps, kWords) = pToken (scanQuotedChar <|> scanDotWords
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek <|> scanDigit <|> reserved kOps scanAnySigns
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek <|> reserved kWords scanAnyWords <?> "simple-id")
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- * 'Token' lists parsers
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | balanced mixfix components within braces
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekbraceP :: GenParser Char st [Token] -> GenParser Char st [Token]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekbraceP p = begDoEnd oBraceT p cBraceT
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | balanced mixfix components within square brackets
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekbracketP :: GenParser Char st [Token] -> GenParser Char st [Token]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekbracketP p = begDoEnd oBracketT p cBracketT
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | an 'sid' optionally followed by other mixfix components
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- (without no two consecutive 'sid's)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekinnerMix1 :: ([String], [String]) -> GenParser Char st [Token]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekinnerMix1 l = sid l <:> option [] (innerMix2 l)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | mixfix components not starting with a 'sid' (possibly places)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekinnerMix2 :: ([String], [String]) -> GenParser Char st [Token]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekinnerMix2 l = let p = innerList l in
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek flat (many1 (braceP p <|> bracketP p <|> many1 placeT))
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek <++> option [] (innerMix1 l)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | any mixfix components within braces or brackets
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekinnerList :: ([String], [String]) -> GenParser Char st [Token]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekinnerList l = option [] (innerMix1 l <|> innerMix2 l <?> "token")
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | mixfix components starting with a 'sid' (outside 'innerList')
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozektopMix1 :: ([String], [String]) -> GenParser Char st [Token]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozektopMix1 l = sid l <:> option [] (topMix2 l)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | mixfix components starting with braces ('braceP')
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- that may follow 'sid' outside 'innerList'.
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- (Square brackets after a 'sid' will be taken as a compound list.)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozektopMix2 :: ([String], [String]) -> GenParser Char st [Token]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozektopMix2 l = flat (many1 (braceP $ innerList l)) <++> option [] (topMix1 l)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | mixfix components starting with square brackets ('bracketP')
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- that may follow a place ('placeT') (outside 'innerList')
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozektopMix3 :: ([String], [String]) -> GenParser Char st [Token]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozektopMix3 l = let p = innerList l in
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek bracketP p <++> flat (many (braceP p))
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek <++> option [] (topMix1 l)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- | any ('topMix1', 'topMix2', 'topMix3') mixfix components
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek-- that may follow a place ('placeT') at the top level
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekafterPlace :: ([String], [String]) -> GenParser Char st [Token]
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub HrozekafterPlace l = topMix1 l <|> topMix2 l<|> topMix3 l
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek-- | 'place's possibly followed by other ('afterPlace') mixfix components
770dc892f867639f36f84455d65be6287935a529Jakub Hrozekmiddle :: ([String], [String]) -> GenParser Char st [Token]
770dc892f867639f36f84455d65be6287935a529Jakub Hrozekmiddle l = many1 placeT <++> option [] (afterPlace l)
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek-- | many (balanced, top-level) mixfix components ('afterPlace')
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek-- possibly interspersed with multiple places ('placeT')
770dc892f867639f36f84455d65be6287935a529Jakub HrozektokStart :: ([String], [String]) -> GenParser Char st [Token]
770dc892f867639f36f84455d65be6287935a529Jakub HrozektokStart l = afterPlace l <++> flat (many (middle l))
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek-- | any (balanced, top-level) mixfix components
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek-- possibly starting with places but no single 'placeT' only.
770dc892f867639f36f84455d65be6287935a529Jakub Hrozekstart :: ([String], [String]) -> GenParser Char st [Token]
770dc892f867639f36f84455d65be6287935a529Jakub Hrozekstart l = tokStart l <|> placeT <:> (tokStart l <|>
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek many1 placeT <++> option [] (tokStart l))
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek <?> "id"
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek-- ----------------------------------------------
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek-- * parser for mixfix and compound 'Id's
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek-- ----------------------------------------------
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | parsing a compound list
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinacomps :: ([String], [String]) -> GenParser Char st ([Id], [Pos])
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinacomps keys = do o <- oBracketT
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina (ts, ps) <- mixId keys keys `separatedBy` commaT
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina c <- cBracketT
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return (ts, toPos o ps c)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina <?> "[<id>,...,<id>]"
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | parse mixfix components ('start') and an optional compound list ('comps')
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- if the last token was no 'place'. Accept possibly further places.
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- Key strings (second argument) within compound list may differ from
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- top-level key strings (frist argument)!
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinamixId :: ([String], [String]) -> ([String], [String]) -> GenParser Char st Id
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinamixId keys idKeys =
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina do l <- start keys
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if isPlace (last l) then return (Id l [] [])
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina else do (c, p) <- option ([], []) (comps idKeys)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina u <- many placeT
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return (Id (l++u) c p)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | the Casl key strings (signs first)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinacasl_keys :: ([String], [String])
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinacasl_keys = (casl_reserved_fops, casl_reserved_fwords)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | Casl ids for operations and predicates
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinaparseId :: GenParser Char st Id
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinaparseId = mixId casl_keys casl_keys
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | disallow 'barS' with in the top-level of constructor names
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinaconsId :: GenParser Char st Id
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinaconsId = mixId (barS:casl_reserved_fops, casl_reserved_fwords) casl_keys
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | Casl sorts are simple words ('varId'),
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- but may have a compound list ('comps')
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinasortId :: GenParser Char st Id
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinasortId = do s <- varId
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina (c, p) <- option ([], []) (comps casl_keys)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return (Id [s] c p)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- ----------------------------------------------
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- * parser for simple 'Id's
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- ----------------------------------------------
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | parse a simple word not in 'casl_reserved_fwords'
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinavarId :: GenParser Char st Token
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinavarId = pToken (reserved casl_reserved_fwords scanAnyWords)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | same as 'varId'. 'SIMPLE_ID' for spec- and view names
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinasimpleId :: GenParser Char st Token
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinasimpleId = varId
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- ----------------------------------------------
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- * parser for key 'Token's
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- ----------------------------------------------
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | parse a question mark key sign ('quMark')
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinaquMarkT :: GenParser Char st Token
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinaquMarkT = pToken $ toKey quMark
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | parse a colon ('colonS') even if other signs (like 'quMark')
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- immediately follow.
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinacolonST :: GenParser Char st Token
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinacolonST = pToken (string colonS)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina-- | parse the product key sign ('prodS' or 'timesS')
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinacrossT :: GenParser Char st Token
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel BřezinacrossT = try (pToken (toKey prodS <|> toKey timesS) <?> "cross")
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina