These tests are easier to write and maintain if the grammars are just JS, like grammars normally are. It doesn't slow the tests down significantly to shell out to `node` for each of these grammars.
32 lines
No EOL
665 B
JavaScript
32 lines
No EOL
665 B
JavaScript
module.exports = grammar({
|
|
name: 'dynamic_precedence',
|
|
|
|
extras: $ => [/\s/],
|
|
|
|
conflicts: $ => [[$.expression, $.type]],
|
|
|
|
rules: {
|
|
program: $ => choice(
|
|
$.declaration,
|
|
$.expression,
|
|
),
|
|
|
|
expression: $ => choice(
|
|
prec.left(seq($.expression, '*', $.expression)),
|
|
$.identifier
|
|
),
|
|
|
|
declaration: $ => seq(
|
|
$.type,
|
|
$.declarator,
|
|
),
|
|
|
|
declarator: $ => choice(
|
|
prec.dynamic(1, seq('*', $.identifier)),
|
|
$.identifier,
|
|
),
|
|
|
|
type: $ => $.identifier,
|
|
identifier: $ => /[a-z-A-Z]+/
|
|
}
|
|
}); |