Skip to content

Commit

Permalink
Fix lua lexer, and actually check error value from compiling regexes :(
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Sep 19, 2017
1 parent 00d5486 commit 631fc87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lexer.go
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions lexers/lua.go
Expand Up @@ -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},
},
Expand Down Expand Up @@ -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)},
},
Expand Down

0 comments on commit 631fc87

Please sign in to comment.