Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 89cc952

Browse files
authored
Backtracking fixes (#30)
1 parent aefcf95 commit 89cc952

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/SqlSquared/Parser.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ queryBinop = asErrorMessage "query operator" $ PC.choice
189189
[ keyword "limit" $> Sig.Limit
190190
, keyword "offset" $> Sig.Offset
191191
, keyword "sample" $> Sig.Sample
192+
, PC.try $ keyword "union" *> keyword "all" $> Sig.UnionAll
192193
, keyword "union" $> Sig.Union
193-
, keyword "union" *> keyword "all" $> Sig.UnionAll
194194
, PC.try $ keyword "intersect" *> keyword "all" $> Sig.IntersectAll
195195
, keyword "intersect" $> Sig.Intersect
196196
, keyword "except" $> Sig.Except
@@ -278,7 +278,7 @@ derefExpr = do
278278
, indexDerefExpr
279279
]
280280

281-
fieldDeref = do
281+
fieldDeref = PC.try do
282282
operator "."
283283
k ← ident <|> anyKeyword <|> stringLiteral
284284
pure \e → C.binop Sig.FieldDeref e (C.ident k)
@@ -435,12 +435,12 @@ literal = withToken "literal" case _ of
435435
| s == "null" → pure $ embed $ Sig.Literal $ EJ.Null
436436
| s == "true" → pure $ embed $ Sig.Literal $ EJ.Boolean true
437437
| s == "false" → pure $ embed $ Sig.Literal $ EJ.Boolean false
438-
_P.fail "not a literal"
438+
tP.fail (printToken t)
439439

440440
stringLiteral m. Monad m P.ParserT TokenStream m String
441441
stringLiteral = withToken "string literal" case _ of
442442
Lit (String s) → pure s
443-
_P.fail "not a string"
443+
tP.fail (printToken t)
444444

445445
arrayLiteral m t. SqlParser' m t
446446
arrayLiteral = do

test/src/Parse.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,14 @@ testSuite5 = do
856856
select length(city) as len, count(*) as cnt from largeZips where state != "MI" group by length(city)
857857
"""
858858

859+
parseSucc """
860+
select foo.* from zips as foo
861+
"""
862+
863+
parseSucc """
864+
select foo from bar union all select baz from quux
865+
"""
866+
859867
testSuite6 e. TestSuite (testOutput Console.TESTOUTPUT | e)
860868
testSuite6 = do
861869
parseSucc Q.q1

0 commit comments

Comments
 (0)