parsing escaped strings from command line fixed

This commit is contained in:
aarne
2005-12-21 19:46:48 +00:00
parent 82c3a45047
commit d91d8043e0
6 changed files with 36 additions and 22 deletions

View File

@@ -23,6 +23,7 @@ import GF.Infra.Option
import GF.Compile.PGrammar (pzIdent, pTrm) --- (string2formsAndTerm)
import GF.API
import GF.System.Arch (fetchCommand)
import GF.UseGrammar.Tokenize (wordsLits)
import Data.Char (isDigit, isSpace)
import System.IO.Error
@@ -44,18 +45,6 @@ pCommandLines :: HState -> String -> [CommandLine]
pCommandLines st =
map (pCommandLine st) . concatMap (chunks ";;" . wordsLits) . lines
-- | Like 'words', but does not split on whitespace inside
-- double quotes.
wordsLits :: String -> [String]
wordsLits [] = []
wordsLits (c:cs) | isSpace c = wordsLits (dropWhile isSpace cs)
| c == '\'' || c == '"'
= let (l,rs) = break (==c) cs
rs' = drop 1 rs
in ([c]++l++[c]):wordsLits rs'
| otherwise = let (w,rs) = break isSpace cs
in (c:w):wordsLits rs
-- | Remove single or double quotes around a string
unquote :: String -> String
unquote (x:xs@(_:_)) | x `elem` "\"'" && x == last xs = init xs
@@ -83,7 +72,7 @@ pCommandOpt _ s = (CVoid, noOptions, [AError "no parse"])
pInputString :: String -> [CommandArg]
pInputString s = case s of
('"':_:_) -> [AString (init (tail s))]
('"':_:_) | last s == '"' -> [AString (read s)]
_ -> [AError "illegal string"]
-- | command @rl@ can be written @remove_language@ etc.