aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-09-02 17:32:49 -0400
committerBobby <[email protected]>2022-09-02 17:32:49 -0400
commit8b33a726e9ddd95e8e566302dd8e49f773a988f5 (patch)
tree9c346f8fe2baa0cf626528c812609acd5ad21a95 /src
parent76725ec95f4f8f38c8b198ef01164311b27131dc (diff)
downloadedify-8b33a726e9ddd95e8e566302dd8e49f773a988f5.tar.xz
edify-8b33a726e9ddd95e8e566302dd8e49f773a988f5.zip
Refactor and Fixed Bugs
Diffstat (limited to 'src')
-rw-r--r--src/edify/builder/builder.py30
-rw-r--r--src/edify/builder/errors.py2
-rw-r--r--src/edify/builder/helpers/core.py12
3 files changed, 22 insertions, 22 deletions
diff --git a/src/edify/builder/builder.py b/src/edify/builder/builder.py
index c1b111f..7371d0b 100644
--- a/src/edify/builder/builder.py
+++ b/src/edify/builder/builder.py
@@ -22,7 +22,7 @@ from .errors import unable_to_quantify
from .helpers.core import apply_subexpression_defaults
from .helpers.core import assertion
from .helpers.core import create_stack_frame
-from .helpers.core import deep_copy
+# from .helpers.core import deep_copy
from .helpers.core import escape_special
from .helpers.core import fuse_elements
from .helpers.quantifiers import quantifier_table
@@ -351,38 +351,38 @@ class RegexBuilder:
return next
def merge_subexpression(self, el, options, parent, increment_capture_groups):
- next_el = deep_copy(el)
+ next_el = clone(el)
if next_el['type'] == 'back_reference':
- next_el['index'] += parent['state']['total_capture_groups']
+ next_el['index'] += parent.state['total_capture_groups']
if next_el['type'] == 'capture':
increment_capture_groups()
if next_el['type'] == 'named_capture':
group_name = '{}{}'.format(options['namespace'], next_el['name']) if options['namespace'] else next_el['name']
- parent['tracked_named_group'] = group_name
+ # parent.tracked_named_group(group_name)
next_el['name'] = group_name
if next_el['type'] == 'named_back_reference':
next_el['name'] = '{}{}'.format(options['namespace'], next_el['name']) if options['namespace'] else next_el['name']
- if next_el['contains_child']:
+ if 'contains_child' in next_el:
next_el['value'] = self.merge_subexpression(next_el['value'], options, parent, increment_capture_groups)
- elif next_el['contains_children']:
+ elif 'contains_children' in next_el:
next_el['value'] = list(map(lambda e: self.merge_subexpression(e, options, parent, increment_capture_groups), next_el['value']))
if next_el['type'] == 'start_of_input':
if options['ignore_start_and_end']:
return t['noop']
- assertion(parent['state']['has_defined_start'] is False, str(start_input_already_defined()) + str(ignore_se()))
- assertion(parent['state']['has_defined_end'] is False, str(end_input_already_defined()) + str(ignore_se()))
- parent['state']['has_defined_start'] = True
+ assertion(parent.state['has_defined_start'] is False, str(start_input_already_defined()) + " " + str(ignore_se()))
+ assertion(parent.state['has_defined_end'] is False, str(end_input_already_defined()) + " " + str(ignore_se()))
+ parent.state['has_defined_start'] = True
if next_el['type'] == 'end_of_input':
- if options['ignore_start_and_end']:
+ if 'ignore_start_and_end' in options:
return t['noop']
- assertion(parent['state']['has_defined_end'] is False, str(end_input_already_defined()) + str(ignore_se()))
- parent['state']['has_defined_end'] = True
+ assertion(parent.state['has_defined_end'] is False, str(end_input_already_defined()) + str(ignore_se()))
+ parent.state['has_defined_end'] = True
return next_el
def subexpression(self, expr, opts={}):
assertion(isinstance(expr, RegexBuilder), must_be_instance("Expression", expr, "RegexBuilder"))
- assertion(len(expr['state']['stack']) == 1, can_not_call_se(expr.get_current_frame()['type']['type']))
+ assertion(len(expr.state['stack']) == 1, can_not_call_se(expr.get_current_frame()['type']['type']))
options = apply_subexpression_defaults(opts)
expr_next = clone(expr)
next = clone(self)
@@ -458,13 +458,13 @@ class RegexBuilder:
cg1 = ['optional', 'zero_or_more', 'zero_or_more_lazy', 'one_or_more', 'one_or_more_lazy']
if el['type'] in cg1:
inner = self.evaluate(el['value'])
- with_group = "(?:{})".format(inner) if el['value']['quantifiers_require_group'] else inner
+ with_group = "(?:{})".format(inner) if 'quantifiers_require_group' in el['value'] else inner
symbol = quantifier_table[el['type']]
return '{}{}'.format(with_group, symbol)
cg2 = ['between', 'between_lazy', 'at_least', 'exactly']
if el['type'] in cg2:
inner = self.evaluate(el['value'])
- with_group = "(?:{})".format(inner) if el['value']['quantifiers_require_group'] else inner
+ with_group = "(?:{})".format(inner) if 'quantifiers_require_group' in el['value'] else inner
return '{}{}'.format(with_group, quantifier_table[el['type']](el['times']))
if el['type'] == 'anything_but_string':
chars = ''.join(map(lambda c: '[^{}]'.format(c), el['value']))
diff --git a/src/edify/builder/errors.py b/src/edify/builder/errors.py
index 741d047..0d6a497 100644
--- a/src/edify/builder/errors.py
+++ b/src/edify/builder/errors.py
@@ -59,7 +59,7 @@ def must_have_a_smaller_value(a, b):
def ignore_se():
- return 'You can ignore a subexpressions startOfInput/endOfInput markers with the ignoreStartAndEnd option'
+ return 'You can ignore a subexpressions start_of_input/end_of_input markers with the ignore_start_and_end option'
def must_be_instance(value, variable_name, class_name):
diff --git a/src/edify/builder/helpers/core.py b/src/edify/builder/helpers/core.py
index e7518d3..f8cabe3 100644
--- a/src/edify/builder/helpers/core.py
+++ b/src/edify/builder/helpers/core.py
@@ -34,12 +34,12 @@ def escape_special(s):
return re.escape(s)
-def deep_copy(o):
- if isinstance(o, list):
- return [deep_copy(e) for e in o]
- if isinstance(o, dict):
- return {k: deep_copy(v) for k, v in o.items()}
- return o
+# def deep_copy(o):
+# if isinstance(o, list):
+# return [deep_copy(e) for e in o]
+# if isinstance(o, dict):
+# return {k: deep_copy(v) for k, v in o.items()}
+# return o
def apply_subexpression_defaults(expr):