Skip to content

Commit

Permalink
Add a Rules.Merge() helper function.
Browse files Browse the repository at this point in the history
Might be useful for alecthomas#363.
  • Loading branch information
alecthomas committed May 16, 2020
1 parent f050b16 commit e4597ae
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions regexp.go
Expand Up @@ -170,6 +170,15 @@ func (r Rules) Clone() Rules {
return out
}

// Merge creates a clone of "r" then merges "rules" into the clone.
func (r Rules) Merge(rules Rules) Rules {
out := r.Clone()
for k, v := range rules.Clone() {
out[k] = v
}
return out
}

// MustNewLexer creates a new Lexer or panics.
func MustNewLexer(config *Config, rules Rules) *RegexLexer {
lexer, err := NewLexer(config, rules)
Expand Down

0 comments on commit e4597ae

Please sign in to comment.