Skip to content

Commit

Permalink
Corrected single_source for simple table lists
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyen committed Apr 23, 2011
1 parent ec760eb commit 9919f98
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
22 changes: 17 additions & 5 deletions sql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,23 @@ join_source =
s: ( whitespace single_source
( join_op whitespace single_source join_constraint )* )
{ var acc = [s[1]];
var cdr = s[2];
for (var i = 0; cdr != null && i < cdr.length; i++) {
acc[acc.length] = merge(merge(cdr[i][0], cdr[i][2]), cdr[i][3]);
var rest = s[2];
for (var i = 0; rest != null && i < rest.length; i++) {
acc[acc.length] = merge(merge(rest[i][0], rest[i][2]), rest[i][3]);
}
return acc;
}

single_source =
( ( s: ( ( t: ( table_ref ( a: ( AS whitespace table_alias )
( ( x: ( database_name dot table_name AS whitespace1 table_alias )
{ return { database: x[0], table: x[2], alias: x[5] } } )
/ ( x: ( database_name dot table_name )
{ return { database: x[0], table: x[2] } } )
/ ( x: ( table_name AS whitespace1 table_alias )
{ return { table: x[0], alias: x[3] } } )
/ ( x: table_name
{ return { table: x } } )
/ ( s: ( ( t: ( table_ref ( a: ( AS whitespace1 table_alias )
{ return { alias: a[2] } } )? )
{ return merge(t[1], t[0]) } )
( ( idx: ( INDEXED BY whitespace index_name )
Expand Down Expand Up @@ -349,7 +357,11 @@ compound_operator =
{ return { compound_operator: flatstr(o) } }

update_stmt =
( ( UPDATE ( OR ( ROLLBACK / ABORT / REPLACE / FAIL / IGNORE ) )? qualified_table_name )
( ( UPDATE ( OR ( ROLLBACK
/ ABORT
/ REPLACE
/ FAIL
/ IGNORE ) )? qualified_table_name )
( SET ( ( column_name equal expr ) comma )+ ( WHERE expr )? ) )

update_stmt_limited =
Expand Down
38 changes: 37 additions & 1 deletion views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module("PEG", {
}
});

test("basics", 2, function() {
test("smoke", 2, function() {
var parser = PEG.buildParser(sql_pegjs);
ok(parser);
var s = parser.parse(
Expand Down Expand Up @@ -79,6 +79,42 @@ test("basics", 2, function() {
]
}]);
});

test("from-clause", 2, function() {
var parser = PEG.buildParser(sql_pegjs);
ok(parser);
var s = parser.parse(
"SELECT * FROM a, b, x AS b1;");
deepEqual(s, [
{
"stmt": "select",
"select_cores": [
{
"results": [
{
"column": "*"
}
],
"from": [
{
"table": "a"
},
{
"join_constraint": null,
"table": "b",
"join_op": "JOIN"
},
{
"join_constraint": null,
"table": "x",
"alias": "b1",
"join_op": "JOIN"
}
]
}
]
}]);
});
</script>

<div>
Expand Down

0 comments on commit 9919f98

Please sign in to comment.