Files
Max Brunsfeld 25b8facc6c Convert some of the fixture grammars from JSON to JS
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.
2021-10-22 18:47:23 -06:00

32 lines
759 B
JavaScript

// This grammar has an external scanner whose `scan` method needs to be able to check for the
// validity of an *internal* token. This is done by including the names of that internal token
// (`line_break`) in the grammar's `externals` field.
module.exports = grammar({
name: 'external_and_internal_tokens',
externals: $ => [
$.string,
$.line_break,
],
extras: $ => [/\s/],
rules: {
statement: $ => seq(
$._expression,
$._expression,
$.line_break,
),
_expression: $ => choice(
$.string,
$.variable,
$.number,
),
variable: $ => /[a-z]+/,
number: $ => /\d+/,
line_break: $ => '\n',
}
});