Skip to content

Commit

Permalink
Adds necessary logic to support attributes. Follows the PHP interpren…
Browse files Browse the repository at this point in the history
…ters lead on disallowing comments starting with #[.
  • Loading branch information
cfroystad committed Apr 23, 2021
1 parent 4dcc061 commit a8b3ddf
Show file tree
Hide file tree
Showing 6 changed files with 62,603 additions and 57,673 deletions.
32 changes: 29 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = grammar({

[$._primary_expression, $._array_destructing],
[$._array_destructing, $.array_creation_expression],
[$.qualified_name, $.attribute],

[$.union_type, $._return_type],

Expand Down Expand Up @@ -243,6 +244,7 @@ module.exports = grammar({
),

class_declaration: $ => prec.right(seq(
optional(field('attributes', $.attribute_list)),
optional($.class_modifier),
keyword('class'),
field('name', $.name),
Expand All @@ -269,20 +271,28 @@ module.exports = grammar({
),

_member_declaration: $ => choice(
$.const_declaration,
alias($._class_const_declaration, $.const_declaration),
$.property_declaration,
$.method_declaration,
$.use_declaration
),

const_declaration: $ => seq(
const_declaration: $ => $._const_declaration,

_class_const_declaration: $ => seq(
optional(field('attributes', $.attribute_list)),
$._const_declaration
),

_const_declaration: $ => seq(
optional($.visibility_modifier),
keyword('const'),
commaSep1($.const_element),
$._semicolon
),

property_declaration: $ => seq(
optional(field('attributes', $.attribute_list)),
repeat1($._modifier),
optional(field('type', $._type)),
commaSep1($.property_element),
Expand All @@ -305,6 +315,7 @@ module.exports = grammar({
),

method_declaration: $ => seq(
optional(field('attributes', $.attribute_list)),
repeat($._modifier),
$._function_definition_header,
choice(
Expand Down Expand Up @@ -362,6 +373,7 @@ module.exports = grammar({
),

function_definition: $ => seq(
optional(field('attributes', $.attribute_list)),
$._function_definition_header,
field('body', $.compound_statement)
),
Expand All @@ -381,6 +393,7 @@ module.exports = grammar({
),

simple_parameter: $ => seq(
optional(field('attributes', $.attribute_list)),
field('type', optional($._type)),
optional('&'),
field('name', $.variable_name),
Expand All @@ -391,6 +404,7 @@ module.exports = grammar({
),

variadic_parameter: $ => seq(
optional(field('attributes', $.attribute_list)),
field('type', optional($._type)),
optional('&'),
'...',
Expand Down Expand Up @@ -1000,6 +1014,17 @@ module.exports = grammar({
seq('[', commaSep($.array_element_initializer), optional(','), ']')
),

attribute_list: $ => repeat1(seq(
'#[',
commaSep1($.attribute),
']',
)),

attribute: $ => seq(
choice($.qualified_name, $.name),
optional(field('parameters', $.arguments))
),

string: $ => {
const b_prefix = /[bB]/
const single_quote_chars = repeat(/\\'|\\\\|\\?[^'\\]/)
Expand Down Expand Up @@ -1117,10 +1142,11 @@ module.exports = grammar({

comment: $ => token(choice(
seq(
choice('//', '#'),
choice('//', /#[^?\[?\r?\n]/),
repeat(/[^?\r?\n]|\?[^>\r\n]/),
optional(/\?\r?\n/)
),
'#',
seq(
'/*',
/[^*]*\*+([^/*][^*]*\*+)*/,
Expand Down
Loading

0 comments on commit a8b3ddf

Please sign in to comment.