1
Fork 0

example how to switch parsing and pretty printing depending on dialect

This commit is contained in:
Jake Wheat 2014-06-28 15:41:11 +03:00
parent 7d63c8f8e5
commit c1c514af35
6 changed files with 206 additions and 157 deletions
Language/SQL/SimpleSQL

View file

@ -17,7 +17,9 @@
> import Control.Applicative ((<$>), (<*>), (<**>), pure, Applicative)
> import Text.Parsec (option,many)
> import Text.Parsec.String (Parser)
> import Text.Parsec.Prim (Parsec)
> type Parser s = Parsec String s
a possible issue with the option suffix is that it enforces left
associativity when chaining it recursively. Have to review
@ -27,7 +29,7 @@ instead, and create an alternative suffix parser
This function style is not good, and should be replaced with chain and
<??> which has a different type
> optionSuffix :: (a -> Parser a) -> a -> Parser a
> optionSuffix :: (a -> Parser s a) -> a -> Parser s a
> optionSuffix p a = option a (p a)
@ -37,7 +39,7 @@ hand result, taken from uu-parsinglib
TODO: make sure the precedence higher than <|> and lower than the
other operators so it can be used nicely
> (<??>) :: Parser a -> Parser (a -> a) -> Parser a
> (<??>) :: Parser s a -> Parser s (a -> a) -> Parser s a
> p <??> q = p <**> option id q
@ -78,7 +80,7 @@ composing suffix parsers, not sure about the name. This is used to add
a second or more suffix parser contingent on the first suffix parser
succeeding.
> (<??.>) :: Parser (a -> a) -> Parser (a -> a) -> Parser (a -> a)
> (<??.>) :: Parser s (a -> a) -> Parser s (a -> a) -> Parser s (a -> a)
> (<??.>) pa pb = (.) `c` pa <*> option id pb
> -- todo: fix this mess
> where c = (<$>) . flip
@ -86,7 +88,7 @@ succeeding.
0 to many repeated applications of suffix parser
> (<??*>) :: Parser a -> Parser (a -> a) -> Parser a
> (<??*>) :: Parser s a -> Parser s (a -> a) -> Parser s a
> p <??*> q = foldr ($) <$> p <*> (reverse <$> many q)