1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-11-25 22:32:32 +02:00

Convert Include to a LexerMutator.

Fixes #18.
This commit is contained in:
Alec Thomas
2017-09-22 22:28:51 +10:00
parent f8658edb57
commit 0bb853fb4f
3 changed files with 46 additions and 40 deletions

View File

@@ -269,10 +269,17 @@ func (r *RegexLexer) maybeCompile() (err error) {
return fmt.Errorf("failed to compile rule %s.%d: %s", state, i, err)
}
}
}
}
for state := range r.rules {
for i := 0; i < len(r.rules[state]); i++ {
rule := r.rules[state][i]
if compile, ok := rule.Mutator.(LexerMutator); ok {
if err := compile.MutateLexer(r, rule); err != nil {
if err := compile.MutateLexer(r.rules, state, i); err != nil {
return err
}
// Process the rules again in case the mutator added/removed rules.
i = -1
}
}
}