Token.hs revision 58564afba8f0bb6b57783c4b440d0b666edf5f67
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance{- |
5d801400993c9671010d244646936d8fd435638cChristian MaederModule : $Header$
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceDescription : parser for CASL 'Id's based on "Common.Lexer"
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceCopyright : (c) Christian Maeder and Uni Bremen 2002-2004
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
5d801400993c9671010d244646936d8fd435638cChristian MaederMaintainer : Christian.Maeder@dfki.de
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceStability : provisional
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancePortability : portable
aa0ca44e856c87db27e61687cbb630f270976da1Felix Gabriel Mance
5d801400993c9671010d244646936d8fd435638cChristian MaederParser for CASL 'Id's based on "Common.Lexer"
5d801400993c9671010d244646936d8fd435638cChristian Maeder
5d801400993c9671010d244646936d8fd435638cChristian Maeder-}
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance{- http://www.cofi.info/Documents/CASL/Summary/
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance from 25 March 2001
097bc9f18b722812d480df0f5c634d09cbca8e21Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance C.2.1 Basic Specifications with Subsorts
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder
dc8c83e9922e4746c192916565f3522418534f3aFelix Gabriel ManceSIMPLE-ID ::= WORDS
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceID ::= TOKEN-ID | MIXFIX-ID
feab1106bbee4f2ea2fd48bca7106dd041e4211dFelix Gabriel ManceTOKEN-ID ::= TOKEN
18ff56829e5e99383ee6106584d55bcbd8ed45e7Felix Gabriel ManceMIXFIX-ID ::= TOKEN-ID PLACE-TOKEN-ID ... PLACE-TOKEN-ID
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance | PLACE-TOKEN-ID ... PLACE-TOKEN-ID
b1162cc13e8371724e3382ae6d1cfdeb43891fbbChristian MaederPLACE-TOKEN-ID ::= PLACE TOKEN-ID
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance | PLACE
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancePLACE ::= __
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel ManceTOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance | SIGNS
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance SIGNS are adapted here and more permissive as in the summary
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance WORDS and NO-BRACKET-SIGNS are treated equally
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance legal are, ie. "{a}", "{+}", "a{}="
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance illegal is "a=" (no two SIMPLE-TOKEN stay beside each other)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance SIMPLE-TOKEN ::= WORDS | DOT-WORDS | DIGIT | QUOTED-CHAR
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | NO-BRACKET-SIGNS
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance
0ec1551231bc5dfdcb3f2bd68fec7457fade7bfdFelix Gabriel Mance STB ::= SIMPLE-TOKEN BRACKETS
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance BST ::= BRACKETS SIMPLE-TOKEN
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder SIGNS ::= BRACKETS
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance | BRACKETS STB ... STB
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance | BRACKETS STB ... STB SIMPLE-TOKEN
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance | SIMPLE-TOKEN
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance | SIMPLE-TOKEN BST ... BST
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance | SIMPLE-TOKEN BST ... BST BRACKETS
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance A SIMPLE-TOKEN followed by "[" outside nested brackets
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance will be taken as the beginning of a compound list.
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance Within SIGNS brackets need not be balanced,
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maeder only after their composition to a MIXFIX-ID.
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maeder
fc7bd98aabe1bc26058660085e8c77d60a97bcecChristian Maeder BRACKETS = BRACKET ... BRACKET
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance BRACKET ::= [ | ] | { | }
3c6b4f79cea11dd2acc2060bf1502b6ba9e905f2Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance 2.4 Identifiers
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance brackets/braces within MIXFIX-ID must be balanced
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder C.2.2 Structured Specifications
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance TOKEN-ID ::= ... | TOKEN [ ID ,..., ID ]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance A compound list must follow the last TOKEN within MIXFIX-ID,
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance so a compound list is never nested within (balanced) mixfix BRACKETS.
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance Only PLACEs may follow a compound list.
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance The IDs within the compound list may surely be compound IDs again.
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance-}
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancemodule Common.Token where
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Manceimport Common.Keywords
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport Common.Lexer
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport Common.Id
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport Text.ParserCombinators.Parsec
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceimport Data.List (delete)
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder-- ----------------------------------------------
852bd6145634dc2832b61c44678fe539bc1682d5Christian Maeder-- * Casl keyword lists
ea3f858eb531d981df3ed00beeadd99cf025adecChristian Maeder-- ----------------------------------------------
ea3f858eb531d981df3ed00beeadd99cf025adecChristian Maeder
ea3f858eb531d981df3ed00beeadd99cf025adecChristian Maeder-- | reserved signs
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancecasl_reserved_ops :: [String]
3c6b4f79cea11dd2acc2060bf1502b6ba9e905f2Felix Gabriel Mancecasl_reserved_ops = [colonS, colonQuMark, defnS, dotS, cDot, mapsTo]
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mance
52991d9b46a98ad6a9020421a3244950b0f8a522Felix Gabriel Mance-- | these formula signs are legal in terms, but illegal in declarations
3c6b4f79cea11dd2acc2060bf1502b6ba9e905f2Felix Gabriel Manceformula_ops :: [String]
3c6b4f79cea11dd2acc2060bf1502b6ba9e905f2Felix Gabriel Manceformula_ops = [equalS, implS, equivS, lOr, lAnd, negS]
75aaf82c430ad2a5cf159962b1c5c09255010fb4Felix Gabriel Mance
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance-- | all reseverd signs
75aaf82c430ad2a5cf159962b1c5c09255010fb4Felix Gabriel Mancecasl_reserved_fops :: [String]
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancecasl_reserved_fops = formula_ops ++ casl_reserved_ops
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- | reserved keywords
1b1144abf7f95a4b23405b8d5604813cfe7b036aFelix Gabriel Mancecasl_basic_reserved_words :: [String]
4c684d7a2343be7350eba088f8be42888f86a495Felix Gabriel Mancecasl_basic_reserved_words =
1b1144abf7f95a4b23405b8d5604813cfe7b036aFelix Gabriel Mance [axiomS, axiomS ++ sS, cogeneratedS, cotypeS, cotypeS ++ sS,
5a3ae0a9224276de25e709ef8788c1b9716cd206Christian Maeder esortS, esortS ++ sS, etypeS, etypeS ++ sS,
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance existsS, forallS, freeS, generatedS,
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance opS, opS ++ sS, predS, predS ++ sS,
668c9c725a11c0f77057152148570af853a1bc0dFelix Gabriel Mance sortS, sortS ++ sS, typeS, typeS ++ sS, varS, varS ++ sS]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance-- | reserved keywords
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mancecasl_structured_reserved_words :: [String]
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancecasl_structured_reserved_words =
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance [andS, archS, behaviourallyS, closedS, cofreeS, endS,
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance fitS, freeS, fromS, getS, givenS,
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance hideS, lambdaS, libraryS, localS, logicS,
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance refinedS, refinementS,
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance resultS, revealS, specS, thenS, toS,
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance unitS, unitS ++ sS, versionS, viewS, withS, withinS]
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance-- | reserved keywords
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mancecasl_reserved_words :: [String]
9cb6af1a7632f12b60f592ce5eb2ac51e6bd33bbFelix Gabriel Mancecasl_reserved_words =
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel Mance casl_basic_reserved_words++ casl_structured_reserved_words
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder-- | these formula words are legal in terms, but illegal in declarations
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Manceformula_words :: [String]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Manceformula_words = [asS, defS, elseS, ifS, inS, whenS, falseS, notS, trueS]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | all reserved words
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancecasl_reserved_fwords :: [String]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancecasl_reserved_fwords = formula_words ++ casl_reserved_words
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- ----------------------------------------------
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- * a single 'Token' parser
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- pass list of key symbols and keywords as parameter
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- ----------------------------------------------
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | a simple 'Token' parser depending on reserved signs and words
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- (including a quoted char, dot-words or a single digit)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancesid :: ([String], [String]) -> GenParser Char st Token
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mancesid (kOps, kWords) = pToken (scanQuotedChar <|> scanDotWords
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance <|> scanDigit <|> reserved kOps scanAnySigns
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance <|> reserved kWords scanAnyWords <?> "simple-id")
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- * 'Token' lists parsers
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- | balanced mixfix components within braces
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancebraceP :: GenParser Char st [Token] -> GenParser Char st [Token]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancebraceP p = begDoEnd oBraceT p cBraceT <|> try (oBracketT <:> single cBracketT)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | balanced mixfix components within square brackets
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancebracketP :: GenParser Char st [Token] -> GenParser Char st [Token]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancebracketP p = begDoEnd oBracketT p cBracketT
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | an 'sid' optionally followed by other mixfix components
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- (without no two consecutive 'sid's)
968930c7674ae3b63d308bf4fa651400aa263054Christian MaederinnerMix1 :: ([String], [String]) -> GenParser Char st [Token]
a921ae1da1302f673204e7b63cdce01439a9bd5eFelix Gabriel ManceinnerMix1 l = sid l <:> option [] (innerMix2 l)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | mixfix components not starting with a 'sid' (possibly places)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceinnerMix2 :: ([String], [String]) -> GenParser Char st [Token]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceinnerMix2 l = let p = innerList l in
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance flat (many1 (braceP p <|> bracketP p <|> many1 placeT))
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance <++> option [] (innerMix1 l)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | any mixfix components within braces or brackets
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceinnerList :: ([String], [String]) -> GenParser Char st [Token]
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel ManceinnerList l = option [] (innerMix1 l <|> innerMix2 l <?> "token")
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | mixfix components starting with a 'sid' (outside 'innerList')
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancetopMix1 :: ([String], [String]) -> GenParser Char st [Token]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancetopMix1 l = sid l <:> option [] (topMix2 l)
097bc9f18b722812d480df0f5c634d09cbca8e21Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- | mixfix components starting with braces ('braceP')
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- that may follow 'sid' outside 'innerList'.
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- (Square brackets after a 'sid' will be taken as a compound list.)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancetopMix2 :: ([String], [String]) -> GenParser Char st [Token]
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancetopMix2 l = flat (many1 (braceP $ innerList l)) <++> option [] (topMix1 l)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | mixfix components starting with square brackets ('bracketP')
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- that may follow a place ('placeT') (outside 'innerList')
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel MancetopMix3 :: ([String], [String]) -> GenParser Char st [Token]
8af00c8930672188ae80c8829428859160d329d0Felix Gabriel MancetopMix3 l = let p = innerList l in
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance bracketP p <++> flat (many (braceP p))
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance <++> option [] (topMix1 l)
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | any ('topMix1', 'topMix2', 'topMix3') mixfix components
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- that may follow a place ('placeT') at the top level
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceafterPlace :: ([String], [String]) -> GenParser Char st [Token]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel ManceafterPlace l = topMix1 l <|> topMix2 l<|> topMix3 l
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | places possibly followed by other ('afterPlace') mixfix components
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancemiddle :: ([String], [String]) -> GenParser Char st [Token]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancemiddle l = many1 placeT <++> option [] (afterPlace l)
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel Mance-- | many (balanced, top-level) mixfix components ('afterPlace')
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- possibly interspersed with multiple places ('placeT')
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancetokStart :: ([String], [String]) -> GenParser Char st [Token]
ffa6044b04fa0e31242141ff56a5d80c4233b676Felix Gabriel MancetokStart l = afterPlace l <++> flat (many (middle l))
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- | any (balanced, top-level) mixfix components
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mance-- possibly starting with places but no single 'placeT' only.
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancestart :: ([String], [String]) -> GenParser Char st [Token]
c77c0efe19dc6556ac872828bfb4cfc5fbca5ac5Felix Gabriel Mancestart l = tokStart l <|> placeT <:> (tokStart l <|>
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance many1 placeT <++> option [] (tokStart l))
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance <?> "id"
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance-- ----------------------------------------------
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance-- * parser for mixfix and compound 'Id's
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance-- ----------------------------------------------
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance-- | parsing a compound list
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mancecomps :: ([String], [String]) -> GenParser Char st ([Id], Range)
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mancecomps keys = do o <- oBracketT
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance (ts, ps) <- mixId keys keys `separatedBy` commaT
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance c <- cBracketT
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance return (ts, toPos o ps c)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance{- | parse mixfix components ('start') and an optional compound list ('comps')
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance if the last token was no place. Accept possibly further places.
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance Key strings (second argument) within compound list may differ from
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance top-level key strings (frist argument)!
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance-}
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancemixId :: ([String], [String]) -> ([String], [String]) -> GenParser Char st Id
44985cbd4eb61dbc348617ebdd44a774e51dac07Christian MaedermixId keys idKeys =
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance do l <- start keys
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance if isPlace (last l) then return (Id l [] nullRange)
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance else do (c, p) <- option ([], nullRange) (comps idKeys)
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance u <- many placeT
44985cbd4eb61dbc348617ebdd44a774e51dac07Christian Maeder return (Id (l++u) c p)
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance-- | the Casl key strings (signs first) with additional keywords
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mancecasl_keys :: [String] -> ([String], [String])
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mancecasl_keys ks = (ks ++ casl_reserved_fops, ks ++ casl_reserved_fwords)
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance-- | Casl ids for operations and predicates
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceparseId :: [String] -> GenParser Char st Id
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceparseId ks = mixId (casl_keys ks) (casl_keys ks)
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance
511be329b2e8f55d0c6b18bd92571a1776b15932Felix Gabriel Mance-- | disallow 'barS' with in the top-level of constructor names
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceconsId :: [String] -> GenParser Char st Id
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel ManceconsId ks = mixId (barS:ks++casl_reserved_fops,
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance ks++casl_reserved_fwords) $ casl_keys ks
83f5f3291f9b40fa688776b4da10b5fa102a5ff8Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- | Casl sorts are simple words ('varId'),
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- but may have a compound list ('comps')
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancesortId :: [String] -> GenParser Char st Id
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancesortId ks =
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance do s <- varId ks
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance (c, p) <- option ([], nullRange) (comps $ casl_keys ks)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance return (Id [s] c p)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- ----------------------------------------------
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- * parser for simple 'Id's
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- ----------------------------------------------
968930c7674ae3b63d308bf4fa651400aa263054Christian Maeder
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- | parse a simple word not in 'casl_reserved_fwords'
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancevarId :: [String] -> GenParser Char st Token
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancevarId ks = pToken (reserved (ks++casl_reserved_fwords) scanAnyWords)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- | like 'varId'. 'Common.Id.SIMPLE_ID' for spec- and view names
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancesimpleId :: GenParser Char st Token
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancesimpleId = pToken (reserved casl_structured_reserved_words scanAnyWords)
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- ----------------------------------------------
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- * parser for key 'Token's
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- ----------------------------------------------
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel Mance-- | parse a question mark key sign ('quMark')
c298a419605037f5352b5ad0f67b3e06db094051Felix Gabriel MancequMarkT :: GenParser Char st Token
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancequMarkT = pToken $ toKey quMark
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance-- | parse a 'colonS' possibly immediately followed by a 'quMark'
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecolonST :: GenParser Char st Token
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecolonST = pToken $ try $ string colonS << notFollowedBy
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance (oneOf $ delete '?' signChars)
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance-- | parse the product key sign ('prodS' or 'timesS')
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecrossT :: GenParser Char st Token
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel MancecrossT = pToken (toKey prodS <|> toKey timesS) <?> "cross"
e99c3c1f572d0442872bba58f187ca520ef5d040Felix Gabriel Mance