Commit 7d0c3289 authored by Igor Dejanovic's avatar Igor Dejanovic

Removed multiline flag.

parent 0a96eea5
...@@ -490,22 +490,17 @@ class RegExMatch(Match): ...@@ -490,22 +490,17 @@ class RegExMatch(Match):
It will be used to create regular expression using re.compile. It will be used to create regular expression using re.compile.
ignore_case(bool): If case insensitive match is needed. ignore_case(bool): If case insensitive match is needed.
Default is None to support propagation from global parser setting. Default is None to support propagation from global parser setting.
multiline(bool): If regex matching is in multiline mode.
Default is None to support propagation from global parser setting.
''' '''
def __init__(self, to_match, rule=None, ignore_case=None, multiline=None): def __init__(self, to_match, rule=None, ignore_case=None):
super(RegExMatch, self).__init__(rule) super(RegExMatch, self).__init__(rule)
self.to_match = to_match self.to_match = to_match
self.ignore_case = ignore_case self.ignore_case = ignore_case
self.multiline = multiline
def compile(self): def compile(self):
flags = 0 flags = re.MULTILINE
if self.ignore_case: if self.ignore_case:
flags |= re.IGNORECASE flags |= re.IGNORECASE
if self.multiline:
flags |= re.MULTILINE
self.regex = re.compile(self.to_match, flags) self.regex = re.compile(self.to_match, flags)
def __str__(self): def __str__(self):
...@@ -790,20 +785,17 @@ class Parser(object): ...@@ -790,20 +785,17 @@ class Parser(object):
ws (str): A string consisting of whitespace characters. ws (str): A string consisting of whitespace characters.
reduce_tree (bool): If true non-terminals with single child will be reduce_tree (bool): If true non-terminals with single child will be
eliminated from the parse tree. Default is True. eliminated from the parse tree. Default is True.
multiline(bool): If RegExMatch is going to match in multiline mode
(default=False).
ignore_case(bool): If case is ignored (default=False) ignore_case(bool): If case is ignored (default=False)
debug (bool): If true debugging messages will be printed. debug (bool): If true debugging messages will be printed.
comments_model: parser model for comments. comments_model: parser model for comments.
""" """
def __init__(self, skipws=True, ws=DEFAULT_WS, reduce_tree=False, def __init__(self, skipws=True, ws=DEFAULT_WS, reduce_tree=False,
debug=False, multiline=False, ignore_case=False): debug=False, ignore_case=False):
self.skipws = skipws self.skipws = skipws
self.ws = ws self.ws = ws
self.reduce_tree = reduce_tree self.reduce_tree = reduce_tree
self.ignore_case = ignore_case self.ignore_case = ignore_case
self.multiline = multiline
self.debug = debug self.debug = debug
self.comments_model = None self.comments_model = None
self.sem_actions = {} self.sem_actions = {}
...@@ -1081,8 +1073,6 @@ class ParserPython(Parser): ...@@ -1081,8 +1073,6 @@ class ParserPython(Parser):
# parser. # parser.
if expression.ignore_case is None: if expression.ignore_case is None:
expression.ignore_case = self.ignore_case expression.ignore_case = self.ignore_case
if expression.multiline is None:
expression.multiline = self.multiline
expression.compile() expression.compile()
retval = expression retval = expression
......
...@@ -193,8 +193,7 @@ class SemRuleCrossRef(SemanticAction): ...@@ -193,8 +193,7 @@ class SemRuleCrossRef(SemanticAction):
class SemRegEx(SemanticAction): class SemRegEx(SemanticAction):
def first_pass(self, parser, node, children): def first_pass(self, parser, node, children):
match = RegExMatch(children[0], match = RegExMatch(children[0],
ignore_case=parser.ignore_case, ignore_case=parser.ignore_case)
multiline=parser.multiline)
match.compile() match.compile()
return match return match
......
...@@ -15,11 +15,10 @@ from arpeggio import RegExMatch as _ ...@@ -15,11 +15,10 @@ from arpeggio import RegExMatch as _
from arpeggio import NoMatch from arpeggio import NoMatch
def foo(): return 'r', bar, baz, Optional(buz), Optional(ml), EOF def foo(): return 'r', bar, baz, Optional(buz), EOF
def bar(): return 'BAR' def bar(): return 'BAR'
def baz(): return _(r'1\w+') def baz(): return _(r'1\w+')
def buz(): return _(r'Aba*', ignore_case=True) def buz(): return _(r'Aba*', ignore_case=True)
def ml(): return _(r'//.*$', multiline=True)
@pytest.fixture @pytest.fixture
def parser_ci(): def parser_ci():
...@@ -39,11 +38,6 @@ def test_parse_tree_nonci(parser_nonci): ...@@ -39,11 +38,6 @@ def test_parse_tree_nonci(parser_nonci):
with pytest.raises(NoMatch): with pytest.raises(NoMatch):
parser_nonci.parse(input_str) parser_nonci.parse(input_str)
def test_parse_multiline(parser_ci):
input_str = """r bar 1baz //adfadsfadf asdfadsfadsf adfadf"""
parse_tree = parser_ci.parse(input_str)
assert parse_tree is not None
def test_flags_override(parser_nonci): def test_flags_override(parser_nonci):
# Parser is not case insensitive # Parser is not case insensitive
# But the buz match is. # But the buz match is.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment