1package a
2
3import (
4	. "github.com/alecthomas/chroma" // nolint
5	"github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Angular2 lexer.
9var Angular2 = internal.Register(MustNewLazyLexer(
10	&Config{
11		Name:      "Angular2",
12		Aliases:   []string{"ng2"},
13		Filenames: []string{},
14		MimeTypes: []string{},
15	},
16	angular2Rules,
17))
18
19func angular2Rules() Rules {
20	return Rules{
21		"root": {
22			{`[^{([*#]+`, Other, nil},
23			{`(\{\{)(\s*)`, ByGroups(CommentPreproc, Text), Push("ngExpression")},
24			{`([([]+)([\w:.-]+)([\])]+)(\s*)(=)(\s*)`, ByGroups(Punctuation, NameAttribute, Punctuation, Text, Operator, Text), Push("attr")},
25			{`([([]+)([\w:.-]+)([\])]+)(\s*)`, ByGroups(Punctuation, NameAttribute, Punctuation, Text), nil},
26			{`([*#])([\w:.-]+)(\s*)(=)(\s*)`, ByGroups(Punctuation, NameAttribute, Punctuation, Operator), Push("attr")},
27			{`([*#])([\w:.-]+)(\s*)`, ByGroups(Punctuation, NameAttribute, Punctuation), nil},
28		},
29		"ngExpression": {
30			{`\s+(\|\s+)?`, Text, nil},
31			{`\}\}`, CommentPreproc, Pop(1)},
32			{`:?(true|false)`, LiteralStringBoolean, nil},
33			{`:?"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
34			{`:?'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
35			{`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil},
36			{`[a-zA-Z][\w-]*(\(.*\))?`, NameVariable, nil},
37			{`\.[\w-]+(\(.*\))?`, NameVariable, nil},
38			{`(\?)(\s*)([^}\s]+)(\s*)(:)(\s*)([^}\s]+)(\s*)`, ByGroups(Operator, Text, LiteralString, Text, Operator, Text, LiteralString, Text), nil},
39		},
40		"attr": {
41			{`".*?"`, LiteralString, Pop(1)},
42			{`'.*?'`, LiteralString, Pop(1)},
43			{`[^\s>]+`, LiteralString, Pop(1)},
44		},
45	}
46}
47