summaryrefslogtreecommitdiff
path: root/src/GF/UseGrammar/Tokenize.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2005-12-02 13:13:14 +0000
committeraarne <aarne@cs.chalmers.se>2005-12-02 13:13:14 +0000
commitdea5158cbf1c11d45f2ed91d9975fbc77245e652 (patch)
tree751ef7bcaccf58c43354d5b1767d3b3d3d1ac34d /src/GF/UseGrammar/Tokenize.hs
parent50ddb387f4495beb8bd8da2b9726a087a489df68 (diff)
floats in GF and GFC (parsing user input still doesn't work)
Diffstat (limited to 'src/GF/UseGrammar/Tokenize.hs')
-rw-r--r--src/GF/UseGrammar/Tokenize.hs21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/GF/UseGrammar/Tokenize.hs b/src/GF/UseGrammar/Tokenize.hs
index bfc0e53bb..91f7f0c61 100644
--- a/src/GF/UseGrammar/Tokenize.hs
+++ b/src/GF/UseGrammar/Tokenize.hs
@@ -52,10 +52,17 @@ tokLits = map mkCFTok . mergeStr . words where
tokVars :: String -> [CFTok]
tokVars = map mkCFTokVar . words
+isFloat s = case s of
+ c:cs | isDigit c -> isFloat cs
+ '.':cs@(_:_) -> all isDigit cs
+ _ -> False
+
+
mkCFTok :: String -> CFTok
mkCFTok s = case s of
'"' :cs@(_:_) | last cs == '"' -> tL $ init cs
'\'':cs@(_:_) | last cs == '\'' -> tL $ init cs --- 's Gravenhage
+ _:_ | isFloat s -> tF s
_:_ | all isDigit s -> tI s
_ -> tS s
@@ -73,10 +80,16 @@ mkTokVars tok = map tv . tok where
tv t = t
mkLit :: String -> CFTok
-mkLit s = if (all isDigit s) then (tI s) else (tL s)
+mkLit s
+ | isFloat s = tF s
+ | all isDigit s = tI s
+ | otherwise = tL s
mkTL :: String -> CFTok
-mkTL s = if (all isDigit s) then (tI s) else (tL ("'" ++ s ++ "'"))
+mkTL s
+ | isFloat s = tF s
+ | all isDigit s = tI s
+ | otherwise = tL ("'" ++ s ++ "'")
-- | Haskell lexer, usable for much code
@@ -120,7 +133,7 @@ lexC2M' isHigherOrder s = case s of
where
lexC = lexC2M' isHigherOrder
getId s = mkT i : lexC cs where (i,cs) = span isIdChar s
- getLit s = tI i : lexC cs where (i,cs) = span isDigit s
+ getLit s = tI i : lexC cs where (i,cs) = span isDigit s ---- Float!
isIdChar c = isAlpha c || isDigit c || elem c "'_"
isSymb = reservedAnsiCSymbol
dropComment s = case s of
@@ -160,6 +173,7 @@ unknown2string :: (String -> Bool) -> [CFTok] -> [CFTok]
unknown2string isKnown = map mkOne where
mkOne t@(TS s)
| isKnown s = t
+ | isFloat s = tF s
| all isDigit s = tI s
| otherwise = tL s
mkOne t@(TC s) = if isKnown s then t else mkTL s
@@ -170,6 +184,7 @@ unknown2var isKnown = map mkOne where
mkOne t@(TS "??") = if isKnown "??" then t else tM "??"
mkOne t@(TS s)
| isKnown s = t
+ | isFloat s = tF s
| all isDigit s = tI s
| otherwise = tV s
mkOne t@(TC s) = if isKnown s then t else tV s