Skip to content

Commit

Permalink
Fix parsing for expression tree, module level attrs, include on piped…
Browse files Browse the repository at this point in the history
… expressions and typed collection initializers (#57, #58, #59, #64)  (#66)

* Add support for module attributes

* Add support for typed collection literals

* Add support for expression trees

* Treat include and require as keywords, allowing their use in piped expressions
  • Loading branch information
andryak authored Aug 29, 2023
1 parent 2887d39 commit fca1e29
Show file tree
Hide file tree
Showing 7 changed files with 218,077 additions and 210,517 deletions.
24 changes: 23 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ const rules = {
'new',
'print',
'namespace',
'include',
'include_once',
'require',
'require_once',
$._primitive_type,
$._collection_type,
),
Expand Down Expand Up @@ -108,6 +112,8 @@ const rules = {
choice(
$._declaration,

$.module_attribute,

$.compound_statement,
$.empty_statement,
$.expression_statement,
Expand Down Expand Up @@ -145,6 +151,14 @@ const rules = {
$.const_declaration,
),

module_attribute: $ => seq(
'<<',
$.identifier,
':',
com($.qualified_identifier, opt($.arguments), ','),
'>>'
),

heredoc: $ =>
seq(
'<<<',
Expand Down Expand Up @@ -180,6 +194,7 @@ const rules = {
$.collection,
$._literal,
$._variablish,
$.expression_tree,
$.prefixed_string,
$.parenthesized_expression,
$.binary_expression,
Expand Down Expand Up @@ -407,6 +422,11 @@ const rules = {
),
),

expression_tree: $ => seq(
field('visitor', $.identifier),
token(/`[^`]*`/),
),

prefixed_string: $ => seq(field('prefix', $.identifier), $.string),

// Types
Expand Down Expand Up @@ -556,6 +576,7 @@ const rules = {
collection: $ =>
seq(
$.qualified_identifier,
opt($.type_arguments),
'{',
opt(com(choice($._expression, $.element_initializer), ',')),
'}',
Expand Down Expand Up @@ -1270,7 +1291,8 @@ module.exports = grammar({
[$.binary_expression, $.prefix_unary_expression, $.call_expression],
[$._expression, $.parameter],
[$._expression, $.type_specifier],
[$._expression, $.type_specifier, $.function_pointer],
[$._expression, $.collection, $.type_specifier, $.function_pointer],
[$._expression, $.collection, $.function_pointer],
[$._expression, $.field_initializer],
[$._expression, $.function_pointer],
[$.scoped_identifier, $._type_constant],
Expand Down
144 changes: 144 additions & 0 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 55 additions & 4 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fca1e29

Please sign in to comment.