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:
parent
d873786710
commit
956748e10c
15 changed files with 1385 additions and 0 deletions
26
crates/snippet/grammar/grammar.js
Normal file
26
crates/snippet/grammar/grammar.js
Normal 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: $ => /([^$}]|\\[$\\}])+/,
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue