mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-06-22 15:59:45 +08:00
Add C-style comment support for the dynamic prompt.
This commit is contained in:
parent
d91544b83c
commit
6a01513d09
@ -62,36 +62,41 @@ def translate_choices(text, seed=0):
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
if 0: pass
|
if 0: pass
|
||||||
elif m := input.match(r'[\\\{]'): # a single metacharacter, \ or {
|
elif m := input.match(r'\\'): # \
|
||||||
ch = m.group(0)
|
|
||||||
if 0: pass
|
if 0: pass
|
||||||
elif ch == '\\':
|
elif m := input.match(r'[\{\|\}\/]'):
|
||||||
if not (m := input.match(r'.')):
|
# escaping a metacharacter to make it literal
|
||||||
raise ParseError(input, f'Unexpected end of input after backslash')
|
out.append(m.group(0)) # output literal character
|
||||||
ch = m.group(0)
|
elif m := input.match(r'.'):
|
||||||
if 0: pass
|
# by passing through non-native or unrecognised escape codes without change, we support clean combiniation of multiple parsing phases
|
||||||
elif ch in {'\\', '(', ')'}:
|
# without forcing the user to add additional escaping for each phase
|
||||||
# these are metacharacters in the weight parsing phase, so we have to handle them specially
|
out.append(f'\\{m.group(0)}')
|
||||||
# maintain the escaping for the upcoming weight parsing phase
|
|
||||||
out.append(f'\\{ch}')
|
|
||||||
elif ch in {'{', '}', '|'}:
|
|
||||||
# escaping a metacharacter to make it literal
|
|
||||||
out.append(ch) # output literal character
|
|
||||||
else:
|
|
||||||
# other characters shouldn't require escaping
|
|
||||||
# treat it as a normal escape regardless
|
|
||||||
# policy subject to change
|
|
||||||
out.append(ch)
|
|
||||||
elif ch == '{':
|
|
||||||
# choice
|
|
||||||
chosen_text = parse_choice(input)
|
|
||||||
out.append(chosen_text)
|
|
||||||
else:
|
else:
|
||||||
raise LogicError(input, f"Expected metacharacter '\\' or '{{' ")
|
raise ParseError(input, f'Unexpected end of input after backslash')
|
||||||
elif m := input.match(r'[^\\\{\}\|]+'): # 1 or more non-metacharacters
|
elif m := input.match(r'\{'): # {
|
||||||
|
# choice
|
||||||
|
chosen_text = parse_choice(input)
|
||||||
|
out.append(chosen_text)
|
||||||
|
elif m := input.match(r'\/'): # /
|
||||||
|
# C-style block "/* */" and line "//" comments
|
||||||
|
if 0: pass
|
||||||
|
elif m := input.match(r'\/'): # /
|
||||||
|
# line comment
|
||||||
|
if not input.match(r'.*?(?:\n|$)'):
|
||||||
|
raise ParseError(input, f"Failed to find end of comment")
|
||||||
|
out.append('\n')
|
||||||
|
elif m := input.match(r'\*'): # /
|
||||||
|
# block comment
|
||||||
|
if not input.match(r'.*?\*\/'):
|
||||||
|
raise ParseError(input, f"Unterminated comment")
|
||||||
|
out.append(' ')
|
||||||
|
else:
|
||||||
|
# it was a literal /, not a comment after all
|
||||||
|
out.append('/');
|
||||||
|
elif m := input.match(r'[^\\\{\}\|\/]+'): # 1 or more non-metacharacters
|
||||||
out.append(m.group(0))
|
out.append(m.group(0))
|
||||||
else:
|
else:
|
||||||
# didn't match \, { or non-metacharacters
|
# didn't match \, {, / or non-metacharacters
|
||||||
# must be either |, } or end of input
|
# must be either |, } or end of input
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user