aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/alecthomas/chroma/regexp.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/alecthomas/chroma/regexp.go')
-rw-r--r--vendor/github.com/alecthomas/chroma/regexp.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/vendor/github.com/alecthomas/chroma/regexp.go b/vendor/github.com/alecthomas/chroma/regexp.go
index d13d58d69f..a3f4eb139f 100644
--- a/vendor/github.com/alecthomas/chroma/regexp.go
+++ b/vendor/github.com/alecthomas/chroma/regexp.go
@@ -6,6 +6,7 @@ import (
"regexp"
"strings"
"sync"
+ "time"
"unicode/utf8"
"github.com/dlclark/regexp2"
@@ -160,6 +161,14 @@ func Tokenise(lexer Lexer, options *TokeniseOptions, text string) ([]Token, erro
// Rules maps from state to a sequence of Rules.
type Rules map[string][]Rule
+// Rename clones rules then a rule.
+func (r Rules) Rename(old, new string) Rules {
+ r = r.Clone()
+ r[new] = r[old]
+ delete(r, old)
+ return r
+}
+
// Clone returns a clone of the Rules.
func (r Rules) Clone() Rules {
out := map[string][]Rule{}
@@ -170,6 +179,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)
@@ -376,6 +394,7 @@ func (r *RegexLexer) maybeCompile() (err error) {
if err != nil {
return fmt.Errorf("failed to compile rule %s.%d: %s", state, i, err)
}
+ rule.Regexp.MatchTimeout = time.Millisecond * 250
}
}
}