1import re 2import textwrap 3 4from ._regexes import _ind, STRING_LITERAL 5 6 7def parse(text, anon_name): 8 context = None 9 data = None 10 for m in DELIMITER_RE.find_iter(text): 11 before, opened, closed = m.groups() 12 delim = opened or closed 13 14 handle_segment = HANDLERS[context][delim] 15 result, context, data = handle_segment(before, delim, data) 16 if result: 17 yield result 18 19 20DELIMITER = textwrap.dedent(rf''' 21 ( 22 (?: 23 [^'"()\[\]{};]* 24 {_ind(STRING_LITERAL, 3)} 25 }* 26 [^'"()\[\]{};]+ 27 )? # <before> 28 (?: 29 ( 30 [(\[{] 31 ) # <open> 32 | 33 ( 34 [)\]};] 35 ) # <close> 36 )? 37 ''') 38DELIMITER_RE = re.compile(DELIMITER, re.VERBOSE) 39 40_HANDLERS = { 41 None: { # global 42 # opened 43 '{': ..., 44 '[': None, 45 '(': None, 46 # closed 47 '}': None, 48 ']': None, 49 ')': None, 50 ';': ..., 51 }, 52 '': { 53 }, 54} 55