From 90fd9894bebddce79f5b8041e7f82523364a619b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Dujava?= <19737748+jdujava@users.noreply.github.com> Date: Sun, 18 Aug 2024 18:12:20 +0200 Subject: [PATCH] Support argument placeholders for nested command definition (#161) When defining a command within other command, the arguments are accessed by doubling the `#` sign. Signed-off-by: Jonas Dujava --- grammar.js | 2 +- src/grammar.json | 2 +- test/corpus/commands.txt | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/grammar.js b/grammar.js index 22ce9de7a..47ae79004 100644 --- a/grammar.js +++ b/grammar.js @@ -386,7 +386,7 @@ module.exports = grammar({ word: $ => /[^\s\\%\{\},\$\[\]\(\)=\#&_\^\-\+\/\*]+/, - placeholder: $ => /#\d/, + placeholder: $ => /#+\d/, delimiter: $ => /&/, diff --git a/src/grammar.json b/src/grammar.json index a849444cb..e36d37131 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -1673,7 +1673,7 @@ }, "placeholder": { "type": "PATTERN", - "value": "#\\d" + "value": "#+\\d" }, "delimiter": { "type": "PATTERN", diff --git a/test/corpus/commands.txt b/test/corpus/commands.txt index 3e82b8f77..f6c65b782 100644 --- a/test/corpus/commands.txt +++ b/test/corpus/commands.txt @@ -195,6 +195,35 @@ Command definition with optional argument (xparse) (placeholder) (placeholder))))) +================================================================================ +Nested command definition with arguments +================================================================================ +\NewDocumentCommand{\foo}{m}{ + \DeclareDocumentCommand{\bar}{m}{#1, ##1} +} + +-------------------------------------------------------------------------------- + +(source_file + (new_command_definition + (curly_group_command_name + (command_name)) + (curly_group_spec + (text + (word))) + (curly_group + (new_command_definition + (curly_group_command_name + (command_name)) + (curly_group_spec + (text + (word))) + (curly_group + (text + (placeholder)) + (text + (placeholder))))))) + ================================================================================ Command copy (of command defined in grammar which requires a following node) ================================================================================