diff options
| author | bringert <unknown> | 2005-06-17 13:15:16 +0000 |
|---|---|---|
| committer | bringert <unknown> | 2005-06-17 13:15:16 +0000 |
| commit | 2c48a10236bb19d8b04382cb1e957ce18b9d29fd (patch) | |
| tree | 1194fc1981b5cd2a144b72f4fff261edfeb1af2e /src/GF/Canon/LexGFC.x | |
| parent | 05b5ffe5bf03a870f6fe0728ace6c0d8de69b89e (diff) | |
Changed name of Con constructor in GFC.cf to avoid errors on Windows when generating Java code with BNFC for the GFC grammar. CON is a reserved filename on Windows. Con was changed to Par, and all the code using was changed too.
Diffstat (limited to 'src/GF/Canon/LexGFC.x')
| -rw-r--r-- | src/GF/Canon/LexGFC.x | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/GF/Canon/LexGFC.x b/src/GF/Canon/LexGFC.x index 3ab44786b..0a50e49d1 100644 --- a/src/GF/Canon/LexGFC.x +++ b/src/GF/Canon/LexGFC.x @@ -1,9 +1,10 @@ -- -*- haskell -*- -- This Alex file was machine-generated by the BNF converter { -module LexGFC where +module GF.Canon.LexGFC where -import ErrM +import GF.Data.ErrM -- H +import GF.Data.SharedString -- H } @@ -20,25 +21,28 @@ $u = [\0-\255] -- universal: any character :- $white+ ; -@rsyms { tok (\p s -> PT p (TS s)) } +@rsyms { tok (\p s -> PT p (TS $ share s)) } -$l $i* { tok (\p s -> PT p (eitherResIdent TV s)) } -\" ([$u # [\" \\ \n]] | (\\ (\" | \\ | \' | n | t)))* \"{ tok (\p s -> PT p (TL $ unescapeInitTail s)) } +$l $i* { tok (\p s -> PT p (eitherResIdent (TV . share) s)) } +\" ([$u # [\" \\ \n]] | (\\ (\" | \\ | \' | n | t)))* \"{ tok (\p s -> PT p (TL $ share $ unescapeInitTail s)) } -$d+ { tok (\p s -> PT p (TI s)) } +$d+ { tok (\p s -> PT p (TI $ share s)) } { tok f p s = f p s +share :: String -> String +share = shareString + data Tok = - TS String -- reserved words - | TL String -- string literals - | TI String -- integer literals - | TV String -- identifiers - | TD String -- double precision float literals - | TC String -- character literals + TS !String -- reserved words + | TL !String -- string literals + | TI !String -- integer literals + | TV !String -- identifiers + | TD !String -- double precision float literals + | TC !String -- character literals deriving (Eq,Show,Ord) @@ -63,20 +67,18 @@ prToken t = case t of _ -> show t +data BTree = N | B String Tok BTree BTree deriving (Show) + eitherResIdent :: (String -> Tok) -> String -> Tok -eitherResIdent tv s = if isResWord s then (TS s) else (tv s) where - isResWord s = isInTree s $ - B "lin" (B "concrete" (B "Type" (B "Str" (B "Ints" N N) N) (B "cat" (B "abstract" N N) N)) (B "fun" (B "flags" (B "data" N N) N) (B "in" (B "grammar" N N) N))) (B "pre" (B "open" (B "of" (B "lincat" N N) N) (B "param" (B "oper" N N) N)) (B "transfer" (B "table" (B "resource" N N) N) (B "variants" N N))) - -data BTree = N | B String BTree BTree deriving (Show) - -isInTree :: String -> BTree -> Bool -isInTree x tree = case tree of - N -> False - B a left right - | x < a -> isInTree x left - | x > a -> isInTree x right - | x == a -> True +eitherResIdent tv s = treeFind resWords + where + treeFind N = tv s + treeFind (B a t left right) | s < a = treeFind left + | s > a = treeFind right + | s == a = t + +resWords = b "lin" (b "concrete" (b "Type" (b "Str" (b "Ints" N N) N) (b "cat" (b "abstract" N N) N)) (b "fun" (b "flags" (b "data" N N) N) (b "in" (b "grammar" N N) N))) (b "pre" (b "open" (b "of" (b "lincat" N N) N) (b "param" (b "oper" N N) N)) (b "transfer" (b "table" (b "resource" N N) N) (b "variants" N N))) + where b s = B s (TS s) unescapeInitTail :: String -> String unescapeInitTail = unesc . tail where |
