Проблема
Учитывая простой класс vb.net, парсер должен правильно обрабатывать поля как с помощью одиночных, так и с множественными модификаторами. PrettyPrint-Override ">
Код: Выделить всё
Public Class MyTestClass
' This line with a single modifier parses correctly.
Private _someField As String
' This line with multiple modifiers fails.
Private ReadOnly _anotherField As Integer
End Class
Код: Выделить всё
(field_declaration
(modifiers
(member_modifier) -- "Private"
)
(variable_declarator
(identifier) -- "ReadOnly"
)
(ERROR) -- "_anotherField As Integer"
)
Соответствующий фрагмент грамматики (
Код: Выделить всё
grammar.js
Вот ключевые правила из моей граммамы. JS , которые участвуют в этом выпуске.
Код: Выделить всё
module.exports = grammar({
name: 'vbnet',
// ... other rules and extras
rules: {
// ...
member_modifier: $ => choice(
ci('Public'), ci('Private'), ci('Protected'), ci('Friend'),
ci('Protected Friend'), ci('Private Protected'), ci('ReadOnly'),
ci('WriteOnly'), ci('Shared'), ci('Shadows'), ci('MustInherit'),
ci('NotInheritable'), ci('Overrides'), ci('MustOverride'),
ci('NotOverridable'), ci('Overridable'), ci('Overloads'),
ci('WithEvents'), ci('Widening'), ci('Narrowing'),
ci('Partial'), ci('Async'), ci('Iterator')
),
modifiers: $ => repeat1($.member_modifier),
_type_member_declaration: $ => choice(
// ... other members like empty_statement, inherits_statement
prec(2, $.constructor_declaration),
prec(1, $.method_declaration),
prec(1, $.property_declaration),
// ... other members with precedence
$.field_declaration // Lower precedence
),
field_declaration: $ => seq(
optional(field('attributes', $.attribute_list)),
field('modifiers', $.modifiers),
commaSep1($.variable_declarator),
$._terminator
),
variable_declarator: $ => seq(
field('name', $.identifier),
optional($.array_rank_specifier),
optional($.as_clause),
optional(seq('=', field('initializer', $._expression)))
),
// ... other rules
}
});
function ci(keyword) {
return new RegExp(keyword.split('').map(letter => `[${letter.toLowerCase()}${letter.toUpperCase()}]`).join(''));
}
// ... other helpers
Как я могу изменить эту грамматику дерева-ситтеров, чтобы правильно и «жадно», все еще правильно распределяет амбиг-подряд между различными типами декларации (например, код. method_declaration )?
Подробнее здесь: https://stackoverflow.com/questions/796 ... sitter-gra