@@ -20,7 +20,7 @@ import Data.Either as E
2020import Data.Foldable as F
2121import Data.List ((:))
2222import Data.List as L
23- import Data.Maybe (Maybe (..), fromMaybe , isJust , maybe )
23+ import Data.Maybe (Maybe (..), fromMaybe , isJust )
2424import Data.NonEmpty ((:|))
2525import Data.Json.Extended as EJ
2626import Data.Tuple (Tuple (..), uncurry )
@@ -88,7 +88,7 @@ prettyParse parser input =
8888 nums = A .mapWithIndex (\n l → padLeft 4 (show (n + pos.line - (A .length pre))) <> " | " <> l) (pre <> line <> post)
8989 pointer = pure $ S .fromCharArray (A .replicate (pos.column - 1 + 7 ) ' -' ) <> " ^ " <> message
9090 in
91- S .joinWith " \n " $ A .take 3 nums <> pointer <> A .drop 3 nums
91+ S .joinWith " \n " $ A .take ( A .length pre + 1 ) nums <> pointer <> A .drop 3 nums
9292
9393parse
9494 ∷ ∀ t
@@ -215,7 +215,7 @@ andExpr = prod cmpExpr (keyword "and") $ _BINOP' Sig.And
215215cmpExpr ∷ ∀ m t . SqlParser' m t
216216cmpExpr = do
217217 e ← defaultExpr
218- modifiers ← A .many $ negatableSuffix <|> relationalSuffix
218+ modifiers ← A .many $ PC .try negatableSuffix <|> relationalSuffix
219219 pure $ F .foldl (\acc fn → fn acc) e modifiers
220220
221221defaultExpr ∷ ∀ m t . SqlParser' m t
@@ -280,7 +280,7 @@ derefExpr = do
280280
281281 fieldDeref = do
282282 operator " ."
283- k ← ident
283+ k ← ident <|> anyKeyword <|> stringLiteral
284284 pure \e → C .binop Sig.FieldDeref e (C .ident k)
285285
286286 fieldDerefExpr = do
@@ -385,7 +385,7 @@ unaryOperator = do
385385
386386functionExpr ∷ ∀ m t . SqlParser' m t
387387functionExpr = PC .try do
388- name ← ident
388+ name ← ident <|> anyKeyword
389389 args ← parenList
390390 pure $ C .invokeFunction name args
391391
@@ -427,15 +427,20 @@ variableString = asErrorMessage "variable" $ PC.try do
427427 pure s
428428
429429literal ∷ ∀ m t . SqlParser' m t
430- literal = PC .tryRethrow $ token >>= case _ of
430+ literal = withToken " literal " case _ of
431431 Lit (String s) → pure $ embed $ Sig.Literal $ EJ.String s
432432 Lit (Integer i) → pure $ embed $ Sig.Literal $ EJ.Integer i
433433 Lit (Decimal d) → pure $ embed $ Sig.Literal $ EJ.Decimal d
434434 Kw s
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 " incorrect literal"
438+ _ → P .fail " not a literal"
439+
440+ stringLiteral ∷ ∀ m . Monad m ⇒ P.ParserT TokenStream m String
441+ stringLiteral = withToken " string literal" case _ of
442+ Lit (String s) → pure s
443+ _ → P .fail " not a string"
439444
440445arrayLiteral ∷ ∀ m t . SqlParser' m t
441446arrayLiteral = do
@@ -461,11 +466,10 @@ keyValuePair = do
461466negatableSuffix ∷ ∀ m t . SqlParser m t (t → t )
462467negatableSuffix = do
463468 inv ← do
464- _ ← PC .optionMaybe $ keyword " is"
469+ _ ← PC .optionMaybe ( keyword " is" )
465470 n ← PC .optionMaybe $ keyword " not"
466471 pure $ isJust n
467- suffix ← asErrorMessage " `LIKE`, `IN`, or `BETWEEN`" do
468- betweenSuffix <|> inSuffix <|> likeSuffix
472+ suffix ← betweenSuffix <|> inSuffix <|> likeSuffix
469473 pure \e → (if inv then _NOT else id) $ suffix e
470474
471475betweenSuffix ∷ ∀ m t . SqlParser m t (t → t )
@@ -563,12 +567,8 @@ tableRelation = do
563567 Pt .parsePath
564568 (const $ P .fail " incorrect path" )
565569 (const $ P .fail " incorrect path" )
566- (maybe (P .fail " incorrect path" )
567- (pure ∘ E.Right )
568- ∘ Pt .sandbox Pt .currentDir)
569- (maybe (P .fail " incorrect path" )
570- (pure ∘ E.Left ∘ (Pt .rootDir Pt .</> _))
571- ∘ Pt .sandbox Pt .rootDir)
570+ (pure ∘ E.Right )
571+ (pure ∘ E.Left )
572572 i
573573 a ← PC .optionMaybe do
574574 _ ← keyword " as"
0 commit comments