Skip to content

Commit

Permalink
Merge pull request tree-sitter#16 from tausbn/upstream-fixes
Browse files Browse the repository at this point in the history
Upstream fixes from QL-for-QL grammar
  • Loading branch information
tausbn authored Jul 15, 2022
2 parents b2c2364 + fd62fd9 commit 24c72ad
Show file tree
Hide file tree
Showing 9 changed files with 60,224 additions and 43,703 deletions.
90 changes: 72 additions & 18 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module.exports = grammar({
conflicts: $ => [
[$.simpleId, $.className],
[$.simpleId, $.literalId],
[$.moduleName, $.varName],
[$.simpleId, $.moduleInstantiation],
[$.className, $.moduleInstantiation],
],

extras: $ => [
Expand All @@ -20,6 +23,17 @@ module.exports = grammar({
module: $ => seq(
'module',
field("name", $.moduleName),
optional(
seq(
"<",
sep1(field('parameter', $.moduleParam), ","),
">"
)
),
optional(seq(
"implements",
sep1(field('implements', $.signatureExpr), ",")
)),
choice(
seq(
"{",
Expand Down Expand Up @@ -87,7 +101,18 @@ module.exports = grammar({
'class',
field("name", $.className),
choice(
seq('extends', sep1($.typeExpr, ","), "{", repeat($.classMember), "}"),
seq(
optional(field("extends", seq('extends', sep1($.typeExpr, ",")))),
optional(field("instanceof", seq('instanceof', sep1($.typeExpr, ",")))),
choice(
seq(
"{",
repeat($.classMember),
"}"
),
";"
)
),
$.typeAliasBody,
$.typeUnionBody
)
Expand All @@ -101,7 +126,7 @@ module.exports = grammar({
$.qldoc
),

charpred: $ => seq($.className, "(", ")", "{", $._exprOrTerm, "}"),
charpred: $ => seq($.className, "(", ")", "{", field('body', $._exprOrTerm), "}"),

memberPredicate: $ => seq(
field("returnType", choice($.predicate, $.typeExpr)),
Expand Down Expand Up @@ -185,9 +210,9 @@ module.exports = grammar({
choice(
seq(
sep($.varDecl, ","),
optional(seq("|", $._exprOrTerm, optional(seq("|", $._exprOrTerm))))
optional(seq("|", field('range', $._exprOrTerm), optional(seq("|", field('formula', $._exprOrTerm)))))
),
$._exprOrTerm
field('expr', $._exprOrTerm)
),
")"),

Expand Down Expand Up @@ -217,8 +242,15 @@ module.exports = grammar({
)
),

call_body:$ => seq("(", sep($._call_arg, ","), ")"),
unqual_agg_body:$ => seq("(", sep($.varDecl, ","), "|", optional($._exprOrTerm), optional(seq("|", $.asExprs)), ")"),
call_body: $ => seq("(", sep($._call_arg, ","), ")"),
unqual_agg_body: $ => seq(
"(",
sep($.varDecl, ","),
"|",
field('guard', optional($._exprOrTerm)),
field('asExprs', optional(seq("|", $.asExprs))),
")"
),

_call_or_unqual_agg_body: $ => choice($.call_body, $.unqual_agg_body),

Expand All @@ -232,14 +264,14 @@ module.exports = grammar({
seq(sep($.varDecl, ","),
seq(
"|",
optional($._exprOrTerm),
optional(seq("|", $.asExprs, optional($.orderBys)))
field('guard', optional($._exprOrTerm)),
optional(seq("|", field('asExprs', $.asExprs), field('orderBys', optional($.orderBys))))
)
),
sep1($.varDecl, ","),
),
),

expr_aggregate_body: $ => seq($.asExprs, optional($.orderBys)),
expr_aggregate_body: $ => seq(field('asExprs', $.asExprs), field('orderBys', optional($.orderBys))),

aggregate: $ => seq($.aggId, // Agg
optional(
Expand All @@ -259,6 +291,7 @@ module.exports = grammar({
set_literal: $ => seq(
"[",
sep($._exprOrTerm, ','),
optional(','),
"]"
),

Expand All @@ -267,10 +300,10 @@ module.exports = grammar({
expr_annotation: $ => seq(
field('name', $.annotName),
"[",
field('annot_arg',$.annotName),
field('annot_arg', $.annotName),
"]",
"(",
$._exprOrTerm,
"(",
$._exprOrTerm,
")",
),

Expand Down Expand Up @@ -302,7 +335,7 @@ module.exports = grammar({
$.range,
$.set_literal,
$.par_expr, // ParExpr
$.expr_annotation
$.expr_annotation, // ExprAnnotation
),

literal: $ => choice(
Expand Down Expand Up @@ -331,6 +364,11 @@ module.exports = grammar({

varDecl: $ => seq($.typeExpr, $.varName),

moduleParam: $ => seq(
field('signature', $.signatureExpr),
field('parameter', $.simpleId)
),

asExprs: $ => sep1($.asExpr, ","),

asExpr: $ => seq($._exprOrTerm, optional(seq('as', $.varName))),
Expand Down Expand Up @@ -363,7 +401,18 @@ module.exports = grammar({

importModuleExpr: $ => seq($.qualModuleExpr, repeat(seq("::", field("name", $.simpleId)))),

moduleExpr: $ => choice($.simpleId, seq($.moduleExpr, "::", field("name", $.simpleId))),
moduleExpr: $ => choice(
$.simpleId,
$.moduleInstantiation,
seq($.moduleExpr, "::", field("name", choice($.simpleId, $.moduleInstantiation)))
),

moduleInstantiation: $ => seq(
field("name", $.moduleName),
"<",
sep1($.signatureExpr, ","),
">"
),

primitiveType: $ => choice('boolean', 'date', 'float', 'int', 'string'),

Expand All @@ -374,20 +423,25 @@ module.exports = grammar({
dbtype: $ => /@[a-z][A-Za-z0-9_]*/,

typeExpr: $ => choice(
seq(optional(seq($.moduleExpr, "::")), field("name", $.className)),
seq(optional(seq(field("qualifier", $.moduleExpr), "::")), field("name", $.className)),
$.dbtype,
$.primitiveType
),

signatureExpr: $ => choice(
field("type_expr", $.typeExpr),
field("predicate", $.predicateExpr)
),

predicateName: $ => $._lower_id,

aritylessPredicateExpr: $ => seq(optional(seq($.moduleExpr, "::")), field("name", $.literalId)),
aritylessPredicateExpr: $ => seq(optional(seq(field('qualifier', $.moduleExpr), "::")), field("name", $.literalId)),

predicateExpr: $ => seq($.aritylessPredicateExpr, '/', $.integer),

varName: $ => $.simpleId,

aggId: $ => choice('avg', 'concat', 'strictconcat', 'count', 'max', 'min', 'rank', 'strictcount', 'strictsum', 'sum', 'any'),
aggId: $ => choice('avg', 'concat', 'strictconcat', 'count', 'max', 'min', 'rank', 'strictcount', 'strictsum', 'sum', 'any', 'unique'),

_upper_id: $ => /[A-Z][A-Za-z0-9_]*/,
_lower_id: $ => /[a-z][A-Za-z0-9_]*/,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Sam Lanning <[email protected]>",
"license": "MIT",
"devDependencies": {
"tree-sitter-cli": "^0.19.1"
"tree-sitter-cli": "^0.20.6"
},
"scripts": {
"tree-sitter": "tree-sitter",
Expand Down Expand Up @@ -42,4 +42,4 @@
"example": "examples",
"test": "test"
}
}
}
Loading

0 comments on commit 24c72ad

Please sign in to comment.