1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-17 20:58:08 +02:00

Fix lua lexer, and actually check error value from compiling regexes :(

This commit is contained in:
Alec Thomas 2017-09-19 12:05:36 +10:00
parent 00d5486e6b
commit 631fc87d6e
2 changed files with 5 additions and 3 deletions

View File

@ -293,7 +293,9 @@ func (r *RegexLexer) maybeCompile() (err error) {
}
func (r *RegexLexer) Tokenise(options *TokeniseOptions, text string, out func(*Token)) error {
r.maybeCompile()
if err := r.maybeCompile(); err != nil {
return err
}
if options == nil {
options = defaultOptions
}

View File

@ -18,7 +18,7 @@ var Lua = Register(MustNewLexer(
Default(Push("base")),
},
"ws": {
{`(?:--\[(?P<level>=*)\[[\w\W]*?\](?P=level)\])`, CommentMultiline, nil},
{`(?:--\[(=*)\[[\w\W]*?\](\1)\])`, CommentMultiline, nil},
{`(?:--.*$)`, CommentSingle, nil},
{`(?:\s+)`, Text, nil},
},
@ -46,7 +46,7 @@ var Lua = Register(MustNewLexer(
"funcname": {
Include("ws"),
{`[.:]`, Punctuation, nil},
{`(?:[^\W\d]\w*)(?=(?:(?:--\[(?P<level>=*)\[[\w\W]*?\](?P=level)\])|(?:--.*$)|(?:\s+))*[.:])`, NameClass, nil},
{`(?:[^\W\d]\w*)(?=(?:(?:--\[(=*)\[[\w\W]*?\](\2)\])|(?:--.*$)|(?:\s+))*[.:])`, NameClass, nil},
{`(?:[^\W\d]\w*)`, NameFunction, Pop(1)},
{`\(`, Punctuation, Pop(1)},
},