2018-06-11 20:18:00 +00:00
|
|
|
module.exports = grammar({
|
|
|
|
name: 'html',
|
|
|
|
|
2018-06-11 22:36:18 +00:00
|
|
|
extras: $ => [
|
|
|
|
$.comment,
|
|
|
|
/\s+/,
|
|
|
|
],
|
|
|
|
|
2018-06-11 20:18:00 +00:00
|
|
|
externals: $ => [
|
2018-06-11 22:12:01 +00:00
|
|
|
$._open_start_tag,
|
|
|
|
$._close_start_tag,
|
|
|
|
$._self_close_start_tag,
|
|
|
|
$.end_tag,
|
|
|
|
$._implicit_end_tag,
|
|
|
|
$._erroneous_end_tag,
|
2018-06-11 22:36:18 +00:00
|
|
|
$.comment,
|
2018-06-11 20:18:00 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
rules: {
|
|
|
|
fragment: $ => repeat($._node),
|
|
|
|
|
|
|
|
_node: $ => choice(
|
|
|
|
$.text,
|
2018-06-11 22:12:01 +00:00
|
|
|
$._erroneous_end_tag,
|
|
|
|
$.element
|
2018-06-11 20:18:00 +00:00
|
|
|
),
|
|
|
|
|
2018-06-11 22:12:01 +00:00
|
|
|
element: $ => choice(
|
|
|
|
seq(
|
|
|
|
$.start_tag,
|
|
|
|
repeat($._node),
|
|
|
|
choice($.end_tag, $._implicit_end_tag)
|
|
|
|
),
|
2018-06-11 20:18:00 +00:00
|
|
|
$.self_closing_tag
|
|
|
|
),
|
|
|
|
|
2018-06-11 22:12:01 +00:00
|
|
|
start_tag: $ => seq(
|
|
|
|
$._open_start_tag,
|
|
|
|
repeat($.attribute),
|
|
|
|
$._close_start_tag
|
|
|
|
),
|
2018-06-11 20:18:00 +00:00
|
|
|
|
|
|
|
self_closing_tag: $ => seq(
|
2018-06-11 22:12:01 +00:00
|
|
|
$._open_start_tag,
|
2018-06-11 20:18:00 +00:00
|
|
|
repeat($.attribute),
|
2018-06-11 22:12:01 +00:00
|
|
|
$._self_close_start_tag
|
2018-06-11 20:18:00 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
attribute: $ => seq(
|
2018-06-11 22:36:18 +00:00
|
|
|
$.attribute_name,
|
2018-06-11 20:18:00 +00:00
|
|
|
optional(seq(
|
|
|
|
'=',
|
|
|
|
choice(
|
2018-06-11 22:36:18 +00:00
|
|
|
$.attribute_value,
|
2018-06-11 20:18:00 +00:00
|
|
|
$.quoted_attribute_value
|
|
|
|
)
|
|
|
|
))
|
|
|
|
),
|
|
|
|
|
2018-06-11 22:36:18 +00:00
|
|
|
attribute_name: $ => /[^<>"'/=\s]+/,
|
|
|
|
|
|
|
|
attribute_value: $ => /[^<>"'=\s]+/,
|
2018-06-11 20:18:00 +00:00
|
|
|
|
|
|
|
quoted_attribute_value: $ => choice(
|
|
|
|
seq("'", optional(alias(/[^']+/, $.attribute_value)), "'"),
|
|
|
|
seq('"', optional(alias(/[^"]+/, $.attribute_value)), '"')
|
|
|
|
),
|
|
|
|
|
|
|
|
text: $ => /[^<>]+/
|
|
|
|
}
|
|
|
|
});
|