aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/alecthomas/chroma/regexp.go
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2020-07-27 13:18:02 -0400
committerGitHub <noreply@github.com>2020-07-27 13:18:02 -0400
commitbfb25e4be17ba33f17156aeb7c326d80e46855ac (patch)
tree61cefe228b5dfb908748923a8784953f407734a6 /vendor/github.com/alecthomas/chroma/regexp.go
parent4315e313d12bbf0655710b6ab0aad121e0f7dba2 (diff)
downloadgitea-bfb25e4be17ba33f17156aeb7c326d80e46855ac.tar.gz
gitea-bfb25e4be17ba33f17156aeb7c326d80e46855ac.zip
update chroma to v0.8.0 (#12337)
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
}
}
}