File: ebnf.go

package info (click to toggle)
golang-github-alecthomas-chroma 0.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,652 kB
  • sloc: python: 426; javascript: 79; makefile: 34; sh: 32
file content (55 lines) | stat: -rw-r--r-- 1,210 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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},
		},
	}
}