ComfyUI/comfy/comments.py
Barry Downes ed253b31df Replace comfy.parse-based comment parsers with re.sub.
Less code is better, right?
But we lost the ability to report errors for unterminated C block comments.
Current differences from the js version:
We consume unterminated C block comments.
2023-08-06 09:39:45 +10:00

13 lines
439 B
Python

import re
def strip_c_comments(text, strict=True):
# Processes the text and strips out any C-style block "/* ... */" or line "// ..." comments found.
# from old dynamicPrompts.js: return str.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,'');
return re.sub(r'/\*[.\n]*?(?:\*/|$)|//.*', '', text)
def strip_hash_comments(text, strict=True):
# Processes the text and strips out any hash "# ... " comments found.
return re.sub(r'#.*', '', text)