ZIm/crates/snippet/grammar/grammar.js
Max Brunsfeld 956748e10c Add snippet crate
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
2022-02-01 11:00:40 -08:00

26 lines
No EOL
570 B
JavaScript

module.exports = grammar({
name: 'snippet',
rules: {
snippet: $ => repeat1($._any),
_any: $ => choice(
$.tabstop,
$.placeholder,
$.text
),
tabstop: $ => choice(
seq('$', $.int),
seq('${', $.int, '}'),
),
placeholder: $ => seq('${', $.int, ':', $.snippet, '}'),
int: $ => /[0-9]+/,
text: $ => choice($._raw_curly, $._plain_text),
_raw_curly: $ => token(prec(-1, /}+/)),
_plain_text: $ => /([^$}]|\\[$\\}])+/,
}
})