Skip to content

Commit 73ef556

Browse files
committed
Lexer: use the first text found for a token in order to unparse it
1 parent cd16ac1 commit 73ef556

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

langkit/lexer/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,11 @@ def add_rules(self,
620620
# representation.
621621
self.literals_map[m.to_match] = a
622622

623-
a.matcher = m
623+
# Keep track of a canonical representation of this token, to be
624+
# used by default in unparsers. The first one found is the
625+
# canonical one.
626+
if a.matcher is None:
627+
a.matcher = m
624628

625629
def add_spacing(
626630
self,

testsuite/python_support/lexer_example.lkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ lexer foo_lexer {
2424
r_par <- ")"
2525
l_brace <- "{"
2626
r_brace <- "}"
27-
equal <- "="
27+
equal <- or("=" | ":=")
2828
plus <- "+"
2929
}
3030

0 commit comments

Comments
 (0)