Token.hs revision 98890889ffb2e8f6f722b00e265a211f13b5a861
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder{- |
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 Bungiu
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuMaintainer : Christian.Maeder@dfki.de
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuStability : provisional
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuPortability : portable
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae BungiuParser for CASL 'Id's based on "Common.Lexer"
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu-}
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu{- http://www.cofi.info/Documents/CASL/Summary/
ed1b8e97e72b2e3e92edaf2eb22a4b5373d705f1Felix Gabriel Mance from 25 March 2001
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu
386bd8214f3137fe84c392cd58338130d2f80607Felix Gabriel Mance C.2.1 Basic Specifications with Subsorts
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maeder
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
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance | PLACE
1f9274bb2aa44ea236327814dce99946be52e348Felix Gabriel MancePLACE ::= __
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu
8dd62da91d8ac7cfa80cfaff34dc87bb4c2c855bFelix Gabriel ManceTOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder | SIGNS
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder
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)
1f9274bb2aa44ea236327814dce99946be52e348Felix Gabriel Mance
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder SIMPLE-TOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maeder | NO-BRACKET-SIGNS
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maeder
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maeder STB ::= SIMPLE-TOKEN BRACKETS
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu BST ::= BRACKETS SIMPLE-TOKEN
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu SIGNS ::= BRACKETS
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu | BRACKETS STB ... STB
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder | BRACKETS STB ... STB SIMPLE-TOKEN
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder | SIMPLE-TOKEN
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu | SIMPLE-TOKEN BST ... BST
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu | SIMPLE-TOKEN BST ... BST BRACKETS
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu
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
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance BRACKETS = BRACKET ... BRACKET
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance BRACKET ::= [ | ] | { | }
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance 2.4 Identifiers
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Mance brackets/braces within MIXFIX-ID must be balanced
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance C.2.2 Structured Specifications
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance TOKEN-ID ::= ... | TOKEN [ ID ,..., ID ]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance
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.
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-}
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Mance
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancemodule Common.Token where
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceimport Common.Id
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Manceimport Common.Keywords
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Manceimport Common.Lexer
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Manceimport Common.Parsec
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceimport Text.ParserCombinators.Parsec
19e01e1a7e319063434bd86c8ecbc5f241ef9993Felix Gabriel Manceimport Data.List (delete)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance
15d62726781e67fe6458fbcf0a8c46832a7bb8daFelix Gabriel Mance-- * Casl keyword lists
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | reserved signs
1f9274bb2aa44ea236327814dce99946be52e348Felix Gabriel Mancecasl_reserved_ops :: [String]
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maedercasl_reserved_ops = [colonS, colonQuMark, defnS, dotS, cDot, mapsTo]
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maeder
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]
332dadf617c7fdc3353346f6b8e1c4d918214f3cChristian Maeder
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- | all reseverd signs
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancecasl_reserved_fops :: [String]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancecasl_reserved_fops = formula_ops ++ casl_reserved_ops
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder
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
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
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
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
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
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
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
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
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
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
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- * a single 'Token' parser taking lists of key symbols and words as parameter
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance
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
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- * 'Token' lists parsers
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance
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
{- | an 'sid' optionally followed by other mixfix components
(without no two consecutive 'sid's) -}
innerMix1 :: ([String], [String]) -> GenParser Char st [Token]
innerMix1 l = sid l <:> optionL (innerMix2 l)
-- | mixfix components not starting with a 'sid' (possibly places)
innerMix2 :: ([String], [String]) -> GenParser Char st [Token]
innerMix2 l = let p = innerList l in
flat (many1 (braceP p <|> bracketP p <|> many1 placeT))
<++> optionL (innerMix1 l)
-- | any mixfix components within braces or brackets
innerList :: ([String], [String]) -> GenParser Char st [Token]
innerList l = optionL (innerMix1 l <|> innerMix2 l <?> "token")
-- | mixfix components starting with a 'sid' (outside 'innerList')
topMix1 :: ([String], [String]) -> GenParser Char st [Token]
topMix1 l = sid l <:> optionL (topMix2 l)
{- | mixfix components starting with braces ('braceP')
that may follow 'sid' outside 'innerList'.
(Square brackets after a 'sid' will be taken as a compound list.) -}
topMix2 :: ([String], [String]) -> GenParser Char st [Token]
topMix2 l = flat (many1 (braceP $ innerList l)) <++> optionL (topMix1 l)
{- | mixfix components starting with square brackets ('bracketP')
that may follow a place ('placeT') (outside 'innerList') -}
topMix3 :: ([String], [String]) -> GenParser Char st [Token]
topMix3 l = let p = innerList l in
bracketP p <++> flat (many (braceP p))
<++> optionL (topMix1 l)
{- | any ('topMix1', 'topMix2', 'topMix3') mixfix components
that may follow a place ('placeT') at the top level -}
afterPlace :: ([String], [String]) -> GenParser Char st [Token]
afterPlace l = topMix1 l <|> topMix2 l <|> topMix3 l
-- | places possibly followed by other ('afterPlace') mixfix components
middle :: ([String], [String]) -> GenParser Char st [Token]
middle l = many1 placeT <++> optionL (afterPlace l)
{- | many (balanced, top-level) mixfix components ('afterPlace')
possibly interspersed with multiple places ('placeT') -}
tokStart :: ([String], [String]) -> GenParser Char st [Token]
tokStart l = afterPlace l <++> flat (many (middle l))
{- | any (balanced, top-level) mixfix components
possibly starting with places but no single 'placeT' only. -}
start :: ([String], [String]) -> GenParser Char st [Token]
start l = tokStart l <|> placeT <:> (tokStart l <|>
many1 placeT <++> optionL (tokStart l))
<?> "id"
-- * parser for mixfix and compound 'Id's
-- | parsing a compound list
comps :: ([String], [String]) -> GenParser Char st ([Id], Range)
comps keys = do
o <- oBracketT
(ts, ps) <- mixId keys keys `separatedBy` commaT
c <- cBracketT
return (ts, toRange o ps c)
{- | parse mixfix components ('start') and an optional compound list ('comps')
if the last token was no place. Accept possibly further places.
Key strings (second argument) within compound list may differ from
top-level key strings (first argument)!
-}
mixId :: ([String], [String]) -> ([String], [String]) -> GenParser Char st Id
mixId keys idKeys = do
l <- start keys
if isPlace (last l) then return (Id l [] nullRange) else do
(c, p) <- option ([], nullRange) (comps idKeys)
u <- many placeT
return (Id (l ++ u) c p)
-- | the Casl key strings (signs first) with additional keywords
casl_keys :: [String] -> ([String], [String])
casl_keys ks = (ks ++ casl_reserved_fops, ks ++ casl_reserved_fwords)
-- | Casl ids for operations and predicates
parseId :: [String] -> GenParser Char st Id
parseId ks = mixId (casl_keys ks) (casl_keys ks)
-- | disallow 'barS' within the top-level of constructor names
consId :: [String] -> GenParser Char st Id
consId ks = mixId (barS : ks ++ casl_reserved_fops,
ks ++ casl_reserved_fwords) $ casl_keys ks
{- | Casl sorts are simple words ('varId'),
but may have a compound list ('comps') -}
sortId :: [String] -> GenParser Char st Id
sortId ks =
do s <- varId ks
(c, p) <- option ([], nullRange) (comps $ casl_keys ks)
return (Id [s] c p)
-- * parser for simple 'Id's
-- | parse a simple word not in 'casl_reserved_fwords'
varId :: [String] -> GenParser Char st Token
varId ks = pToken (reserved (ks ++ casl_reserved_fwords) scanAnyWords)
-- | like 'varId'. 'Common.Id.SIMPLE_ID' for spec- and view names
simpleId :: GenParser Char st Token
simpleId = pToken (reserved casl_structured_reserved_words scanAnyWords)
-- * parser for key 'Token's
-- | parse a question mark key sign ('quMark')
quMarkT :: GenParser Char st Token
quMarkT = pToken $ toKey quMark
-- | parse a 'colonS' possibly immediately followed by a 'quMark'
colonST :: GenParser Char st Token
colonST = pToken $ try $ string colonS << notFollowedBy
(oneOf $ delete '?' signChars)
-- | parse the product key sign ('prodS' or 'timesS')
crossT :: GenParser Char st Token
crossT = pToken (toKey prodS <|> toKey timesS) <?> "cross"