aboutsummaryrefslogtreecommitdiff
path: root/compiler/compiler.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-09-22 23:36:19 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-09-22 23:36:19 +0900
commitcf4f53332e9d99a3a9eccfe69e70f98769862c3a (patch)
tree5963589f931d899f2855b5b25919e8368c3575d5 /compiler/compiler.go
parentAdd name field to the lexical specification (diff)
downloadtre-cf4f53332e9d99a3a9eccfe69e70f98769862c3a.tar.gz
tre-cf4f53332e9d99a3a9eccfe69e70f98769862c3a.tar.xz
Keep the order of AST nodes constant
Diffstat (limited to '')
-rw-r--r--compiler/compiler.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/compiler.go b/compiler/compiler.go
index 0c89737..3469044 100644
--- a/compiler/compiler.go
+++ b/compiler/compiler.go
@@ -201,8 +201,19 @@ func compile(entries []*spec.LexEntry, modeName2ID map[spec.LexModeName]spec.Lex
var root astNode
var symTab *symbolTable
{
+ pats := make([]*patternEntry, len(patterns)+1)
+ pats[spec.LexModeKindIDNil] = &patternEntry{
+ id: spec.LexModeKindIDNil,
+ }
+ for id, pattern := range patterns {
+ pats[id] = &patternEntry{
+ id: id,
+ pattern: pattern,
+ }
+ }
+
var err error
- root, symTab, err = parse(patterns, fragmentPatterns)
+ root, symTab, err = parse(pats, fragmentPatterns)
if err != nil {
return nil, err
}