mirror of
https://github.com/hanzoai/ast.git
synced 2026-11-02 19:28:21 +00:00
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
759 B
JavaScript
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',
|
|
}
|
|
}); |