From 8c30d5ead994764aba5fd62a79ba208406623c9b Mon Sep 17 00:00:00 2001 From: Antonio Cordero Balcazar Date: Fri, 22 May 2026 20:30:26 +0200 Subject: [PATCH] * Fix globbing at the start --- docs/SYNTAX.md | 4 +- grammar.lark | 87 ++++++++++++++++++++-------------------- tests/tests_wildcards.py | 9 ++++- 3 files changed, 53 insertions(+), 47 deletions(-) diff --git a/docs/SYNTAX.md b/docs/SYNTAX.md index fcf71d8..0fd58ff 100644 --- a/docs/SYNTAX.md +++ b/docs/SYNTAX.md @@ -88,7 +88,7 @@ The parameters, the filter, and the setting of a variable are optional. The para ### Identifier * Allowed characters are letters, numbers, underscore (`_`), dash (`-`), dot (`.`), and the path separators (`/` and `\`). It cannot start with an underscore because it would be ambiguous whether it's part of the name or just precedes the wildcard. -* Can have a relative path and contain globbing formatting, to read multiple wildcards and merge their choices. Note that if there are no parameters specified, the globbing will use the ones from the first wildcard that matches and have parameters (sorted by keys), so if you don't want that you might want to specify them. Also note that, unlike with *Dynamic Prompts*, the wildcard name has to be specified with its full path (unless you use globbing). Globbing cannot be at the start (you can't do, for example, `*/colors`). +* Can have a relative path and contain globbing formatting, to read multiple wildcards and merge their choices. Note that if there are no parameters specified, the globbing will use the ones from the first wildcard that matches and have parameters (sorted by keys), so if you don't want that you might want to specify them. Also note that, unlike with *Dynamic Prompts*, the wildcard name has to be specified with its full path (unless you use globbing). * You can use variables, with the `${name}`, `${name:default}`, `` or `defaultecho>` formats, to build a dynamic identifier. ### Filter @@ -196,7 +196,7 @@ The format is: | `` | Sets a filter | | `` | Removes the filter | -The wildcard identifier supports globbing (but not at the start). The filter does not allow the `^` or `#` flags. +The wildcard identifier supports globbing. The filter does not allow the `^` or `#` flags. ## Variables diff --git a/grammar.lark b/grammar.lark index ca4a47c..281ed60 100644 --- a/grammar.lark +++ b/grammar.lark @@ -3,8 +3,8 @@ _WHITESPACE: /\s+/ STRING: /("(?!"").*?(?" -?encontent.3: content_en +?encontent.4: content_en //#if ALLOW_COMMVARS or ALLOW_CHOICES or ALLOW_WILDCARDS vardescriptor_get.8: VARNAME [ /\[/ [ SIGNED_NUMBER | IDENTIFIER | separator_descriptor | /#/ ] /\]/ ] @@ -151,10 +150,10 @@ extranetworktag: "<" /(?!ppp:)\w+:/ encontent ">" // command: ext commandext: "" [ commandexttriggers "" ] | "/>" ) commandexttype: [/\$/] IDENTIFIER - ?commandextid.2: STRING | CNAME + ?commandextid.3: STRING | CNAME ?commandextparams: STRING | SIGNED_NUMBER ?commandextif: "if" _WHITESPACE condition - ?commandexttriggers.3: content + ?commandexttriggers.4: content //#endif //#if ALLOW_CHOICES or ALLOW_WILDCARDS diff --git a/tests/tests_wildcards.py b/tests/tests_wildcards.py index 33ee2f8..ff62f4d 100644 --- a/tests/tests_wildcards.py +++ b/tests/tests_wildcards.py @@ -364,11 +364,18 @@ class TestWildcards(TestPromptPostProcessorBase): def test_wc_wildcard_globbing(self): # wildcard with globbing self.process( - InputTuple("the choices are: __yaml/wildcard[12]__, __yaml/wildcard?__", ""), + InputTuple("the choices are: __yaml/*card[12]__, __yaml/wildcard?__", ""), OutputTuple("the choices are: choice3-choice2, - choice2 -choice3", ""), ppp="nocup", ) + def test_wc_wildcard_globbing2(self): # wildcard with globbing + self.process( + InputTuple("the choices are: __*/wildcard1__", ""), + OutputTuple("the choices are: choice2", ""), + ppp="nocup", + ) + def test_wc_wildcardwithvar(self): # wildcard with inline variable self.process( InputTuple("the choices are: __yaml/wildcard5(var=test)__, __yaml/wildcard5__", ""),