diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-06-28 22:03:25 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-06-29 18:07:17 +0900 |
commit | 4858970db07ce6c9500fa7f082f1eab7b647352c (patch) | |
tree | f5e4c4bc04daa70170971282f57990e1184aafb5 | |
parent | Add ast action (diff) | |
download | urubu-4858970db07ce6c9500fa7f082f1eab7b647352c.tar.gz urubu-4858970db07ce6c9500fa7f082f1eab7b647352c.tar.xz |
Prioritize anonymous patterns over named patterns
-rw-r--r-- | grammar/grammar.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/grammar/grammar.go b/grammar/grammar.go index 05ba836..d0ae2f4 100644 --- a/grammar/grammar.go +++ b/grammar/grammar.go @@ -113,6 +113,7 @@ func NewGrammar(root *spec.RootNode) (*Grammar, error) { } } + var anonEntries []*mlspec.LexEntry for i, p := range anonPats { kind := fmt.Sprintf("__%v__", i+1) @@ -122,11 +123,13 @@ func NewGrammar(root *spec.RootNode) (*Grammar, error) { } anonPat2Sym[p] = sym - entries = append(entries, &mlspec.LexEntry{ + anonEntries = append(anonEntries, &mlspec.LexEntry{ Kind: mlspec.LexKind(kind), Pattern: mlspec.LexPattern(p), }) } + // Anonymous patterns take precedence over explicitly defined lexical specifications. + entries = append(anonEntries, entries...) for _, fragment := range root.Fragments { entries = append(entries, &mlspec.LexEntry{ |