From 2f78c3e209d08f82a3a656f0636405738c15e0e3 Mon Sep 17 00:00:00 2001 From: aarne Date: Mon, 4 Apr 2005 14:50:27 +0000 Subject: [PATCH] support for multi-character string literals --- src/GF/Source/GrammarToSource.hs | 8 +++++--- src/GF/UseGrammar/Tokenize.hs | 23 +++++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/GF/Source/GrammarToSource.hs b/src/GF/Source/GrammarToSource.hs index 2a2e3e2d5..bfbb815f7 100644 --- a/src/GF/Source/GrammarToSource.hs +++ b/src/GF/Source/GrammarToSource.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/02/24 11:46:38 $ --- > CVS $Author: peb $ --- > CVS $Revision: 1.17 $ +-- > CVS $Date: 2005/04/04 15:50:27 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.18 $ -- -- From internal source syntax to BNFC-generated (used for printing). ----------------------------------------------------------------------------- @@ -145,6 +145,8 @@ trt trm = case trm of Q t l -> P.EQCons (tri t) (tri l) QC t l -> P.EQConstr (tri t) (tri l) TSh (TComp ty) cc -> P.ETTable (trt ty) (map trCases cc) + TSh (TTyped ty) cc -> P.ETTable (trt ty) (map trCases cc) + TSh (TWild ty) cc -> P.ETTable (trt ty) (map trCases cc) T (TTyped ty) cc -> P.ETTable (trt ty) (map trCase cc) T (TComp ty) cc -> P.ETTable (trt ty) (map trCase cc) T (TWild ty) cc -> P.ETTable (trt ty) (map trCase cc) diff --git a/src/GF/UseGrammar/Tokenize.hs b/src/GF/UseGrammar/Tokenize.hs index cfbf8c8df..067404468 100644 --- a/src/GF/UseGrammar/Tokenize.hs +++ b/src/GF/UseGrammar/Tokenize.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/02/24 11:46:39 $ --- > CVS $Author: peb $ --- > CVS $Revision: 1.10 $ +-- > CVS $Date: 2005/04/04 15:50:27 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.11 $ -- -- lexers = tokenizers, to prepare input for GF grammars. AR 4\/1\/2002. -- an entry for each is included in 'Custom.customTokenizer' @@ -38,15 +38,23 @@ tokWords :: String -> [CFTok] tokWords = map tS . words tokLits :: String -> [CFTok] -tokLits = map mkCFTok . words +tokLits = map mkCFTok . mergeStr . words where + mergeStr ss = case ss of + w@(c:_):rest | elem c "\'\"" -> getStr [w] rest + w :rest -> w : mergeStr rest + [] -> [] + getStr v ss = case ss of + w@(_:_):rest | elem (last w) "\'\"" -> (unwords (reverse (w:v))) : mergeStr rest + w :rest -> getStr (w:v) rest + [] -> reverse v tokVars :: String -> [CFTok] tokVars = map mkCFTokVar . words mkCFTok :: String -> CFTok mkCFTok s = case s of - '"' :cs@(_:_) -> tL $ init cs - '\'':cs@(_:_) -> tL $ init cs --- 's Gravenhage + '"' :cs@(_:_) | last cs == '"' -> tL $ init cs + '\'':cs@(_:_) | last cs == '\'' -> tL $ init cs --- 's Gravenhage _:_ | all isDigit s -> tI s _ -> tS s @@ -152,7 +160,7 @@ unknown2string isKnown = map mkOne where mkOne t@(TS s) | isKnown s = t | all isDigit s = tI s - | otherwise = tV s + | otherwise = tL s mkOne t@(TC s) = if isKnown s then t else mkTL s mkOne t = t @@ -163,7 +171,6 @@ unknown2var isKnown = map mkOne where | isKnown s = t | all isDigit s = tI s | otherwise = tV s - mkOne t@(TS s) = if isKnown s then t else tV s mkOne t@(TC s) = if isKnown s then t else tV s mkOne t = t