2019-10-27 17:04:31 +01:00
|
|
|
package e
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Ebnf lexer.
|
2021-04-28 18:35:32 +02:00
|
|
|
var Ebnf = internal.Register(MustNewLazyLexer(
|
2019-10-27 17:04:31 +01:00
|
|
|
&Config{
|
|
|
|
Name: "EBNF",
|
|
|
|
Aliases: []string{"ebnf"},
|
|
|
|
Filenames: []string{"*.ebnf"},
|
|
|
|
MimeTypes: []string{"text/x-ebnf"},
|
|
|
|
},
|
2021-04-28 18:35:32 +02:00
|
|
|
ebnfRules,
|
|
|
|
))
|
|
|
|
|
|
|
|
func ebnfRules() Rules {
|
|
|
|
return Rules{
|
2019-10-27 17:04:31 +01:00
|
|
|
"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},
|
|
|
|
},
|
2021-04-28 18:35:32 +02:00
|
|
|
}
|
|
|
|
}
|