Add snippet crate

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Max Brunsfeld 2022-02-01 10:42:14 -08:00
parent d873786710
commit 956748e10c
15 changed files with 1385 additions and 0 deletions

View file

@ -0,0 +1,26 @@
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: $ => /([^$}]|\\[$\\}])+/,
}
})