Implement *Copy macros for commands/environments (#154)

This completes the implementation of all command/environment
definition macros which are provided by LaTeX kernel and
described in https://ctan.org/pkg/usrguide.

Signed-off-by: Jonas Dujava <jonas.dujava@gmail.com>
pull/813/head
Jonáš Dujava 2024-07-27 22:14:14 +07:00 committed by GitHub
parent f074e142ad
commit f23cf647fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 292 additions and 102 deletions

@ -911,7 +911,7 @@ module.exports = grammar({
),
new_command_definition: $ =>
choice($._new_command_definition, $._newer_command_definition),
choice($._new_command_definition, $._newer_command_definition, $._new_command_copy),
_new_command_definition: $ =>
seq(
@ -941,25 +941,37 @@ module.exports = grammar({
),
_newer_command_definition: $ =>
prec.right(
seq(
field(
'command',
choice(
'\\NewDocumentCommand',
'\\RenewDocumentCommand',
'\\ProvideDocumentCommand',
'\\DeclareDocumentCommand',
'\\NewExpandableDocumentCommand',
'\\RenewExpandableDocumentCommand',
'\\ProvideExpandableDocumentCommand',
'\\DeclareExpandableDocumentCommand',
),
seq(
field(
'command',
choice(
'\\NewDocumentCommand',
'\\RenewDocumentCommand',
'\\ProvideDocumentCommand',
'\\DeclareDocumentCommand',
'\\NewExpandableDocumentCommand',
'\\RenewExpandableDocumentCommand',
'\\ProvideExpandableDocumentCommand',
'\\DeclareExpandableDocumentCommand',
),
),
field('declaration', choice($.curly_group_command_name, $.command_name)),
field('spec', $.curly_group_spec),
field('implementation', $.curly_group),
),
_new_command_copy: $ =>
seq(
field(
'command',
choice(
'\\NewCommandCopy',
'\\RenewCommandCopy',
'\\DeclareCommandCopy',
),
field('declaration', choice($.curly_group_command_name, $.command_name)),
field('spec', $.curly_group_spec),
field('implementation', $.curly_group),
),
field('declaration', choice($.curly_group_command_name, $.command_name)),
field('implementation', $.curly_group_command_name),
),
old_command_definition: $ =>
@ -989,7 +1001,7 @@ module.exports = grammar({
),
environment_definition: $ =>
choice($._environment_definition, $._newer_environment_definition),
choice($._environment_definition, $._newer_environment_definition, $._new_environment_copy),
_environment_definition: $ =>
seq(
@ -1023,6 +1035,20 @@ module.exports = grammar({
field('end', $.curly_group_impl),
),
_new_environment_copy: $ =>
seq(
field(
'command',
choice(
'\\NewEnvironmentCopy',
'\\RenewEnvironmentCopy',
'\\DeclareEnvironmentCopy',
),
),
field('name', $.curly_group_text),
field('name', $.curly_group_text),
),
glossary_entry_definition: $ =>
seq(
field('command', '\\newglossaryentry'),

@ -5309,6 +5309,10 @@
{
"type": "SYMBOL",
"name": "_newer_command_definition"
},
{
"type": "SYMBOL",
"name": "_new_command_copy"
}
]
},
@ -5429,87 +5433,134 @@
]
},
"_newer_command_definition": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\NewDocumentCommand"
},
{
"type": "STRING",
"value": "\\RenewDocumentCommand"
},
{
"type": "STRING",
"value": "\\ProvideDocumentCommand"
},
{
"type": "STRING",
"value": "\\DeclareDocumentCommand"
},
{
"type": "STRING",
"value": "\\NewExpandableDocumentCommand"
},
{
"type": "STRING",
"value": "\\RenewExpandableDocumentCommand"
},
{
"type": "STRING",
"value": "\\ProvideExpandableDocumentCommand"
},
{
"type": "STRING",
"value": "\\DeclareExpandableDocumentCommand"
}
]
}
},
{
"type": "FIELD",
"name": "declaration",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "curly_group_command_name"
},
{
"type": "SYMBOL",
"name": "command_name"
}
]
}
},
{
"type": "FIELD",
"name": "spec",
"content": {
"type": "SYMBOL",
"name": "curly_group_spec"
}
},
{
"type": "FIELD",
"name": "implementation",
"content": {
"type": "SYMBOL",
"name": "curly_group"
}
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\NewDocumentCommand"
},
{
"type": "STRING",
"value": "\\RenewDocumentCommand"
},
{
"type": "STRING",
"value": "\\ProvideDocumentCommand"
},
{
"type": "STRING",
"value": "\\DeclareDocumentCommand"
},
{
"type": "STRING",
"value": "\\NewExpandableDocumentCommand"
},
{
"type": "STRING",
"value": "\\RenewExpandableDocumentCommand"
},
{
"type": "STRING",
"value": "\\ProvideExpandableDocumentCommand"
},
{
"type": "STRING",
"value": "\\DeclareExpandableDocumentCommand"
}
]
}
]
}
},
{
"type": "FIELD",
"name": "declaration",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "curly_group_command_name"
},
{
"type": "SYMBOL",
"name": "command_name"
}
]
}
},
{
"type": "FIELD",
"name": "spec",
"content": {
"type": "SYMBOL",
"name": "curly_group_spec"
}
},
{
"type": "FIELD",
"name": "implementation",
"content": {
"type": "SYMBOL",
"name": "curly_group"
}
}
]
},
"_new_command_copy": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\NewCommandCopy"
},
{
"type": "STRING",
"value": "\\RenewCommandCopy"
},
{
"type": "STRING",
"value": "\\DeclareCommandCopy"
}
]
}
},
{
"type": "FIELD",
"name": "declaration",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "curly_group_command_name"
},
{
"type": "SYMBOL",
"name": "command_name"
}
]
}
},
{
"type": "FIELD",
"name": "implementation",
"content": {
"type": "SYMBOL",
"name": "curly_group_command_name"
}
}
]
},
"old_command_definition": {
"type": "SEQ",
@ -5683,6 +5734,10 @@
{
"type": "SYMBOL",
"name": "_newer_environment_definition"
},
{
"type": "SYMBOL",
"name": "_new_environment_copy"
}
]
},
@ -5810,6 +5865,48 @@
}
]
},
"_new_environment_copy": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "command",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\\NewEnvironmentCopy"
},
{
"type": "STRING",
"value": "\\RenewEnvironmentCopy"
},
{
"type": "STRING",
"value": "\\DeclareEnvironmentCopy"
}
]
}
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "curly_group_text"
}
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "curly_group_text"
}
}
]
},
"glossary_entry_definition": {
"type": "SEQ",
"members": [

@ -3184,7 +3184,7 @@
},
"begin": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "curly_group_impl",
@ -3200,10 +3200,18 @@
"type": "\\DeclareDocumentEnvironment",
"named": false
},
{
"type": "\\DeclareEnvironmentCopy",
"named": false
},
{
"type": "\\NewDocumentEnvironment",
"named": false
},
{
"type": "\\NewEnvironmentCopy",
"named": false
},
{
"type": "\\ProvideDocumentEnvironment",
"named": false
@ -3212,6 +3220,10 @@
"type": "\\RenewDocumentEnvironment",
"named": false
},
{
"type": "\\RenewEnvironmentCopy",
"named": false
},
{
"type": "\\newenvironment",
"named": false
@ -3224,7 +3236,7 @@
},
"end": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "curly_group_impl",
@ -3233,7 +3245,7 @@
]
},
"name": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
@ -5302,6 +5314,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "\\DeclareCommandCopy",
"named": false
},
{
"type": "\\DeclareDocumentCommand",
"named": false
@ -5326,6 +5342,10 @@
"type": "\\DeclareRobustCommand*",
"named": false
},
{
"type": "\\NewCommandCopy",
"named": false
},
{
"type": "\\NewDocumentCommand",
"named": false
@ -5342,6 +5362,10 @@
"type": "\\ProvideExpandableDocumentCommand",
"named": false
},
{
"type": "\\RenewCommandCopy",
"named": false
},
{
"type": "\\RenewDocumentCommand",
"named": false
@ -5407,6 +5431,10 @@
{
"type": "curly_group",
"named": true
},
{
"type": "curly_group_command_name",
"named": true
}
]
},
@ -8499,6 +8527,10 @@
"type": "\\Crefrange*",
"named": false
},
{
"type": "\\DeclareCommandCopy",
"named": false
},
{
"type": "\\DeclareDocumentCommand",
"named": false
@ -8507,6 +8539,10 @@
"type": "\\DeclareDocumentEnvironment",
"named": false
},
{
"type": "\\DeclareEnvironmentCopy",
"named": false
},
{
"type": "\\DeclareExpandableDocumentCommand",
"named": false
@ -8671,6 +8707,10 @@
"type": "\\Glsuservi",
"named": false
},
{
"type": "\\NewCommandCopy",
"named": false
},
{
"type": "\\NewDocumentCommand",
"named": false
@ -8679,6 +8719,10 @@
"type": "\\NewDocumentEnvironment",
"named": false
},
{
"type": "\\NewEnvironmentCopy",
"named": false
},
{
"type": "\\NewExpandableDocumentCommand",
"named": false
@ -8711,6 +8755,10 @@
"type": "\\Pvolcite",
"named": false
},
{
"type": "\\RenewCommandCopy",
"named": false
},
{
"type": "\\RenewDocumentCommand",
"named": false
@ -8719,6 +8767,10 @@
"type": "\\RenewDocumentEnvironment",
"named": false
},
{
"type": "\\RenewEnvironmentCopy",
"named": false
},
{
"type": "\\RenewExpandableDocumentCommand",
"named": false

@ -195,6 +195,21 @@ Command definition with optional argument (xparse)
(placeholder)
(placeholder)))))
================================================================================
Command copy (of command defined in grammar which requires a following node)
================================================================================
\NewCommandCopy{\foo}{\ref}
--------------------------------------------------------------------------------
(source_file
(new_command_definition
(curly_group_command_name
(command_name))
(curly_group_command_name
(command_name))))
================================================================================
Author command
================================================================================