From a3178ad24984f0f91b9b55f6db7081e4b2bbd602 Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Mon, 22 Feb 2016 23:20:11 +0200 Subject: [PATCH] refactor the symbol lexer a little --- Language/SQL/SimpleSQL/Lex.lhs | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/Language/SQL/SimpleSQL/Lex.lhs b/Language/SQL/SimpleSQL/Lex.lhs index a252541..8f3d2ac 100644 --- a/Language/SQL/SimpleSQL/Lex.lhs +++ b/Language/SQL/SimpleSQL/Lex.lhs @@ -416,43 +416,30 @@ which allows the last character of a multi character symbol to be + or > <*> option [] opMoreChars > ] -> symbol d | diSyntaxFlavour d == SQLServer = -> Symbol <$> choice (otherSymbol ++ regularOp) +> symbol d = Symbol <$> choice (otherSymbol ++ regularOp) > where > otherSymbol = many1 (char '.') : -> (map (string . (:[])) ",;():?" +> (map (string . (:[])) otherSymbolChars > ++ if allowOdbc d > then [string "{", string "}"] > else []) +> otherSymbolChars = +> case diSyntaxFlavour d of +> SQLServer -> ",;():?" +> _ -> "[],;():?" 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 . (:[])) "+-^*/%~&<>=" +> -- what about using many1 (char '|'), then it will +> -- fail in the parser? Not sure exactly how +> -- standalone the lexer should be > ++ [char '|' *> > choice ["||" <$ char '|' <* notFollowedBy (char '|') > ,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 _ = Whitespace <$> many1 (satisfy isSpace)