* Fix globbing at the start

This commit is contained in:
Antonio Cordero Balcazar
2026-05-22 23:29:22 +02:00
parent 9f024bebb4
commit 8c30d5ead9
3 changed files with 53 additions and 47 deletions
+2 -2
View File
@@ -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}`, `<ppp:echo name/>` or `<ppp:echo name>default<ppp:/>echo>` formats, to build a dynamic identifier.
### Filter
@@ -196,7 +196,7 @@ The format is:
| `<ppp:setwcdeffilter 'identifier' 'filter'/>` | Sets a filter |
| `<ppp:setwcdeffilter 'identifier'/>` | 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
+43 -44
View File
@@ -3,8 +3,8 @@
_WHITESPACE: /\s+/
STRING: /("(?!"").*?(?<!\\)(\\\\)*?"|'(?!'').*?(?<!\\)(\\\\)*?')/i // string with single or double quotes
BOOLEAN: /true|false/i
WC_NAME_PLAIN_START: /(?:(?!__|\$\$|\$\{|<ppp:|[('"])[a-zA-Z0-9\-.\\\/])+/u // starting characters, excluding end and other inside constructs
WC_NAME_PLAIN: /(?:(?!__|\$\$|\$\{|<ppp:|[('"])[a-zA-Z0-9\-.\\\/_#\*\?\[!\]])+/u // continuing characters, including globbing characters and anonymous wildcard mark, excluding end and other inside constructs
WC_NAME_PLAIN_START: /(?:(?!__|\$\$|\$\{|<ppp:|[('"])[a-zA-Z0-9\-.\\\/\*\?\[!\]])+/u // starting characters, excluding end and other inside constructs
WC_NAME_PLAIN: /(?:(?!__|\$\$|\$\{|<ppp:|[('"])[a-zA-Z0-9\-.\\\/\*\?\[!\]_#])+/u // continuing characters, including globbing characters and anonymous wildcard mark, excluding end and other inside constructs
INDEX: INT
IDENTIFIER: CNAME
SIMPLEVALUE: STRING | SIGNED_NUMBER | BOOLEAN
@@ -27,60 +27,59 @@ start: prompt negative_sep prompt
negative_sep: /\x1d/
// prompt composition with AND
promptcomp.4: promptcomppart ( [ ":" numpar ] ( /\bAND\b/ promptcomppart [ ":" numpar ] )+ )+
promptcomp.5: promptcomppart ( [ ":" numpar ] ( /\bAND\b/ promptcomppart [ ":" numpar ] )+ )+
promptcomppart: content
// simple prompts
?old_content.2: ( attention | scheduled | alternate | extranetworktag )+
?old_content.3: ( attention | scheduled | alternate | extranetworktag )+
//#if ALLOW_NEW_CONTENT
?content.2: ( old_content | new_content | plain | specialchars )*
?content_choice.2: ( old_content | new_content | plain_choice | specialchars_choice )*
?content_var.2: ( old_content | new_content | plain_var | specialchars_var )*
?content_negtag.2: ( old_content | new_content_negtag | plain | specialchars_negtag )*
?content_alternate.2: ( old_content | new_content | plain_alternate | specialchars_alternate )*
?content_en.2: (new_content_en | plain | specialchars )*
?content.3: ( old_content | new_content | plain | specialchars )*
?content_choice.3: ( old_content | new_content | plain_choice | specialchars_choice )*
?content_var.3: ( old_content | new_content | plain_var | specialchars_var )*
?content_negtag.3: ( old_content | new_content_negtag | plain | specialchars_negtag )*
?content_alternate.3: ( old_content | new_content | plain_alternate | specialchars_alternate )*
?content_en.3: (new_content_en | plain | specialchars )*
//#if ALLOW_WILDCARDS and ALLOW_CHOICES and ALLOW_COMMVARS
?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard | choices )+
?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard | choices )+
?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif | choices )+
?new_content.4: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard | choices )+
?new_content_negtag.4: ( variableset | variableuse | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard | choices )+
?new_content_en.4: ( variableset | variableuse | commandset | commandecho | commandif | choices )+
//#elif ALLOW_WILDCARDS and not ALLOW_CHOICES and ALLOW_COMMVARS
?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard )+
?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard )+
?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif )+
?new_content.4: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard )+
?new_content_negtag.4: ( variableset | variableuse | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard )+
?new_content_en.4: ( variableset | variableuse | commandset | commandecho | commandif )+
//#elif not ALLOW_WILDCARDS and ALLOW_CHOICES and ALLOW_COMMVARS
?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | choices )+
?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | commandext | choices )+
?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif | choices )+
?new_content.4: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | choices )+
?new_content_negtag.4: ( variableset | variableuse | commandset | commandecho | commandif | commandext | choices )+
?new_content_en.4: ( variableset | variableuse | commandset | commandecho | commandif | choices )+
//#elif ALLOW_WILDCARDS and ALLOW_CHOICES and not ALLOW_COMMVARS
?new_content.3: ( wildcard | choices )+
?new_content_negtag.3: ( wildcard | choices )+
?new_content_en.3: ( choices )+
?new_content.4: ( wildcard | choices )+
?new_content_negtag.4: ( wildcard | choices )+
?new_content_en.4: ( choices )+
//#elif ALLOW_WILDCARDS and not ALLOW_CHOICES and not ALLOW_COMMVARS
?new_content.3: ( wildcard )+
?new_content_negtag.3: ( wildcard )+
?new_content_en.3: /(?!)./ // never matches
?new_content.4: ( wildcard )+
?new_content_negtag.4: ( wildcard )+
?new_content_en.4: /(?!)./ // never matches
//#elif not ALLOW_WILDCARDS and ALLOW_CHOICES and not ALLOW_COMMVARS
?new_content.3: ( choices )+
?new_content_negtag.3: ( choices )+
?new_content_en.3: ( choices )+
?new_content.4: ( choices )+
?new_content_negtag.4: ( choices )+
?new_content_en.4: ( choices )+
//#elif not ALLOW_WILDCARDS and not ALLOW_CHOICES and ALLOW_COMMVARS
?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext )+
?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | commandext )+
?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif )+
?new_content.4: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext )+
?new_content_negtag.4: ( variableset | variableuse | commandset | commandecho | commandif | commandext )+
?new_content_en.4: ( variableset | variableuse | commandset | commandecho | commandif )+
//#else
// same as all enabled
?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard | choices )+
?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard | choices )+
?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif | choices )+
?new_content.4: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard | choices )+
?new_content_negtag.4: ( variableset | variableuse | commandset | commandecho | commandif | commandext | commandsetwcdeffilter | wildcard | choices )+
?new_content_en.4: ( variableset | variableuse | commandset | commandecho | commandif | choices )+
//#endif
//#else
?content.2: ( old_content | plain | specialchars )*
?content_choice.2: ( old_content | plain_choice | specialchars_choice )*
?content_var.2: ( old_content | plain_var | specialchars_var )*
?content_negtag.2: ( old_content | plain | specialchars_negtag )*
?content_alternate.2: ( old_content | plain_alternate | specialchars_alternate )*
?content_en.2: (plain | specialchars )*
?content.3: ( old_content | plain | specialchars )*
?content_choice.3: ( old_content | plain_choice | specialchars_choice )*
?content_var.3: ( old_content | plain_var | specialchars_var )*
?content_negtag.3: ( old_content | plain | specialchars_negtag )*
?content_alternate.3: ( old_content | plain_alternate | specialchars_alternate )*
?content_en.3: (plain | specialchars )*
//#endif
// attention modifiers
@@ -93,7 +92,7 @@ scheduled: "[" [ content ":" ] content ":" numpar "]"
// extra network tags
extranetworktag: "<" /(?!ppp:)\w+:/ encontent ">"
?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: "<ppp:ext" _WHITESPACE commandexttype _WHITESPACE commandextid [ _WHITESPACE? commandextparams ] [ _WHITESPACE? commandextif ] _WHITESPACE? ( ">" [ commandexttriggers "<ppp:/ext>" ] | "/>" )
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
+8 -1
View File
@@ -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, <lora:test2:1>- 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__", ""),