actionscript3.go

 1package a
 2
 3import (
 4	. "github.com/alecthomas/chroma" // nolint
 5	"github.com/alecthomas/chroma/lexers/internal"
 6)
 7
 8// Actionscript 3 lexer.
 9var Actionscript3 = internal.Register(MustNewLexer(
10	&Config{
11		Name:      "ActionScript 3",
12		Aliases:   []string{"as3", "actionscript3"},
13		Filenames: []string{"*.as"},
14		MimeTypes: []string{"application/x-actionscript3", "text/x-actionscript3", "text/actionscript3"},
15		DotAll:    true,
16	},
17	Rules{
18		"root": {
19			{`\s+`, Text, nil},
20			{`(function\s+)([$a-zA-Z_]\w*)(\s*)(\()`, ByGroups(KeywordDeclaration, NameFunction, Text, Operator), Push("funcparams")},
21			{`(var|const)(\s+)([$a-zA-Z_]\w*)(\s*)(:)(\s*)([$a-zA-Z_]\w*(?:\.<\w+>)?)`, ByGroups(KeywordDeclaration, Text, Name, Text, Punctuation, Text, KeywordType), nil},
22			{`(import|package)(\s+)((?:[$a-zA-Z_]\w*|\.)+)(\s*)`, ByGroups(Keyword, Text, NameNamespace, Text), nil},
23			{`(new)(\s+)([$a-zA-Z_]\w*(?:\.<\w+>)?)(\s*)(\()`, ByGroups(Keyword, Text, KeywordType, Text, Operator), nil},
24			{`//.*?\n`, CommentSingle, nil},
25			{`/\*.*?\*/`, CommentMultiline, nil},
26			{`/(\\\\|\\/|[^\n])*/[gisx]*`, LiteralStringRegex, nil},
27			{`(\.)([$a-zA-Z_]\w*)`, ByGroups(Operator, NameAttribute), nil},
28			{`(case|default|for|each|in|while|do|break|return|continue|if|else|throw|try|catch|with|new|typeof|arguments|instanceof|this|switch|import|include|as|is)\b`, Keyword, nil},
29			{`(class|public|final|internal|native|override|private|protected|static|import|extends|implements|interface|intrinsic|return|super|dynamic|function|const|get|namespace|package|set)\b`, KeywordDeclaration, nil},
30			{`(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b`, KeywordConstant, nil},
31			{`(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|unescape)\b`, NameFunction, nil},
32			{`[$a-zA-Z_]\w*`, Name, nil},
33			{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
34			{`0x[0-9a-f]+`, LiteralNumberHex, nil},
35			{`[0-9]+`, LiteralNumberInteger, nil},
36			{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
37			{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
38			{`[~^*!%&<>|+=:;,/?\\{}\[\]().-]+`, Operator, nil},
39		},
40		"funcparams": {
41			{`\s+`, Text, nil},
42			{`(\s*)(\.\.\.)?([$a-zA-Z_]\w*)(\s*)(:)(\s*)([$a-zA-Z_]\w*(?:\.<\w+>)?|\*)(\s*)`, ByGroups(Text, Punctuation, Name, Text, Operator, Text, KeywordType, Text), Push("defval")},
43			{`\)`, Operator, Push("type")},
44		},
45		"type": {
46			{`(\s*)(:)(\s*)([$a-zA-Z_]\w*(?:\.<\w+>)?|\*)`, ByGroups(Text, Operator, Text, KeywordType), Pop(2)},
47			{`\s+`, Text, Pop(2)},
48			Default(Pop(2)),
49		},
50		"defval": {
51			{`(=)(\s*)([^(),]+)(\s*)(,?)`, ByGroups(Operator, Text, UsingSelf("root"), Text, Operator), Pop(1)},
52			{`,`, Operator, Pop(1)},
53			Default(Pop(1)),
54		},
55	},
56))