1
Fork 0

refactor the symbol lexer a little

This commit is contained in:
Jake Wheat 2016-02-22 23:20:11 +02:00
parent 3f7e0123a2
commit a3178ad249

View file

@ -416,43 +416,30 @@ which allows the last character of a multi character symbol to be + or
> <*> option [] opMoreChars > <*> option [] opMoreChars
> ] > ]
> symbol d | diSyntaxFlavour d == SQLServer = > symbol d = Symbol <$> choice (otherSymbol ++ regularOp)
> Symbol <$> choice (otherSymbol ++ regularOp)
> where > where
> otherSymbol = many1 (char '.') : > otherSymbol = many1 (char '.') :
> (map (string . (:[])) ",;():?" > (map (string . (:[])) otherSymbolChars
> ++ if allowOdbc d > ++ if allowOdbc d
> then [string "{", string "}"] > then [string "{", string "}"]
> else []) > else [])
> otherSymbolChars =
> case diSyntaxFlavour d of
> SQLServer -> ",;():?"
> _ -> "[],;():?"
try is used because most of the first characters of the two character try is used because most of the first characters of the two character
symbols can also be part of a single character symbol symbols can also be part of a single character symbol
> regularOp = map (try . string) [">=","<=","!=","<>"] > regularOp = map (try . string) [">=","<=","!=","<>"]
> ++ map (string . (:[])) "+-^*/%~&<>=" > ++ map (string . (:[])) "+-^*/%~&<>="
> -- what about using many1 (char '|'), then it will
> -- fail in the parser? Not sure exactly how
> -- standalone the lexer should be
> ++ [char '|' *> > ++ [char '|' *>
> choice ["||" <$ char '|' <* notFollowedBy (char '|') > choice ["||" <$ char '|' <* notFollowedBy (char '|')
> ,return "|"]] > ,return "|"]]
> symbol d =
> Symbol <$> choice (otherSymbol ++ regularOp)
> where
> otherSymbol = many1 (char '.') :
> (map (string . (:[])) "[],;():?"
> ++ if allowOdbc d
> then [string "{", string "}"]
> else [])
try is used because most of the first characters of the two character
symbols can also be part of a single character symbol
> regularOp = map (try . string) [">=","<=","!=","<>"]
> ++ map (string . (:[])) "+-^*/%~&<>=[]"
> ++ [char '|' *>
> choice ["||" <$ char '|' <* notFollowedBy (char '|')
> ,return "|"]]
> sqlWhitespace :: Dialect -> Parser Token > sqlWhitespace :: Dialect -> Parser Token
> sqlWhitespace _ = Whitespace <$> many1 (satisfy isSpace) > sqlWhitespace _ = Whitespace <$> many1 (satisfy isSpace)