mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-23 02:51:37 +01:00
d6df0a53b5
Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/390 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package e
|
|
|
|
import (
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
)
|
|
|
|
// Ebnf lexer.
|
|
var Ebnf = internal.Register(MustNewLazyLexer(
|
|
&Config{
|
|
Name: "EBNF",
|
|
Aliases: []string{"ebnf"},
|
|
Filenames: []string{"*.ebnf"},
|
|
MimeTypes: []string{"text/x-ebnf"},
|
|
},
|
|
ebnfRules,
|
|
))
|
|
|
|
func ebnfRules() Rules {
|
|
return Rules{
|
|
"root": {
|
|
Include("whitespace"),
|
|
Include("comment_start"),
|
|
Include("identifier"),
|
|
{`=`, Operator, Push("production")},
|
|
},
|
|
"production": {
|
|
Include("whitespace"),
|
|
Include("comment_start"),
|
|
Include("identifier"),
|
|
{`"[^"]*"`, LiteralStringDouble, nil},
|
|
{`'[^']*'`, LiteralStringSingle, nil},
|
|
{`(\?[^?]*\?)`, NameEntity, nil},
|
|
{`[\[\]{}(),|]`, Punctuation, nil},
|
|
{`-`, Operator, nil},
|
|
{`;`, Punctuation, Pop(1)},
|
|
{`\.`, Punctuation, Pop(1)},
|
|
},
|
|
"whitespace": {
|
|
{`\s+`, Text, nil},
|
|
},
|
|
"comment_start": {
|
|
{`\(\*`, CommentMultiline, Push("comment")},
|
|
},
|
|
"comment": {
|
|
{`[^*)]`, CommentMultiline, nil},
|
|
Include("comment_start"),
|
|
{`\*\)`, CommentMultiline, Pop(1)},
|
|
{`[*)]`, CommentMultiline, nil},
|
|
},
|
|
"identifier": {
|
|
{`([a-zA-Z][\w \-]*)`, Keyword, nil},
|
|
},
|
|
}
|
|
}
|