Merge pull request #63 from ryleelyman/master

remove operators from word and add sub- and superscript captures
pull/511/head
Patrick Förster 2022-12-02 19:43:55 +07:00 committed by GitHub
commit fc46fed791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 596550 additions and 591879 deletions

@ -384,13 +384,15 @@ module.exports = grammar({
$.word,
$.placeholder,
$.block_comment,
$._command
$._command,
$.superscript,
$.subscript,
)
)
)
),
word: $ => /[^\s\\%\{\},\$\[\]\(\)=\#]+/,
word: $ => /[^\s\\%\{\},\$\[\]\(\)=\#_\^\-\+\/\*]+/,
placeholder: $ => /#\d/,
@ -407,7 +409,29 @@ module.exports = grammar({
),
operator: $ =>
choice('+', '-', '*', '/', '^', '_', '<', '>', '!', '|', ':', "'"),
choice('+', '-', '*', '/', '<', '>', '!', '|', ':', "'"),
subscript: $ =>
seq('_', field(
'subscript',
choice(
$.curly_group,
$.word,
$.generic_command
)
)
),
superscript: $ =>
seq('^', field(
'superscript',
choice(
$.curly_group,
$.word,
$.generic_command
)
)
),
//--- Key / Value
@ -572,7 +596,7 @@ module.exports = grammar({
)
),
command_name: $ => /\\([^\r\n]|[@a-zA-Z:_]+\*?)?/,
command_name: $ => /\\([^\r\n]|[@a-zA-Z]+\*?)?/,
title_declaration: $ =>
seq(

80
src/grammar.json vendored

@ -1641,6 +1641,14 @@
{
"type": "SYMBOL",
"name": "_command"
},
{
"type": "SYMBOL",
"name": "superscript"
},
{
"type": "SYMBOL",
"name": "subscript"
}
]
}
@ -1649,7 +1657,7 @@
},
"word": {
"type": "PATTERN",
"value": "[^\\s\\\\%\\{\\},\\$\\[\\]\\(\\)=\\#]+"
"value": "[^\\s\\\\%\\{\\},\\$\\[\\]\\(\\)=\\#_\\^\\-\\+\\/\\*]+"
},
"placeholder": {
"type": "PATTERN",
@ -1718,14 +1726,6 @@
"type": "STRING",
"value": "/"
},
{
"type": "STRING",
"value": "^"
},
{
"type": "STRING",
"value": "_"
},
{
"type": "STRING",
"value": "<"
@ -1752,6 +1752,66 @@
}
]
},
"subscript": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "_"
},
{
"type": "FIELD",
"name": "subscript",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "curly_group"
},
{
"type": "SYMBOL",
"name": "word"
},
{
"type": "SYMBOL",
"name": "generic_command"
}
]
}
}
]
},
"superscript": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "^"
},
{
"type": "FIELD",
"name": "superscript",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "curly_group"
},
{
"type": "SYMBOL",
"name": "word"
},
{
"type": "SYMBOL",
"name": "generic_command"
}
]
}
}
]
},
"key_value_pair": {
"type": "SEQ",
"members": [
@ -3115,7 +3175,7 @@
},
"command_name": {
"type": "PATTERN",
"value": "\\\\([^\\r\\n]|[@a-zA-Z:_]+\\*?)?"
"value": "\\\\([^\\r\\n]|[@a-zA-Z]+\\*?)?"
},
"title_declaration": {
"type": "SEQ",

@ -6105,6 +6105,30 @@
]
}
},
{
"type": "subscript",
"named": true,
"fields": {
"subscript": {
"multiple": false,
"required": true,
"types": [
{
"type": "curly_group",
"named": true
},
{
"type": "generic_command",
"named": true
},
{
"type": "word",
"named": true
}
]
}
}
},
{
"type": "subsection",
"named": true,
@ -6601,6 +6625,30 @@
]
}
},
{
"type": "superscript",
"named": true,
"fields": {
"superscript": {
"multiple": false,
"required": true,
"types": [
{
"type": "curly_group",
"named": true
},
{
"type": "generic_command",
"named": true
},
{
"type": "word",
"named": true
}
]
}
}
},
{
"type": "svg_include",
"named": true,
@ -6769,6 +6817,14 @@
"type": "placeholder",
"named": true
},
{
"type": "subscript",
"named": true
},
{
"type": "superscript",
"named": true
},
{
"type": "svg_include",
"named": true

1188221
src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -231,13 +231,13 @@ Math environment
(text
(word))))
(text
(word))
(curly_group
(text
(word)
(superscript
(curly_group
(text
(word)
(generic_command
(command_name))))
(text
(command_name)))))
(operator)
(word))
(text

@ -480,8 +480,12 @@ Let
(word))
(text
(word)
(superscript
(word))
(operator)
(word))
(word)
(superscript
(word)))
(text_mode
(curly_group
(text
@ -492,8 +496,12 @@ Let
(word))
(text
(word)
(superscript
(word))
(operator)
(word))
(word)
(superscript
(word)))
(end
(curly_group_text
(text

@ -205,3 +205,21 @@ Simple math set
(word)
(generic_command
(command_name))))
================================================================================
Subscripts and superscripts
================================================================================
Foo_{bar}^2
--------------------------------------------------------------------------------
(source_file
(text
(word)
(subscript
(curly_group
(text
(word))))
(superscript
(word))))