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

Commit

Permalink
Allow keywords as variables (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
natefaubion authored Jun 27, 2017
1 parent c8fbb46 commit 8e7c8f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/SqlSquare/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ keyword s = PC.try $ token >>= case _ of
Kw ss | S.toLower s == S.toLower ss → pure s
_ → P.fail $ "Token is not a keyword " <> s

anyKeyword m. Monad m P.ParserT (Array Token) m String
anyKeyword = PC.try $ token >>= case _ of
Kw s → pure s
_ → P.fail "Token is not a keyword"

match m. Monad m Token P.ParserT (Array Token) m Token
match = whenTok ∘ eq

Expand Down Expand Up @@ -467,7 +472,7 @@ variable
P.ParserT (Array Token) m t
variable = PC.try do
operator ":"
s ← ident
s ← ident <|> anyKeyword
pure $ embed $ Sig.Vari s

literal
Expand Down
1 change: 1 addition & 0 deletions test/src/Parse.purs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ select 12
"""
, """import foo; select * from `/test`"""
, """create function foo(:bar) begin :bar + 2 end; select * from `/test` where foo = foo(42)"""
, """select :where"""
]

testSuite e. TestSuite (testOutput Console.TESTOUTPUT | e)
Expand Down

0 comments on commit 8e7c8f8

Please sign in to comment.