Skip to content

Commit b3b867c

Browse files
committed
Merge pull request forward#18 from haskellcamargo/master
Implemented function call without parameters and subselects as fields
2 parents 3403bf7 + c4451fd commit b3b867c

8 files changed

Lines changed: 142 additions & 63 deletions

File tree

‎Cakefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{spawn, exec} = require 'child_process'
22
fs = require('fs')
3+
require('coffee-script/register')
34

45
run = (args, cb) ->
56
proc = spawn './node_modules/.bin/coffee', args

‎browser/sql-parser.js‎

Lines changed: 56 additions & 30 deletions
Large diffs are not rendered by default.

‎lib/compiled_parser.js‎

Lines changed: 33 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/grammar.js‎

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/lexer.js‎

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/nodes.js‎

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/grammar.coffee‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ grammar =
149149
o 'Value SUB_SELECT_OP LEFT_PAREN List RIGHT_PAREN', -> new Op($2, $1, $4)
150150
o 'Value SUB_SELECT_OP SubSelectExpression', -> new Op($2, $1, $3)
151151
o 'SUB_SELECT_UNARY_OP SubSelectExpression', -> new UnaryOp($1, $2)
152+
o 'SubSelectExpression'
152153
o 'Value'
153154
]
154155

@@ -201,6 +202,7 @@ grammar =
201202
]
202203

203204
UserFunction: [
205+
o "LITERAL LEFT_PAREN RIGHT_PAREN", -> new FunctionValue($1, null, true)
204206
o "LITERAL LEFT_PAREN AggregateArgumentList RIGHT_PAREN", -> new FunctionValue($1, $3, true)
205207
]
206208

‎test/grammar.spec.coffee‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ describe "SQL Grammar", ->
8686
OFFSET 30
8787
"""
8888

89+
it "parses SELECTs with FUNCTIONs without arguments", ->
90+
parse("SELECT X(Y(Z())) FROM X").toString().should.eql """
91+
SELECT X(Y(Z()))
92+
FROM `X`
93+
"""
94+
8995
it "parses SELECTs with FUNCTIONs", ->
9096
parse("SELECT a, COUNT(1, b) FROM my_table LIMIT 10").toString().should.eql """
9197
SELECT `a`, COUNT(1, `b`)
@@ -301,6 +307,15 @@ describe "SQL Grammar", ->
301307
"""
302308

303309
describe "subselect clauses", ->
310+
it "parses a subselect field", ->
311+
parse("""select (select x from y) from a""").toString().should.eql """
312+
SELECT (
313+
SELECT `x`
314+
FROM `y`
315+
)
316+
FROM `a`
317+
"""
318+
304319
it "parses an IN clause containing a list", ->
305320
parse("""select * from a where x in (1,2,3)""").toString().should.eql """
306321
SELECT *
@@ -352,7 +367,7 @@ describe "SQL Grammar", ->
352367
"""
353368

354369
describe "STARS", ->
355-
it "parses stars as multiplcation", ->
370+
it "parses stars as multiplication", ->
356371
parse('SELECT * FROM foo WHERE a = 1*2').toString().should.eql """
357372
SELECT *
358373
FROM `foo`

0 commit comments

Comments
 (0)