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

Commit b9801ae

Browse files
authored
Merge pull request #49 from slamdata/ps-0.14
Update for GH actions, PS 0.14, support escaped slash
2 parents 7141ef5 + fa41a1e commit b9801ae

File tree

16 files changed

+119
-107
lines changed

16 files changed

+119
-107
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- uses: purescript-contrib/setup-purescript@main
14+
15+
- uses: actions/setup-node@v1
16+
with:
17+
node-version: "12"
18+
19+
- name: Install dependencies
20+
run: |
21+
npm install -g bower
22+
npm install
23+
bower install --production
24+
25+
- name: Build source
26+
run: npm run-script build
27+
28+
- name: Run tests
29+
run: |
30+
bower install
31+
npm run-script test --if-present

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
/.*
2+
!/.gitignore
3+
!/.github
14
/bower_components/
25
/node_modules/
3-
/.pulp-cache/
46
/output/
5-
/.psc*
6-
/.psa*
7-
/.purs-repl
7+
package-lock.json

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# purescript-sql-squared
22

33
[![Latest release](http://img.shields.io/github/release/slamdata/purescript-sql-squared.svg)](https://github.com/slamdata/purescript-sql-squared/releases)
4-
[![Build status](https://travis-ci.org/slamdata/purescript-sql-squared.svg?branch=master)](https://travis-ci.org/slamdata/purescript-sql-squared)
4+
![Build Status](https://github.com/slamdata/purescript-sql-squared/actions/workflows/ci.yml/badge.svg)
55

66
AST and printer for SQL² -- query language used by [quasar](https://github.com/quasar-analytics/quasar).
77

bower.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
"package.json"
1616
],
1717
"dependencies": {
18-
"purescript-prelude": "^4.0.1",
19-
"purescript-matryoshka": "^0.4.0",
20-
"purescript-pathy": "^7.0.0",
21-
"purescript-profunctor-lenses": "^6.1.0",
22-
"purescript-ejson": "^12.0.0"
18+
"purescript-prelude": "^5.0.1",
19+
"purescript-matryoshka": "^0.5.0",
20+
"purescript-pathy": "^8.1.0",
21+
"purescript-profunctor-lenses": "^7.0.1",
22+
"purescript-ejson": "^13.0.0"
2323
},
2424
"devDependencies": {
25-
"purescript-quickcheck": "^6.1.0",
26-
"purescript-argonaut": "^6.0.0",
27-
"purescript-assert": "^4.1.0"
25+
"purescript-quickcheck": "^7.1.0",
26+
"purescript-argonaut": "^8.0.0",
27+
"purescript-assert": "^5.0.0"
2828
}
2929
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"test": "pulp test"
66
},
77
"dependencies": {
8-
"pulp": "^12.2.0",
9-
"purescript": "^0.12.0",
10-
"purescript-psa": "^0.6.0"
8+
"pulp": "^15.0.0",
9+
"purescript": "^0.14.1",
10+
"purescript-psa": "^0.8.2"
1111
}
1212
}

src/SqlSquared/Lenses.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import Data.Json.Extended as EJ
88
import Data.Lens (Prism', prism', Lens', lens, Iso')
99
import Data.Lens.Iso.Newtype (_Newtype)
1010
import Data.List as L
11+
import Data.List.NonEmpty as NEL
1112
import Data.Maybe as M
12-
import Data.NonEmpty as NE
1313
import Matryoshka (class Recursive, class Corecursive, embed, project)
1414
import SqlSquared.Signature as S
1515
import SqlSquared.Utils (type (×), (∘), (⋙))
@@ -20,7 +20,7 @@ _GroupBy = _Newtype
2020
_Case a. Iso' (S.Case a) { cond a, expr a }
2121
_Case = _Newtype
2222

23-
_OrderBy a. Iso' (S.OrderBy a) (NE.NonEmpty L.List (S.OrderType × a))
23+
_OrderBy a. Iso' (S.OrderBy a) (NEL.NonEmptyList (S.OrderType × a))
2424
_OrderBy = _Newtype
2525

2626
_Projection a. Iso' (S.Projection a) { expr a, alias M.Maybe S.Ident }

src/SqlSquared/Parser.purs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import Data.Foldable as F
2020
import Data.Json.Extended as EJ
2121
import Data.List ((:))
2222
import Data.List as L
23+
import Data.List.NonEmpty as NEL
2324
import Data.Maybe (Maybe(..), fromMaybe, isJust)
24-
import Data.NonEmpty ((:|))
2525
import Data.String as S
2626
import Data.String.CodeUnits as SCU
2727
import Data.Tuple (Tuple(..), uncurry)
@@ -77,17 +77,18 @@ prettyParse parser input =
7777
SCU.fromCharArray (A.replicate (n - S.length s) ' ') <> s
7878

7979
printError parseError =
80-
let
81-
message = P.parseErrorMessage parseError
82-
PP.Position pos = P.parseErrorPosition parseError
83-
lines = S.split (S.Pattern "\n") input
84-
pre = A.drop (pos.line - 3) $ A.take (pos.line - 1) lines
85-
line = A.take 1 $ A.drop (pos.line - 1) lines
86-
post = A.take 3 $ A.drop pos.line lines
87-
nums = A.mapWithIndex (\n l → padLeft 4 (show (n + pos.line - (A.length pre))) <> " | " <> l) (pre <> line <> post)
88-
pointer = pure $ SCU.fromCharArray (A.replicate (pos.column - 1 + 7) '-') <> "^ " <> message
89-
in
90-
S.joinWith "\n" $ A.take (A.length pre + 1) nums <> pointer <> A.drop 3 nums
80+
case P.parseErrorPosition parseError of
81+
PP.Position pos →
82+
let
83+
message = P.parseErrorMessage parseError
84+
lines = S.split (S.Pattern "\n") input
85+
pre = A.drop (pos.line - 3) $ A.take (pos.line - 1) lines
86+
line = A.take 1 $ A.drop (pos.line - 1) lines
87+
post = A.take 3 $ A.drop pos.line lines
88+
nums = A.mapWithIndex (\n l → padLeft 4 (show (n + pos.line - (A.length pre))) <> " | " <> l) (pre <> line <> post)
89+
pointer = pure $ SCU.fromCharArray (A.replicate (pos.column - 1 + 7) '-') <> "^ " <> message
90+
in
91+
S.joinWith "\n" $ A.take (A.length pre + 1) nums <> pointer <> A.drop 3 nums
9192

9293
parse
9394
t
@@ -111,7 +112,7 @@ parseModule
111112
parseModule = tokenize >=> flip P.runParser (moduleTop <* eof)
112113

113114
queryTop m t. SqlParser m t (Sig.SqlQueryF t)
114-
queryTop = defer \_ → Sig.Query <$> (PC.sepEndBy decl $ operator ";") <*> expr
115+
queryTop = defer \_ → Sig.Query <$> PC.sepEndBy decl (operator ";") <*> expr
115116

116117
moduleTop m t. SqlParser m t (Sig.SqlModuleF t)
117118
moduleTop = defer \_ → Sig.Module <$> PC.sepBy decl (operator ";")
@@ -639,7 +640,7 @@ groupBy ∷ ∀ m t. SqlParser m t (Sig.GroupBy t)
639640
groupBy = do
640641
_ ← keyword "group"
641642
_ ← keyword "by"
642-
keys ← PC.sepBy1 definedExpr $ operator ","
643+
keys ← NEL.toList <$> PC.sepBy1 definedExpr (operator ",")
643644
having ← PC.optionMaybe do
644645
_ ← keyword "having"
645646
definedExpr
@@ -655,10 +656,7 @@ orderBy prs = do
655656
_ ← keyword "order"
656657
_ ← keyword "by"
657658
pos ← P.position
658-
lst ← flip PC.sepBy1 (operator ",") $ sortClause pos
659-
case lst of
660-
L.NilP.fail "incorrect order by"
661-
x : xs → pure $ Sig.OrderBy (x :| xs)
659+
Sig.OrderBy <$> flip PC.sepBy1 (operator ",") (sortClause pos)
662660
where
663661
sortPart = PC.choice
664662
[ keyword "asc" $> Sig.ASC

src/SqlSquared/Parser/Tokenizer.purs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ type PositionedToken =
5454

5555
type TokenStream = Array PositionedToken
5656

57-
isKeyword Token Boolean
58-
isKeyword = case _ of
59-
Kw _ → true
60-
_ → false
61-
6257
isComment Token Boolean
6358
isComment = case _ of
6459
Comment _ → true
@@ -72,7 +67,7 @@ printToken = case _ of
7267
Lit (String _) → "string literal"
7368
Lit (Integer _) → "integer literal"
7469
Lit (Decimal _) → "decimal literal"
75-
Comment str"comment"
70+
Comment _"comment"
7671

7772
op m. Monad m P.ParserT String m Token
7873
op = map Op $ PC.choice $ map PS.string operators
@@ -181,9 +176,6 @@ keywords = Set.fromFoldable
181176
, "all"
182177
]
183178

184-
digits Array Char
185-
digits = ['0','1','2','3','4','5','6','7','8','9' ]
186-
187179
identOrKeyword m. Monad m P.ParserT String m Token
188180
identOrKeyword = quotedIdent <|> notQuotedIdentOrKeyword
189181

@@ -215,9 +207,10 @@ quotedIdent =
215207
$ map S.fromCharArray
216208
$ A.some (PC.asErrorMessage "identifier character" identChar)
217209
where
218-
identChar = identEscape <|> identLetter
210+
identChar = identSlash <|> identEscape <|> identLetter
219211
identLetter = PS.satisfy (not ∘ eq '`')
220212
identEscape = PS.string "\\`" $> '`'
213+
identSlash = PS.string "\\\\" $> '\\'
221214

222215
notQuotedIdentOrKeyword m. Monad m P.ParserT String m Token
223216
notQuotedIdentOrKeyword = do

src/SqlSquared/Signature.purs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -588,24 +588,24 @@ genLetP n = do
588588

589589
genQueryExprP m t. Int GenSql m t
590590
genQueryExprP n
591-
| n < 2 = Gen.oneOf $ genQueryP n :| [ genDefinedExprP n ]
591+
| n < 2 = Gen.oneOf $ genQueryP :| [ genDefinedExprP n ]
592592
| otherwise = do
593593
op ←
594594
Gen.elements $ BO.Limit :|
595595
[ BO.Offset, BO.Sample, BO.Union
596596
, BO.UnionAll, BO.Intersect, BO.IntersectAll
597597
, BO.Except
598598
]
599-
lhs ← Gen.oneOf $ genQueryP n :| [ genDefinedExprP n ]
600-
rhs ← Gen.oneOf $ genQueryP n :| [ genDefinedExprP n ]
599+
lhs ← Gen.oneOf $ genQueryP :| [ genDefinedExprP n ]
600+
rhs ← Gen.oneOf $ genQueryP :| [ genDefinedExprP n ]
601601
pure $ embed $ Binop { op, lhs, rhs }
602602

603603
genDefinedExprP m t. Int GenSql m t
604604
genDefinedExprP n = do
605605
binops ← Gen.resize (const n) $ Gen.unfoldable BO.genBinaryOperator
606606
unops ← Gen.resize (const n) $ Gen.unfoldable UO.genUnaryOperator
607-
start ← genPrimaryExprP n
608-
adds ← Gen.resize (const n) $ Gen.unfoldable $ genPrimaryExprP n
607+
start ← genPrimaryExprP
608+
adds ← Gen.resize (const n) $ Gen.unfoldable $ genPrimaryExprP
609609
pure $ F.foldl foldFn start $ A.zip binops $ A.zip unops adds
610610
where
611611
foldFn acc (binop × unop × rhs) =
@@ -617,39 +617,39 @@ genDefinedExprP n = do
617617
, expr: embed $ Binop { lhs: acc, rhs, op:binop }
618618
}
619619

620-
genPrimaryExprP m t. Int GenSql m t
621-
genPrimaryExprP n =
620+
genPrimaryExprP m t. GenSql m t
621+
genPrimaryExprP =
622622
Gen.oneOf $ genLeaf :|
623-
[ genCaseP n
624-
, genUnaryP n
625-
, genFunctionP n
626-
, genSetP n
627-
, genArrayP n
628-
, genMapP n
629-
, genSpliceP n
623+
[ genCaseP
624+
, genUnaryP
625+
, genFunctionP
626+
, genSetP
627+
, genArrayP
628+
, genMapP
629+
, genSpliceP
630630
, map (embed ∘ Identifier) ID.genIdent
631631
]
632632

633-
genCaseP m t. Int GenSql m t
634-
genCaseP n = genLeaf
633+
genCaseP m t. GenSql m t
634+
genCaseP = genLeaf
635635

636-
genUnaryP m t. Int GenSql m t
637-
genUnaryP n = genLeaf
636+
genUnaryP m t. GenSql m t
637+
genUnaryP = genLeaf
638638

639-
genFunctionP m t. Int GenSql m t
640-
genFunctionP n = genLeaf
639+
genFunctionP m t. GenSql m t
640+
genFunctionP = genLeaf
641641

642-
genSetP m t. Int GenSql m t
643-
genSetP n = genLeaf
642+
genSetP m t. GenSql m t
643+
genSetP = genLeaf
644644

645-
genArrayP m t. Int GenSql m t
646-
genArrayP n = genLeaf
645+
genArrayP m t. GenSql m t
646+
genArrayP = genLeaf
647647

648-
genMapP m t. Int GenSql m t
649-
genMapP n = genLeaf
648+
genMapP m t. GenSql m t
649+
genMapP = genLeaf
650650

651-
genSpliceP m t. Int GenSql m t
652-
genSpliceP n = pure $ embed $ Splice Nothing
651+
genSpliceP m t. GenSql m t
652+
genSpliceP = pure $ embed $ Splice Nothing
653653

654-
genQueryP m t. Int GenSql m t
655-
genQueryP n = genLeaf
654+
genQueryP m t. GenSql m t
655+
genQueryP = genLeaf

src/SqlSquared/Signature/Case.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ derive instance eqCase ∷ Eq a ⇒ Eq (Case a)
1616
derive instance ordCaseOrd a Ord (Case a)
1717

1818
instance foldableCaseF.Foldable Case where
19-
foldMap f (Case { cond, expr }) = f expr
19+
foldMap f (Case { expr }) = f expr
2020
foldl f a (Case { cond, expr }) = f (f a cond) expr
2121
foldr f a (Case { cond, expr }) = f cond $ f expr a
2222

src/SqlSquared/Signature/Ident.purs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import Prelude
88

99
import Control.Monad.Gen as Gen
1010
import Data.Generic.Rep (class Generic)
11-
import Data.Generic.Rep.Show (genericShow)
1211
import Data.Int as Int
1312
import Data.Newtype (class Newtype)
1413
import Data.NonEmpty ((:|))
1514
import Data.Set as Set
15+
import Data.Show.Generic (genericShow)
1616
import Data.String as S
1717
import Data.String.Regex as RX
1818
import Data.String.Regex.Flags as RXF
@@ -31,14 +31,17 @@ printIdent ∷ Ident → String
3131
printIdent (Ident ident) =
3232
if RX.test identifier ident && not (Set.member (S.toLower ident) keywords)
3333
then ident
34-
else "`" <> RX.replace tick ("\\`") ident <> "`"
34+
else "`" <> RX.replace slash ("\\\\") (RX.replace tick ("\\`") ident) <> "`"
3535

3636
identifier RX.Regex
3737
identifier = RXU.unsafeRegex "^[a-z][_a-z0-9]*$" RXF.ignoreCase
3838

3939
tick RX.Regex
4040
tick = RXU.unsafeRegex "`" RXF.global
4141

42+
slash RX.Regex
43+
slash = RXU.unsafeRegex "\\\\" RXF.global
44+
4245
genIdent m. Gen.MonadGen m m Ident
4346
genIdent = do
4447
start ← Gen.elements $ "a" :| S.split (S.Pattern "") "bcdefghijklmnopqrstuvwxyz"

0 commit comments

Comments
 (0)