tree-sitter.tree-sitter/test/fixtures/test_grammars/eof_duplicate_reduction/grammar.js
Amaan Qureshi 74b7d0c951 feat!: add an eof function
This commit adds an `eof()` function for grammars, which is easier to
use than the NUL byte directly. It compiles down to a constraint that
the enclosing production can only reduce at end of input, not to a
shiftable token.

BREAKING CHANGE: Public error types for `tree-sitter-generate` were modified.

Co-authored-by: Will Lillis <will.lillis24@gmail.com>
2026-08-21 20:02:58 -04:00

12 lines
426 B
JavaScript

// Both branches reduce `line` to the same single `'text'` child, differing only in
// whether the reduce is gated on end of input. Identical actions are not a conflict,
// but they still have to be compared on precedence rather than skipped.
export default grammar({
name: 'eof_duplicate_reduction',
rules: {
source_file: $ => repeat($.line),
line: _ => choice('text', seq('text', eof())),
}
});