diff --git a/DHParser/server.py b/DHParser/server.py index cd98cdc6f1085140128f910c8986fd3d545066de..9024a884f83fbc4498899ce69b2257db348a7aa6 100644 --- a/DHParser/server.py +++ b/DHParser/server.py @@ -77,7 +77,7 @@ JSON_Type = Union[Dict, Sequence, str, int, None] RE_IS_JSONRPC = b'\s*{' # b'\s*(?:{|\[|"|\d|true|false|null)' RE_GREP_URL = b'GET ([^ \n]+) HTTP' -RE_FUNCTION_CALL = b'\s*(\w+)\(([^)\n]*)\)' +RE_FUNCTION_CALL = b'\s*(\w+)\(([^)]*)\)$' SERVER_ERROR = "COMPILER-SERVER-ERROR" diff --git a/DHParser/toolkit.py b/DHParser/toolkit.py index 9e94e20f11048718a96cbc63c5f83f30f6c4b1ca..4e37c82ab540c1fb4d2c7d59afe94258fb63d322 100644 --- a/DHParser/toolkit.py +++ b/DHParser/toolkit.py @@ -249,6 +249,8 @@ def isgenerictype(t): # ####################################################################### +RX_FILEPATH = re.compile(r'[^ \t][^\n\t?*]+(? str: """ @@ -264,7 +266,7 @@ def load_if_file(text_or_file) -> str: content = f.read() return content except FileNotFoundError: - if re.fullmatch(r'[\w/:. \\]+', text_or_file): + if RX_FILEPATH.fullmatch(text_or_file): raise FileNotFoundError('Not a valid file: ' + text_or_file + '!\n(Add "\\n" ' 'to distinguish source data from a file name.)') else: diff --git a/test/test_ebnf.py b/test/test_ebnf.py index 0badea6a22e5667d48fe81094182402ad834e8cb..b24eb3d715b82b247c54fb7e870d8fed8e14522a 100644 --- a/test/test_ebnf.py +++ b/test/test_ebnf.py @@ -185,7 +185,7 @@ class TestParserNameOverwriteBug: assert not has_errors(messages), str(messages) def test_single_mandatory_bug(self): - lang = """series = § /B/""" + lang = """series = § /B/\n""" result, messages, ast = compile_ebnf(lang) assert result.find('Required') < 0 parser = grammar_provider(lang)() @@ -415,8 +415,8 @@ class TestFlowControlOperators: """Tests whether failures to comply with the required operator '§' are correctly reported as such. """ - lang1 = r"nonsense == /\w+/~ # wrong_equal_sign" - lang2 = "nonsense = [^{}%]+ # someone forgot the '/'-delimiters for regular expressions" + lang1 = r"nonsense == /\w+/~ # wrong_equal_sign " + lang2 = "nonsense = [^{}%]+ # someone forgot the '/'-delimiters for regular expressions\n" try: parser_class = grammar_provider(lang1) assert False, "Compilation error expected." diff --git a/test/test_parse.py b/test/test_parse.py index 1f803b54fc4faa61efffbfe9ce80f07e1297f535..ba17ad98f58a8c2f4fc7296ad31bdca51a6af301 100644 --- a/test/test_parse.py +++ b/test/test_parse.py @@ -662,7 +662,7 @@ class TestErrorReporting: class TestBorderlineCases: def test_not_matching(self): - minilang = """parser = /X/""" + minilang = """parser = /X/\n""" gr = grammar_provider(minilang)() cst = gr('X', 'parser') assert not cst.error_flag diff --git a/test/test_toolkit.py b/test/test_toolkit.py index 15d6e029f33e8ce11ec52039ead24da680d32908..c639d07231a329b1740668d0646e131a10033be0 100644 --- a/test/test_toolkit.py +++ b/test/test_toolkit.py @@ -38,7 +38,7 @@ class TestLoggingAndLoading: self.filename = os.path.join("test", self.tmpname, "test.py") if os.path.isdir('test') \ else os.path.join(self.tmpname, "test.py") self.dirname = os.path.dirname(self.filename) - self.code1 = "x = 46" + self.code1 = "x = 46\n" self.code2 = "def f():\n return 46" if not os.path.exists(self.dirname): os.mkdir(self.dirname)