mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-06-22 15:59:45 +08:00
Move comment support out of comfy.choices and into comfy.comments module.
This commit is contained in:
parent
dcb4bdfb9b
commit
57ae0987db
@ -67,28 +67,7 @@ def translate(text, seed=None, strict=True, reescape=frozenset()):
|
|||||||
if strict:
|
if strict:
|
||||||
raise ParseError(openbrace, f"Missing matching closing brace '}}' for earlier open brace '{{'")
|
raise ParseError(openbrace, f"Missing matching closing brace '}}' for earlier open brace '{{'")
|
||||||
out.append(chosen_text)
|
out.append(chosen_text)
|
||||||
elif m := input.match(r'\/'):
|
elif m := input.match(r'[^\\\{\}\|]+'):
|
||||||
# C-style block "/* */" and line "//" comments
|
|
||||||
comment = input.prior()
|
|
||||||
if 0: pass
|
|
||||||
elif m := input.match(r'\/'):
|
|
||||||
# // line comment
|
|
||||||
if not input.match(r'.*?(?:\n|$)'):
|
|
||||||
if strict:
|
|
||||||
raise ParseLogicError(comment, f"Failed to find end of C-style // line comment")
|
|
||||||
input.match(r'.*') # consume unterminated comment (however that might be possible)
|
|
||||||
out.append('\n')
|
|
||||||
elif m := input.match(r'\*'):
|
|
||||||
# /* ... */ block comment
|
|
||||||
if not input.match(r'.*?\*\/'):
|
|
||||||
if strict:
|
|
||||||
raise ParseError(comment, f"Unterminated C-style /* ... */ block comment")
|
|
||||||
input.match(r'.*') # consume 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
|
# 1 or more non-metacharacters
|
||||||
out.append(m.group(0))
|
out.append(m.group(0))
|
||||||
else:
|
else:
|
||||||
|
|||||||
67
comfy/comments.py
Normal file
67
comfy/comments.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
|
||||||
|
import comfy.parse as parse
|
||||||
|
from comfy.parse import ParseError, ParseLogicError
|
||||||
|
|
||||||
|
def strip_c_comments(text, strict=True):
|
||||||
|
'''
|
||||||
|
Processes the text and strips out any C-style block "/* ... */" or line "// ..." comments found.
|
||||||
|
'''
|
||||||
|
out = []
|
||||||
|
input = parse.Cursor(text)
|
||||||
|
while True:
|
||||||
|
if 0: pass
|
||||||
|
elif input.match(r'\/'):
|
||||||
|
# C-style block "/* */" or line "//" comment
|
||||||
|
comment = input.prior()
|
||||||
|
if 0: pass
|
||||||
|
elif m := input.match(r'\/'):
|
||||||
|
# // line comment
|
||||||
|
if not input.match(r'.*?(?:\n|$)'):
|
||||||
|
if strict:
|
||||||
|
raise ParseLogicError(comment, f"Failed to find end of C-style // line comment")
|
||||||
|
input.match(r'.*') # consume unterminated comment (however that might be possible)
|
||||||
|
out.append('\n')
|
||||||
|
elif m := input.match(r'\*'):
|
||||||
|
# /* ... */ block comment
|
||||||
|
if not input.match(r'.*?\*\/'):
|
||||||
|
if strict:
|
||||||
|
raise ParseError(comment, f"Unterminated C-style /* ... */ block comment")
|
||||||
|
input.match(r'.*') # consume unterminated comment
|
||||||
|
out.append(' ')
|
||||||
|
else:
|
||||||
|
# it was a literal /, not a comment after all
|
||||||
|
out.append('/');
|
||||||
|
elif m := input.match(r'[^/]+'):
|
||||||
|
out.append(m.group(0))
|
||||||
|
elif input.match(r'$'):
|
||||||
|
break;
|
||||||
|
else:
|
||||||
|
raise ParseLogicError(input, f"Failed to match")
|
||||||
|
|
||||||
|
return ''.join(out)
|
||||||
|
|
||||||
|
def strip_hash_comments(text, strict=True):
|
||||||
|
'''
|
||||||
|
Processes the text and strips out any hash "# ... " comments found.
|
||||||
|
'''
|
||||||
|
out = []
|
||||||
|
input = parse.Cursor(text)
|
||||||
|
while True:
|
||||||
|
if 0: pass
|
||||||
|
elif input.match(r'\#'):
|
||||||
|
comment = input.prior()
|
||||||
|
# scripting-language-style "# ...\n" comment
|
||||||
|
if not input.match(r'.*?(?:\n|$)'):
|
||||||
|
if strict:
|
||||||
|
raise ParseLogicError(comment, f"Failed to find end of script-style # ... comment")
|
||||||
|
input.match(r'.*') # consume unterminated comment (however that might be possible)
|
||||||
|
out.append('\n')
|
||||||
|
elif m := input.match(r'[^#]+'):
|
||||||
|
out.append(m.group(0))
|
||||||
|
elif input.match(r'$'):
|
||||||
|
break;
|
||||||
|
else:
|
||||||
|
raise ParseLogicError(input, f"Failed to match")
|
||||||
|
|
||||||
|
return ''.join(out)
|
||||||
|
|
||||||
6
nodes.py
6
nodes.py
@ -15,6 +15,7 @@ import numpy as np
|
|||||||
import safetensors.torch
|
import safetensors.torch
|
||||||
|
|
||||||
import comfy.choices
|
import comfy.choices
|
||||||
|
import comfy.comments
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy"))
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy"))
|
||||||
|
|
||||||
@ -1479,8 +1480,9 @@ class DynamicPrompt:
|
|||||||
CATEGORY = "conditioning"
|
CATEGORY = "conditioning"
|
||||||
|
|
||||||
def dynamic_prompt(self, text, seed):
|
def dynamic_prompt(self, text, seed):
|
||||||
translated_prompt_text = comfy.choices.translate(text, seed=seed, strict=False, reescape=r'\()')
|
text = comfy.comments.strip_c_comments(text)
|
||||||
return (translated_prompt_text,)
|
text = comfy.choices.translate(text, seed=seed, strict=False, reescape=r'\()')
|
||||||
|
return (text,)
|
||||||
|
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user