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

Commit 1c58d92

Browse files
committed
Change args property to node instead of array.
Instead of an array, for the `args` property of an AST node, it will now contain an expression list node containing the arguments on the `expression` property. ``` json { "type": "expression", "variant": "list", "expression": [] } ```
1 parent 4cc2e27 commit 1c58d92

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ All notable changes to this project will be documented in this file.
272272
}
273273
```
274274

275+
- **BREAKING CHANGE** Instead of an array, for the `args` property of an AST node, it will now contain an expression list node containing the arguments on the `expression` property.
276+
277+
``` json
278+
{
279+
"type": "expression",
280+
"variant": "list",
281+
"expression": []
282+
}
283+
```
284+
275285
### Fixed
276286
- Fixed binary expression parsing logic so that it can handle expressions such as:
277287

src/grammar.pegjs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ type_definition_types
125125
return {
126126
'type': 'datatype',
127127
'variant': n[0],
128-
'args': [] // datatype definition arguments
129128
'affinity': n[1]
130129
};
131130
}
@@ -174,7 +173,11 @@ type_definition_args "Type Definition Arguments"
174173
= sym_popen a1:( literal_number_signed ) o a2:( definition_args_loop )? sym_pclose
175174
{
176175
return {
177-
'args': flattenAll([ a1, a2 ])
176+
'args': {
177+
'type': 'expression',
178+
'variant': 'list',
179+
'expression': flattenAll([ a1, a2 ])
180+
}
178181
};
179182
}
180183

@@ -696,11 +699,17 @@ expression_and_op
696699
/* END: Unary and Binary Expression */
697700

698701
expression_list "Expression List"
699-
= f:( expression ) o rest:( expression_list_rest )*
700-
{
702+
= l:( expression_list_loop )? o {
703+
return {
704+
'type': 'expression',
705+
'variant': 'list',
706+
'expression': isOkay(l) ? l : []
707+
};
708+
}
709+
expression_list_loop
710+
= f:( expression ) o rest:( expression_list_rest )* {
701711
return flattenAll([ f, rest ]);
702712
}
703-
704713
expression_list_rest
705714
= sym_comma e:( expression ) o
706715
{ return e; }
@@ -714,25 +723,24 @@ function_call "Function Call"
714723
{
715724
return Object.assign({
716725
'type': 'function',
717-
'name': n,
718-
'args': []
726+
'name': n
719727
}, a);
720728
}
721729

722730
function_call_args "Function Call Arguments"
723731
= s:( select_star ) {
724732
return {
725-
'args': [{
733+
'args': {
726734
'type': 'identifier',
727735
'variant': 'star',
728736
'name': s
729-
}]
737+
}
730738
};
731739
}
732740
/ d:( args_list_distinct )? e:( expression_list ) {
733-
return Object.assign({
734-
'args': e
735-
}, d);
741+
return {
742+
'args': Object.assign(e, d)
743+
};
736744
}
737745

738746
args_list_distinct
@@ -1064,7 +1072,11 @@ stmt_pragma "PRAGMA Statement"
10641072
'type': 'statement',
10651073
'variant': keyNode(s),
10661074
'target': n,
1067-
'args': (isOkay(v) ? makeArray(v) : [])
1075+
'args': {
1076+
'type': 'expression',
1077+
'variant': 'list',
1078+
'expression': v
1079+
}
10681080
};
10691081
}
10701082

@@ -1256,7 +1268,7 @@ select_core_group "GROUP BY Clause"
12561268
= f:( GROUP ) o BY o e:( expression_list ) o h:( select_core_having )?
12571269
{
12581270
return Object.assign({
1259-
'group': makeArray(e)
1271+
'group': e
12601272
}, h);
12611273
}
12621274

@@ -1598,26 +1610,13 @@ insert_value_start "VALUES Keyword"
15981610
{ return keyNode(s); }
15991611

16001612
insert_values_list
1601-
= f:( insert_values ) o b:( insert_values_loop )*
1613+
= f:( expression_list_wrapped ) o b:( insert_values_loop )*
16021614
{ return flattenAll([ f, b ]); }
16031615

16041616
insert_values_loop
1605-
= sym_comma e:( insert_values ) o
1617+
= sym_comma e:( expression_list_wrapped ) o
16061618
{ return e; }
16071619

1608-
insert_values "Insert Values List"
1609-
= sym_popen e:( expression_list ) o sym_pclose
1610-
{
1611-
return {
1612-
'type': 'values',
1613-
'variant': 'list',
1614-
'values': e
1615-
};
1616-
}
1617-
1618-
insert_select "SELECT Results Clause"
1619-
= stmt_select
1620-
16211620
expression_list_wrapped "Wrapped Expression List"
16221621
= sym_popen e:( expression_list ) o sym_pclose {
16231622
return e;
@@ -2420,8 +2419,7 @@ virtual_module
24202419
{
24212420
return Object.assign({
24222421
'type': 'module',
2423-
'name': m,
2424-
'args': []
2422+
'name': m
24252423
}, a);
24262424
}
24272425

0 commit comments

Comments
 (0)