Skip to content

Commit

Permalink
Merge 0781cf3 into d6297a2
Browse files Browse the repository at this point in the history
  • Loading branch information
goto40 committed Sep 18, 2019
2 parents d6297a2 + 0781cf3 commit 1373549
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ please take a look at related PRs and issues and see if the change affects you.

### Changed

- Changed the parser rule for regex matches. Spaces are not stripped any more form
the beginning and the end of the regexp-pattern. This could be possible
**BIC** for some special cases [#208].
- Changed function name `textx.scoping.get_all_models_including_attached_models`
to `textx.scoping.get_included_models` (marked old function
as deprecated) ([#197]).
Expand Down Expand Up @@ -409,6 +412,7 @@ please take a look at related PRs and issues and see if the change affects you.
- Export to dot.


[#208]: https://github.com/textX/textX/pull/208
[#200]: https://github.com/textX/textX/issues/200
[#197]: https://github.com/textX/textX/issues/197
[#188]: https://github.com/textX/textX/issues/188
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/regressions/test_issue206_regex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import unicode_literals
from textx.metamodel import metamodel_from_str


def xtest_issue206_regex_reference1():
mm = metamodel_from_str('''
Word: ('bar' /[ ]*/)*;
''', skipws=False, debug=False)

m = mm.model_from_str('''bar bar''', debug=False)
assert m is not None


def test_issue206_regex():
mm = metamodel_from_str('''
Word: ('bar' / */)*;
''', skipws=False, debug=False)

m = mm.model_from_str('''bar bar''', debug=False)
assert m is not None
6 changes: 3 additions & 3 deletions tests/functional/test_textx_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,11 @@ def test_empty_strmatch():
def test_empty_regexmatch():
"""
Test emtpy regex match.
Note, there must be at least one space between slashes or else it will be
parsed as line comment.
Note, there must be some regex-code between slashes or else it will be
parsed as line comment, e.g. "()".
"""
grammar = """
Rule: first=/ / 'a';
Rule: first=/()/ 'a';
"""
mm = metamodel_from_str(grammar)
model = mm.model_from_str('a')
Expand Down
8 changes: 3 additions & 5 deletions textx/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def obj_ref_rule(): return ident
def class_name(): return qualified_ident

def str_match(): return string_value
def re_match(): return "/", _(r"((\\/)|[^/])*"), "/"
def re_match(): return _(r"/((?:(?:\\/)|[^/])*)/")
def ident(): return _(r'\w+')
def qualified_ident(): return _(r'\w+(\.\w+)?')
def integer(): return _(r'[-+]?[0-9]+')
Expand Down Expand Up @@ -845,10 +845,8 @@ def visit_str_match(self, node, children):
return StrMatch(to_match, ignore_case=self.metamodel.ignore_case)

def visit_re_match(self, node, children):
try:
to_match = children[0]
except IndexError:
to_match = ''
to_match = node.extra_info.group(1)
# print("**** visit_re_match, to_match == '{}'".format(to_match))
regex = RegExMatch(to_match,
ignore_case=self.metamodel.ignore_case)
try:
Expand Down

0 comments on commit 1373549

Please sign in to comment.