Skip to content

Commit

Permalink
release 8.25.22004
Browse files Browse the repository at this point in the history
  • Loading branch information
klahnakoski committed Jan 4, 2022
2 parents f5a4616 + 7b847db commit 464b176
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
8 changes: 8 additions & 0 deletions mo_parsing/enhancement.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,14 @@ def __init__(self, expr, include=False, ignore=None, fail_on=None, engine_=None)
def min_length(self):
return 0

def __regex__(self):
prec, pattern = self.expr.__regex__()
pattern = regex_iso(prec, pattern, "+")
if self.parser_config.include:
return "*", f"(.*?{pattern})"
else:
return "+", f"(.*?){pattern}"

def parse_impl(self, string, start, do_actions=True):
instrlen = len(string)
fail = self.parser_config.fail
Expand Down
4 changes: 2 additions & 2 deletions mo_parsing/whitespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def set_whitespace(self, chars):
self.white_chars = "".join(sorted(set(chars)))
self.content = None
self.expr = None if isinstance(Empty, Expecting) else Empty()
self.regex = re.compile(self.__regex__()[1])
self.regex = re.compile(self.__regex__()[1], re.DOTALL)

def add_ignore(self, *ignore_exprs):
"""
Expand All @@ -122,7 +122,7 @@ def add_ignore(self, *ignore_exprs):
self.ignore_list.append(ignore_expr)
self.content = None
self.expr = None if isinstance(Empty, Expecting) else Empty()
self.regex = re.compile(self.__regex__()[1])
self.regex = re.compile(self.__regex__()[1], re.DOTALL)
return self

def backup(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
name='mo-parsing',
packages=["mo_parsing"],
url='https://github.com/klahnakoski/mo-parsing',
version='8.24.21357'
version='8.25.22004'
)
2 changes: 1 addition & 1 deletion setuptools.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@
"name": "mo-parsing",
"packages": ["mo_parsing"],
"url": "https://github.com/klahnakoski/mo-parsing",
"version": "8.24.21357"
"version": "8.25.22004"
}
20 changes: 17 additions & 3 deletions tests/test_regex.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# encoding: utf-8
import re

from mo_parsing import Regex, Char, LookAhead
from mo_parsing.tokens import SingleCharLiteral
from tests.test_simple_unit import PyparsingExpressionTestCase
from mo_parsing import Regex, Char, LookAhead, Whitespace
from mo_parsing.debug import Debugger
from mo_parsing.tokens import SingleCharLiteral, Literal, Keyword
from tests.test_simple_unit import PyparsingExpressionTestCase, SkipTo


class TestRegexParsing(PyparsingExpressionTestCase):
Expand Down Expand Up @@ -230,3 +231,16 @@ def test_make_complex_ident(self):
raise Exception("expecting parse error")
except Exception:
pass

def test_comment(self):
with Whitespace() as white:
white.add_ignore(Literal("/*") + SkipTo("*/", include=True))
parser = Keyword("select")+Keyword("true")
parser = parser.finalize()

result = parser.parse_string('/* \nfoo\n\n */\nselect true')

self.assertEqual(
list(result),
["select", "true"]
)

0 comments on commit 464b176

Please sign in to comment.