aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/c-analyzer/c_parser/parser/_delim.py')
-rw-r--r--Tools/c-analyzer/c_parser/parser/_delim.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/Tools/c-analyzer/c_parser/parser/_delim.py b/Tools/c-analyzer/c_parser/parser/_delim.py
new file mode 100644
index 00000000000..51433a629d3
--- /dev/null
+++ b/Tools/c-analyzer/c_parser/parser/_delim.py
@@ -0,0 +1,54 @@
+import re
+import textwrap
+
+from ._regexes import _ind, STRING_LITERAL
+
+
+def parse(text, anon_name):
+ context = None
+ data = None
+ for m in DELIMITER_RE.find_iter(text):
+ before, opened, closed = m.groups()
+ delim = opened or closed
+
+ handle_segment = HANDLERS[context][delim]
+ result, context, data = handle_segment(before, delim, data)
+ if result:
+ yield result
+
+
+DELIMITER = textwrap.dedent(rf'''
+ (
+ (?:
+ [^'"()\[\]{};]*
+ {_ind(STRING_LITERAL, 3)}
+ }*
+ [^'"()\[\]{};]+
+ )? # <before>
+ (?:
+ (
+ [(\[{]
+ ) # <open>
+ |
+ (
+ [)\]};]
+ ) # <close>
+ )?
+ ''')
+DELIMITER_RE = re.compile(DELIMITER, re.VERBOSE)
+
+_HANDLERS = {
+ None: { # global
+ # opened
+ '{': ...,
+ '[': None,
+ '(': None,
+ # closed
+ '}': None,
+ ']': None,
+ ')': None,
+ ';': ...,
+ },
+ '': {
+ },
+}