Skip to content

Commit

Permalink
wip: declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
grantmacken committed May 31, 2023
1 parent b81fa67 commit 4a1a436
Show file tree
Hide file tree
Showing 12 changed files with 109,764 additions and 109,821 deletions.
15 changes: 12 additions & 3 deletions examples/spec/FLWOR_expressions.xq
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
( '3.12 FLWOR Expressions',
'3.12 FLWOR Expressions',
'3.12.2 For Clause',
for $y allowing empty at $j in ($x to 3)
return (),
Expand Down Expand Up @@ -84,5 +84,14 @@ return
</big-dept>,
let $i := 5,
$j := 20 * $i
return ($i, $j)
)
return ($i, $j),
'@',
$N[if (@x castable as xs:date)
then xs:date(@x) gt xs:date("2000-01-01")
else false()],
let $vat := function($art) { $art/@vat + $art/@price }
return shop/article/$vat(.),
let $ctx := shop/article,
$vat := function() { for $a in $ctx return $a/@vat + $a/@price }
return $vat()

2 changes: 1 addition & 1 deletion examples/spec/annotations.xq
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare
%java:method("java.lang.StrictMath.copySign")
%java:method ("java.lang.StrictMath.copySign")
function smath:copySign($magnitude, $sign)
external;
()
2 changes: 1 addition & 1 deletion examples/spec/construction_declaration.xq
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
declare construction strip;
declare construction;
()
3 changes: 2 additions & 1 deletion examples/spec/example.xq
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
1 instance of ( ItemType )
1 instance of ( ss:xx ),
Q{http://example.com/ns}invoice

2 changes: 1 addition & 1 deletion examples/spec/function_declaration.xq
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare
function smath:copySign($magnitude, $sign)
external;

declare function local:summary($emps as element(employee)*) as element(dept)*
declare function local:summary($emps as element(employee)*) as element(dept)*
{
for $d in fn:distinct-values($emps/deptno)
let $e := $emps[deptno = $d]
Expand Down
2 changes: 2 additions & 0 deletions examples/spec/path_expressions.xq
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ section/attribute(id),
section/@id,
div1//para,
//para[1],
$n/para,
../title,
para,
*,
xs:string,
text(),
@name,
@*,
Expand Down
5 changes: 5 additions & 0 deletions examples/spec/primary_expressions.xq
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ my:two-argument-function((1, 2), 3),
my:one-argument-function((1, 2, 3)),
my:one-argument-function(( )),
my:zero-argument-function( ),
array(),
myFunc(?),
'3.1.5.1 Evaluating Static and Dynamic Function Calls',
'Example: Partial Application of an Anonymous Function ',
let $f := function ($seq, $delim) {
Expand Down Expand Up @@ -61,11 +63,14 @@ let $m := map {
$days := ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
return fn:filter($days,$m),
-'3.1.6 Named Function References',
abs#1,
fn:abs#1,
fn:concat#5,
local:myfunc#2,
'3.1.7 Inline Function Expressions',
%local:inline ('ss')
function() as xs:integer+ { 2, 3, 5, 7, 11, 13 },
%public
function($a as xs:double, $b as xs:double) as xs:double { $a * $b },
function($a) { $a },
collection()/(let $a := . return function() { $a })
15 changes: 8 additions & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = grammar({
field('body', choice($.enclosed_expr, 'external'))
), // 32
param_list: ($) => seq($._param, repeat(seq(',', $._param))), // 33
_param: ($) => seq(field('param', $.variable), optional(field('param_type', $.type_declaration))), // 34
_param: ($) => seq('$', $._EQName, optional(field('param_type', $.type_declaration))), // 34
option_declaration: ($) => seq('declare', 'option', field('name', $._EQName), field('value', $.string_literal)), // 37
query_body: ($) => $._expr, // 38
_expr: ($) => prec(1, seq($._expr_single, repeat(seq(',', $._expr_single)))), // 39
Expand Down Expand Up @@ -179,15 +179,16 @@ module.exports = grammar({
for_clause: ($) => seq('for', $.for_binding, repeat(seq(',', $.for_binding))), // 44',
for_binding: ($) =>
seq(
$.variable,
'$',
$._EQName,
optional($.type_declaration),
optional(seq('allowing', 'empty')),
optional(seq('at', field('positional_variable', $.variable))),
'in',
field('binding_sequence', $._expr_single)
), // 45
let_clause: ($) => seq('let', $.let_binding, repeat(seq(',', $.let_binding))), // 48
let_binding: ($) => seq($.variable, optional($.type_declaration), ':=', $._expr_single), // 49
let_binding: ($) => seq('$', $._EQName, optional($.type_declaration), ':=', $._expr_single), // 49
count_clause: ($) => seq('count', $.variable), // 59
where_clause: ($) => seq('where', $._expr_single), // 60
group_by_clause: ($) => seq('group', 'by', $.grouping_spec, repeat(seq(',', $.grouping_spec))), // 61
Expand Down Expand Up @@ -232,7 +233,7 @@ module.exports = grammar({
try_catch_expr: ($) => prec(2, seq($.try_clause, $.catch_clause)), // 78
try_clause: ($) => seq('try', $.enclosed_expr), // 79
catch_clause: ($) => seq('catch', $.catch_error_list, $.enclosed_expr), // 81
catch_error_list: ($) => seq($._name_test, repeat(seq('|', $._name_test))), // 82
catch_error_list: ($) => seq($.name_test, repeat(seq('|', $.name_test))), // 82
or_expr: ($) => prec.left(3, seq(field('lhs', $._expr_single), 'or', field('rhs', $._expr_single))), // 83
and_expr: ($) => prec.left(4, seq(field('lhs', $._expr_single), 'and', field('rhs', $._expr_single))), // 84
comparison_expr: ($) => prec.left(5, seq(field('lhs', $._expr_single), $._comparison_ops, field('rhs', $._expr_single))), // 85
Expand Down Expand Up @@ -267,9 +268,9 @@ module.exports = grammar({
_forward_step: ($) => choice($.forward_axis, $.abbrev_forward_step),
forward_axis: ($) => seq(choice('child', 'descendant', 'attribute', 'self', 'descendant-or-self', 'following-sibling', 'following'), '::', $._node_test), //113
reverse_axis: ($) => seq(choice('parent', 'ancestor', 'preceding-sibling', 'preceding', 'ancestor-or-self'), '::', $._node_test), //116
abbrev_forward_step: ($) => seq(optional('@'), $._node_test),
_node_test: ($) => choice($._name_test, $._kind_test), // 118
_name_test: ($) => field('name_test', choice($._EQName, $.wildcard)), // 199
abbrev_forward_step: ($) => prec.right(seq(optional('@'), $._node_test)),
_node_test: ($) => choice($.name_test, $._kind_test), // 118
name_test: ($) => choice($._EQName, $.wildcard), // 199
wildcard: ($) => choice('*', seq($._ncname, ':*'), seq('*:', $._ncname), seq($.braced_uri_literal, '*')), // 120
_primary_expr: ($) =>
choice(
Expand Down

0 comments on commit 4a1a436

Please sign in to comment.