...

Source file src/github.com/alecthomas/chroma/lexers/a/actionscript3.go

Documentation: github.com/alecthomas/chroma/lexers/a

     1  package a
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Actionscript 3 lexer.
     9  var Actionscript3 = internal.Register(MustNewLazyLexer(
    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  	actionscript3Rules,
    18  ))
    19  
    20  func actionscript3Rules() Rules {
    21  	return Rules{
    22  		"root": {
    23  			{`\s+`, Text, nil},
    24  			{`(function\s+)([$a-zA-Z_]\w*)(\s*)(\()`, ByGroups(KeywordDeclaration, NameFunction, Text, Operator), Push("funcparams")},
    25  			{`(var|const)(\s+)([$a-zA-Z_]\w*)(\s*)(:)(\s*)([$a-zA-Z_]\w*(?:\.<\w+>)?)`, ByGroups(KeywordDeclaration, Text, Name, Text, Punctuation, Text, KeywordType), nil},
    26  			{`(import|package)(\s+)((?:[$a-zA-Z_]\w*|\.)+)(\s*)`, ByGroups(Keyword, Text, NameNamespace, Text), nil},
    27  			{`(new)(\s+)([$a-zA-Z_]\w*(?:\.<\w+>)?)(\s*)(\()`, ByGroups(Keyword, Text, KeywordType, Text, Operator), nil},
    28  			{`//.*?\n`, CommentSingle, nil},
    29  			{`/\*.*?\*/`, CommentMultiline, nil},
    30  			{`/(\\\\|\\/|[^\n])*/[gisx]*`, LiteralStringRegex, nil},
    31  			{`(\.)([$a-zA-Z_]\w*)`, ByGroups(Operator, NameAttribute), nil},
    32  			{`(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},
    33  			{`(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},
    34  			{`(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b`, KeywordConstant, nil},
    35  			{`(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|unescape)\b`, NameFunction, nil},
    36  			{`[$a-zA-Z_]\w*`, Name, nil},
    37  			{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
    38  			{`0x[0-9a-f]+`, LiteralNumberHex, nil},
    39  			{`[0-9]+`, LiteralNumberInteger, nil},
    40  			{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
    41  			{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
    42  			{`[~^*!%&<>|+=:;,/?\\{}\[\]().-]+`, Operator, nil},
    43  		},
    44  		"funcparams": {
    45  			{`\s+`, Text, nil},
    46  			{`(\s*)(\.\.\.)?([$a-zA-Z_]\w*)(\s*)(:)(\s*)([$a-zA-Z_]\w*(?:\.<\w+>)?|\*)(\s*)`, ByGroups(Text, Punctuation, Name, Text, Operator, Text, KeywordType, Text), Push("defval")},
    47  			{`\)`, Operator, Push("type")},
    48  		},
    49  		"type": {
    50  			{`(\s*)(:)(\s*)([$a-zA-Z_]\w*(?:\.<\w+>)?|\*)`, ByGroups(Text, Operator, Text, KeywordType), Pop(2)},
    51  			{`\s+`, Text, Pop(2)},
    52  			Default(Pop(2)),
    53  		},
    54  		"defval": {
    55  			{`(=)(\s*)([^(),]+)(\s*)(,?)`, ByGroups(Operator, Text, UsingSelf("root"), Text, Operator), Pop(1)},
    56  			{`,`, Operator, Pop(1)},
    57  			Default(Pop(1)),
    58  		},
    59  	}
    60  }
    61  

View as plain text