Add text_mode rule for \text command

See #3.
pull/511/head
Patrick Förster 2022-03-16 20:12:58 +07:00
parent 4b11d243bc
commit 5686c9c831
5 changed files with 434654 additions and 430076 deletions

@ -63,7 +63,8 @@ module.exports = grammar({
$.text,
$.displayed_equation,
$.inline_formula,
$.math_set
$.math_set,
$.text_mode
)
),
@ -1019,5 +1020,11 @@ module.exports = grammar({
field('command', choice('\\usepgflibrary', '\\usetikzlibrary')),
field('paths', $.curly_group_path_list)
),
text_mode: $ =>
seq(
field('command', choice('\\text', '\\intertext', 'shortintertext')),
field('content', $.curly_group)
),
},
});

38
src/grammar.json vendored

@ -183,6 +183,10 @@
{
"type": "SYMBOL",
"name": "math_set"
},
{
"type": "SYMBOL",
"name": "text_mode"
}
]
}
@ -4714,6 +4718,40 @@
}
}
]
},
"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"
}
}
]
}
},
"extras": [

118
src/node-types.json vendored

@ -567,6 +567,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -887,6 +891,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -1596,6 +1604,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -1787,6 +1799,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -2084,6 +2100,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -2324,6 +2344,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -2632,6 +2656,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -3228,6 +3256,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -3779,6 +3811,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -3998,6 +4034,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -4365,6 +4405,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -4605,6 +4649,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -4873,6 +4921,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -5084,6 +5136,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -5292,6 +5348,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -5512,6 +5572,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -5728,6 +5792,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -5941,6 +6009,40 @@
]
}
},
{
"type": "text_mode",
"named": true,
"fields": {
"command": {
"multiple": false,
"required": true,
"types": [
{
"type": "\\intertext",
"named": false
},
{
"type": "\\text",
"named": false
},
{
"type": "shortintertext",
"named": false
}
]
},
"content": {
"multiple": false,
"required": true,
"types": [
{
"type": "curly_group",
"named": true
}
]
}
}
},
{
"type": "theorem_definition",
"named": true,
@ -6175,6 +6277,10 @@
"type": "text",
"named": true
},
{
"type": "text_mode",
"named": true
},
{
"type": "theorem_definition",
"named": true
@ -7056,6 +7162,10 @@
"type": "\\inputfrom",
"named": false
},
{
"type": "\\intertext",
"named": false
},
{
"type": "\\item",
"named": false
@ -7256,6 +7366,10 @@
"type": "\\svolcite",
"named": false
},
{
"type": "\\text",
"named": false
},
{
"type": "\\textcite",
"named": false
@ -7336,6 +7450,10 @@
"type": "placeholder",
"named": true
},
{
"type": "shortintertext",
"named": false
},
{
"type": "source_code",
"named": true

864478
src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -409,3 +409,90 @@ tree-sitter-latex (Issue #29)
(text
(generic_command
(command_name))))))
================================================================================
tree-sitter-latex (Issue #3) | \text
================================================================================
Let $C =\{ f \colon M \to \mathbb{R} \mid \text{$f$ is smooth} \}$.
--------------------------------------------------------------------------------
(source_file
(text
(word))
(inline_formula
(text
(word))
(text
(word))
(math_set
(text
(word)
(generic_command
(command_name))
(word)
(generic_command
(command_name))
(generic_command
(command_name)
(curly_group
(text
(word))))
(generic_command
(command_name)))
(text_mode
(curly_group
(inline_formula
(text
(word)))
(text
(word)
(word))))))
(text
(word)))
================================================================================
tree-sitter-latex (Issue #3) | \intertext
================================================================================
Let
\begin{align*}
F &= x^2 + y^2
\intertext{and similarly}
G &= x^2 - y^2.
\end{align*}
--------------------------------------------------------------------------------
(source_file
(text
(word))
(generic_environment
(begin
(curly_group_text
(text
(word))))
(text
(word)
(word))
(text
(word)
(operator)
(word))
(text_mode
(curly_group
(text
(word)
(word))))
(text
(word)
(word))
(text
(word)
(operator)
(word))
(end
(curly_group_text
(text
(word))))))