feat: tumblr grammar with highlights, injections, and tests
This commit is contained in:
+59
-3
@@ -10,8 +10,64 @@
|
||||
export default grammar({
|
||||
name: "tumblr",
|
||||
|
||||
extras: _ => [],
|
||||
|
||||
rules: {
|
||||
// TODO: add the actual grammar rules
|
||||
source_file: $ => "hello"
|
||||
}
|
||||
template: $ => repeat($._node),
|
||||
|
||||
_node: $ => choice(
|
||||
$.content,
|
||||
$.block_open,
|
||||
$.block_close,
|
||||
$.lang_tag,
|
||||
$.variable,
|
||||
),
|
||||
|
||||
content: _ => token(prec(-1, /([^{]|\{[^A-Za-z/])+/)),
|
||||
|
||||
block_open: $ => seq(
|
||||
$._block_open_start,
|
||||
$.block_name,
|
||||
optional($.attributes),
|
||||
"}",
|
||||
),
|
||||
|
||||
block_close: $ => seq(
|
||||
$._block_close_start,
|
||||
$.block_name,
|
||||
"}",
|
||||
),
|
||||
|
||||
lang_tag: $ => seq(
|
||||
$._lang_start,
|
||||
$.lang_text,
|
||||
"}",
|
||||
),
|
||||
|
||||
variable: $ => seq(
|
||||
"{",
|
||||
choice(
|
||||
seq($.variable_name, optional(seq("-", $.variable_modifier))),
|
||||
seq($.variable_prefix, ":", $.prefix_argument),
|
||||
),
|
||||
"}",
|
||||
),
|
||||
|
||||
attributes: $ => repeat1($.attribute),
|
||||
attribute: $ => seq($._space, $.attribute_name, "=", $.attribute_value),
|
||||
attribute_name: _ => /[A-Za-z_][A-Za-z0-9_-]*/,
|
||||
attribute_value: _ => /"[^"]*"/,
|
||||
|
||||
block_name: _ => /[A-Za-z][A-Za-z0-9_]*/,
|
||||
variable_name: _ => /[A-Z][A-Za-z0-9_]*/,
|
||||
variable_modifier: _ => /[A-Za-z0-9]+/,
|
||||
variable_prefix: _ => choice("text", "color", "font", "image"),
|
||||
prefix_argument: _ => /[A-Za-z][A-Za-z0-9 _-]*/,
|
||||
lang_text: _ => /[^}]+/,
|
||||
|
||||
_block_open_start: _ => /\{[Bb][Ll][Oo][Cc][Kk]:/,
|
||||
_block_close_start: _ => /\{\/[Bb][Ll][Oo][Cc][Kk]:/,
|
||||
_lang_start: _ => /\{[Ll][Aa][Nn][Gg]:/,
|
||||
_space: _ => /[ \t]+/,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user