Skip to content

Commit

Permalink
fixed 2.7 unicode issue in lark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrob95 committed Nov 10, 2019
1 parent 6841bc6 commit eba046b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dragonfly/parsing/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
?alternative: sequence ("|" sequence)*
?sequence: single*

?single: WORD -> literal
?single: WORD+ -> literal
| "<" WORD ">" -> reference
| "[" alternative "]" -> optional
| "(" alternative ")"
Expand Down
26 changes: 13 additions & 13 deletions dragonfly/test/test_lark_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# ===========================================================================

extras = {"an_extra": Alternative([Literal("1"), Literal("2")])}
extras = {"an_extra": Alternative([Literal(u"1"), Literal(u"2")])}


def check_parse_tree(spec, expected):
Expand All @@ -19,29 +19,29 @@ def check_parse_tree(spec, expected):

class TestLarkParser(unittest.TestCase):
def test_literal(self):
check_parse_tree("test ", Literal("test"))
check_parse_tree("test ", Literal(u"test"))

def test_parens(self):
check_parse_tree("(test ) ", Literal("test"))
check_parse_tree("(test ) ", Literal(u"test"))

def test_punctuation(self):
check_parse_tree(",", Literal(","))
check_parse_tree("test's ", Literal("test's"))
check_parse_tree("cul-de-sac ", Literal("cul-de-sac"))
check_parse_tree(",", Literal(u","))
check_parse_tree("test's ", Literal(u"test's"))
check_parse_tree("cul-de-sac ", Literal(u"cul-de-sac"))

def test_sequence(self):
check_parse_tree(
" test <an_extra> [op]",
Sequence([Literal("test"), extras["an_extra"], Optional(Literal("op"))]),
Sequence([Literal(u"test"), extras["an_extra"], Optional(Literal(u"op"))]),
)

def test_alternative_no_parens(self):
check_parse_tree(
" test |[op] <an_extra>",
Alternative(
[
Literal("test"),
Sequence([Optional(Literal("op")), extras["an_extra"]]),
Literal(u"test"),
Sequence([Optional(Literal(u"op")), extras["an_extra"]]),
]
),
)
Expand All @@ -51,17 +51,17 @@ def test_alternative_parens(self):
"( test |[op] <an_extra>)",
Alternative(
[
Literal("test"),
Sequence([Optional(Literal("op")), extras["an_extra"]]),
Literal(u"test"),
Sequence([Optional(Literal(u"op")), extras["an_extra"]]),
]
),
)

def test_optional_alternative(self):
check_parse_tree("[test|test's]", Optional(Alternative([Literal("test"), Literal("test's")])))
check_parse_tree("[test|test's]", Optional(Alternative([Literal(u"test"), Literal(u"test's")])))

def test_digit_in_word(self):
check_parse_tree("F2", Literal("F2"))
check_parse_tree("F2", Literal(u"F2"))

def test_unicode(self):
check_parse_tree(u"touché", Literal(u"touché"))
Expand Down

0 comments on commit eba046b

Please sign in to comment.