Reorder and refactor code (#152)

Signed-off-by: Jonas Dujava <jonas.dujava@gmail.com>
pull/813/head
Jonáš Dujava 2024-07-24 16:33:35 +07:00 committed by GitHub
parent 6706f88d5b
commit 7ee50b2868
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 215 additions and 201 deletions

@ -104,10 +104,7 @@ module.exports = grammar({
$.block_comment,
$._command,
$.text,
$.displayed_equation,
$.inline_formula,
$.math_delimiter,
$.text_mode,
$._math_content,
'(',
')',
),
@ -433,6 +430,14 @@ module.exports = grammar({
//--- Math
_math_content: $ =>
choice(
$.displayed_equation,
$.inline_formula,
$.math_delimiter,
$.text_mode,
),
displayed_equation: $ =>
prec.left(
seq(choice('$$', '\\['), repeat($._root_content), choice('$$', '\\]')),
@ -443,6 +448,32 @@ module.exports = grammar({
seq(choice('$', '\\('), repeat($._root_content), choice('$', '\\)')),
),
_math_delimiter_part: $ =>
choice($.word, $.command_name, '[', ']', '(', ')', '|'),
math_delimiter: $ =>
prec.left(
seq(
field(
'left_command',
choice('\\left', '\\bigl', '\\Bigl', '\\biggl', '\\Biggl'),
),
field('left_delimiter', $._math_delimiter_part),
repeat($._root_content),
field(
'right_command',
choice('\\right', '\\bigr', '\\Bigr', '\\biggr', '\\Biggr'),
),
field('right_delimiter', $._math_delimiter_part),
),
),
text_mode: $ =>
seq(
field('command', choice('\\text', '\\intertext', '\\shortintertext')),
field('content', $.curly_group),
),
//--- Environments
begin: $ =>
@ -942,26 +973,6 @@ module.exports = grammar({
field('implementation', $.command_name),
),
_math_delimiter_part: $ =>
choice($.word, $.command_name, '[', ']', '(', ')', '|'),
math_delimiter: $ =>
prec.left(
seq(
field(
'left_command',
choice('\\left', '\\bigl', '\\Bigl', '\\biggl', '\\Biggl'),
),
field('left_delimiter', $._math_delimiter_part),
repeat($._root_content),
field(
'right_command',
choice('\\right', '\\bigr', '\\Bigr', '\\biggr', '\\Biggr'),
),
field('right_delimiter', $._math_delimiter_part),
),
),
paired_delimiter_definition: $ =>
prec.right(
seq(
@ -1192,7 +1203,7 @@ module.exports = grammar({
seq(
field(
'command',
choice('\\color', '\\pagecolor', '\\textcolor', '\\mathcolor','\\colorbox'),
choice('\\color', '\\pagecolor', '\\textcolor', '\\mathcolor', '\\colorbox'),
),
choice(
field('name', $.curly_group_text),
@ -1211,12 +1222,6 @@ module.exports = grammar({
field('paths', $.curly_group_path_list),
),
text_mode: $ =>
seq(
field('command', choice('\\text', '\\intertext', '\\shortintertext')),
field('content', $.curly_group),
),
hyperlink: $ =>
prec.right(
seq(

@ -194,19 +194,7 @@
},
{
"type": "SYMBOL",
"name": "displayed_equation"
},
{
"type": "SYMBOL",
"name": "inline_formula"
},
{
"type": "SYMBOL",
"name": "math_delimiter"
},
{
"type": "SYMBOL",
"name": "text_mode"
"name": "_math_content"
},
{
"type": "STRING",
@ -1918,6 +1906,27 @@
]
}
},
"_math_content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "displayed_equation"
},
{
"type": "SYMBOL",
"name": "inline_formula"
},
{
"type": "SYMBOL",
"name": "math_delimiter"
},
{
"type": "SYMBOL",
"name": "text_mode"
}
]
},
"displayed_equation": {
"type": "PREC_LEFT",
"value": 0,
@ -2002,6 +2011,163 @@
]
}
},
"_math_delimiter_part": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "word"
},
{
"type": "SYMBOL",
"name": "command_name"
},
{
"type": "STRING",
"value": "["
},
{
"type": "STRING",
"value": "]"
},
{
"type": "STRING",
"value": "("
},
{
"type": "STRING",
"value": ")"
},
{
"type": "STRING",
"value": "|"
}
]
},
"math_delimiter": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "left_command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\left"
},
{
"type": "STRING",
"value": "\\bigl"
},
{
"type": "STRING",
"value": "\\Bigl"
},
{
"type": "STRING",
"value": "\\biggl"
},
{
"type": "STRING",
"value": "\\Biggl"
}
]
}
},
{
"type": "FIELD",
"name": "left_delimiter",
"content": {
"type": "SYMBOL",
"name": "_math_delimiter_part"
}
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_root_content"
}
},
{
"type": "FIELD",
"name": "right_command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\right"
},
{
"type": "STRING",
"value": "\\bigr"
},
{
"type": "STRING",
"value": "\\Bigr"
},
{
"type": "STRING",
"value": "\\biggr"
},
{
"type": "STRING",
"value": "\\Biggr"
}
]
}
},
{
"type": "FIELD",
"name": "right_delimiter",
"content": {
"type": "SYMBOL",
"name": "_math_delimiter_part"
}
}
]
}
},
"text_mode": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\text"
},
{
"type": "STRING",
"value": "\\intertext"
},
{
"type": "STRING",
"value": "\\shortintertext"
}
]
}
},
{
"type": "FIELD",
"name": "content",
"content": {
"type": "SYMBOL",
"name": "curly_group"
}
}
]
},
"begin": {
"type": "PREC_RIGHT",
"value": 0,
@ -5407,129 +5573,6 @@
}
]
},
"_math_delimiter_part": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "word"
},
{
"type": "SYMBOL",
"name": "command_name"
},
{
"type": "STRING",
"value": "["
},
{
"type": "STRING",
"value": "]"
},
{
"type": "STRING",
"value": "("
},
{
"type": "STRING",
"value": ")"
},
{
"type": "STRING",
"value": "|"
}
]
},
"math_delimiter": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "left_command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\left"
},
{
"type": "STRING",
"value": "\\bigl"
},
{
"type": "STRING",
"value": "\\Bigl"
},
{
"type": "STRING",
"value": "\\biggl"
},
{
"type": "STRING",
"value": "\\Biggl"
}
]
}
},
{
"type": "FIELD",
"name": "left_delimiter",
"content": {
"type": "SYMBOL",
"name": "_math_delimiter_part"
}
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_root_content"
}
},
{
"type": "FIELD",
"name": "right_command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\right"
},
{
"type": "STRING",
"value": "\\bigr"
},
{
"type": "STRING",
"value": "\\Bigr"
},
{
"type": "STRING",
"value": "\\biggr"
},
{
"type": "STRING",
"value": "\\Biggr"
}
]
}
},
{
"type": "FIELD",
"name": "right_delimiter",
"content": {
"type": "SYMBOL",
"name": "_math_delimiter_part"
}
}
]
}
},
"paired_delimiter_definition": {
"type": "PREC_RIGHT",
"value": 0,
@ -6630,40 +6673,6 @@
}
]
},
"text_mode": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\text"
},
{
"type": "STRING",
"value": "\\intertext"
},
{
"type": "STRING",
"value": "\\shortintertext"
}
]
}
},
{
"type": "FIELD",
"name": "content",
"content": {
"type": "SYMBOL",
"name": "curly_group"
}
}
]
},
"hyperlink": {
"type": "PREC_RIGHT",
"value": 0,