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: $ => new_command_definition: $ =>
choice($._new_command_definition, $._newer_command_definition), choice($._new_command_definition, $._newer_command_definition, $._new_command_copy),
_new_command_definition: $ => _new_command_definition: $ =>
seq( seq(
@ -941,25 +941,37 @@ module.exports = grammar({
), ),
_newer_command_definition: $ => _newer_command_definition: $ =>
prec.right( seq(
seq( field(
field( 'command',
'command', choice(
choice( '\\NewDocumentCommand',
'\\NewDocumentCommand', '\\RenewDocumentCommand',
'\\RenewDocumentCommand', '\\ProvideDocumentCommand',
'\\ProvideDocumentCommand', '\\DeclareDocumentCommand',
'\\DeclareDocumentCommand', '\\NewExpandableDocumentCommand',
'\\NewExpandableDocumentCommand', '\\RenewExpandableDocumentCommand',
'\\RenewExpandableDocumentCommand', '\\ProvideExpandableDocumentCommand',
'\\ProvideExpandableDocumentCommand', '\\DeclareExpandableDocumentCommand',
'\\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: $ => old_command_definition: $ =>
@ -989,7 +1001,7 @@ module.exports = grammar({
), ),
environment_definition: $ => environment_definition: $ =>
choice($._environment_definition, $._newer_environment_definition), choice($._environment_definition, $._newer_environment_definition, $._new_environment_copy),
_environment_definition: $ => _environment_definition: $ =>
seq( seq(
@ -1023,6 +1035,20 @@ module.exports = grammar({
field('end', $.curly_group_impl), 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: $ => glossary_entry_definition: $ =>
seq( seq(
field('command', '\\newglossaryentry'), field('command', '\\newglossaryentry'),

@ -5309,6 +5309,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_newer_command_definition" "name": "_newer_command_definition"
},
{
"type": "SYMBOL",
"name": "_new_command_copy"
} }
] ]
}, },
@ -5429,87 +5433,134 @@
] ]
}, },
"_newer_command_definition": { "_newer_command_definition": {
"type": "PREC_RIGHT", "type": "SEQ",
"value": 0, "members": [
"content": { {
"type": "SEQ", "type": "FIELD",
"members": [ "name": "command",
{ "content": {
"type": "FIELD", "type": "CHOICE",
"name": "command", "members": [
"content": { {
"type": "CHOICE", "type": "STRING",
"members": [ "value": "\\NewDocumentCommand"
{ },
"type": "STRING", {
"value": "\\NewDocumentCommand" "type": "STRING",
}, "value": "\\RenewDocumentCommand"
{ },
"type": "STRING", {
"value": "\\RenewDocumentCommand" "type": "STRING",
}, "value": "\\ProvideDocumentCommand"
{ },
"type": "STRING", {
"value": "\\ProvideDocumentCommand" "type": "STRING",
}, "value": "\\DeclareDocumentCommand"
{ },
"type": "STRING", {
"value": "\\DeclareDocumentCommand" "type": "STRING",
}, "value": "\\NewExpandableDocumentCommand"
{ },
"type": "STRING", {
"value": "\\NewExpandableDocumentCommand" "type": "STRING",
}, "value": "\\RenewExpandableDocumentCommand"
{ },
"type": "STRING", {
"value": "\\RenewExpandableDocumentCommand" "type": "STRING",
}, "value": "\\ProvideExpandableDocumentCommand"
{ },
"type": "STRING", {
"value": "\\ProvideExpandableDocumentCommand" "type": "STRING",
}, "value": "\\DeclareExpandableDocumentCommand"
{ }
"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": "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": { "old_command_definition": {
"type": "SEQ", "type": "SEQ",
@ -5683,6 +5734,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_newer_environment_definition" "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": { "glossary_entry_definition": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [

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

@ -195,6 +195,21 @@ Command definition with optional argument (xparse)
(placeholder) (placeholder)
(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 Author command
================================================================================ ================================================================================