Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lark/load_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

EXT = '.lark'

_RE_FLAGS = 'imslux'
_RE_FLAGS = 'imsluxaL'

_EMPTY = Symbol('__empty__')

Expand Down
7 changes: 7 additions & 0 deletions tests/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def test_flag_order_is_deterministic(self):
self.assertEqual([t.pattern.to_regexp() for t in p.terminals],
['(?u:(?s:(?m:(?i:x))))'])

def test_flag_order_with_new_flags(self):
# Test that new flag (a) works and is sorted deterministically
p = Lark('start: A+\nA: /x/ai\n', parser='lalr')
# Flags should be sorted alphabetically: a before i
self.assertEqual([t.pattern.to_regexp() for t in p.terminals],
['(?i:(?a:x))'])

def test_subset_lex(self):
p = Lark("""
start: "a" "b" "c" "d"
Expand Down
8 changes: 8 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,14 @@ def test_token_flags_verbose_multiline(self):
x = g.parse('abcdef')
self.assertEqual(x.children, ['abcdef'])

def test_token_flags_ascii(self):
# Test the ASCII flag (a) - makes \w, \d, \s ASCII-only
l = _Lark(r"""!start: /\d/a+
""")
# Should match ASCII digits
tree = l.parse('123')
self.assertEqual(tree.children, ['1', '2', '3'])

@unittest.skipIf(PARSER == 'cyk', "No empty rules")
def test_twice_empty(self):
g = """!start: ("A"?)?
Expand Down