gas.go

 1package g
 2
 3import (
 4	. "github.com/alecthomas/chroma" // nolint
 5	"github.com/alecthomas/chroma/lexers/internal"
 6)
 7
 8// Gas lexer.
 9var Gas = internal.Register(MustNewLexer(
10	&Config{
11		Name:      "GAS",
12		Aliases:   []string{"gas", "asm"},
13		Filenames: []string{"*.s", "*.S"},
14		MimeTypes: []string{"text/x-gas"},
15	},
16	Rules{
17		"root": {
18			Include("whitespace"),
19			{`(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+):`, NameLabel, nil},
20			{`\.(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameAttribute, Push("directive-args")},
21			{`lock|rep(n?z)?|data\d+`, NameAttribute, nil},
22			{`(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameFunction, Push("instruction-args")},
23			{`[\r\n]+`, Text, nil},
24		},
25		"directive-args": {
26			{`(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameConstant, nil},
27			{`"(\\"|[^"])*"`, LiteralString, nil},
28			{`@(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameAttribute, nil},
29			{`(?:0[xX][a-zA-Z0-9]+|\d+)`, LiteralNumberInteger, nil},
30			{`[\r\n]+`, Text, Pop(1)},
31			Include("punctuation"),
32			Include("whitespace"),
33		},
34		"instruction-args": {
35			{`([a-z0-9]+)( )(<)((?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+))(>)`, ByGroups(LiteralNumberHex, Text, Punctuation, NameConstant, Punctuation), nil},
36			{`([a-z0-9]+)( )(<)((?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+))([-+])((?:0[xX][a-zA-Z0-9]+|\d+))(>)`, ByGroups(LiteralNumberHex, Text, Punctuation, NameConstant, Punctuation, LiteralNumberInteger, Punctuation), nil},
37			{`(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameConstant, nil},
38			{`(?:0[xX][a-zA-Z0-9]+|\d+)`, LiteralNumberInteger, nil},
39			{`%(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameVariable, nil},
40			{`$(?:0[xX][a-zA-Z0-9]+|\d+)`, LiteralNumberInteger, nil},
41			{`$'(.|\\')'`, LiteralStringChar, nil},
42			{`[\r\n]+`, Text, Pop(1)},
43			Include("punctuation"),
44			Include("whitespace"),
45		},
46		"whitespace": {
47			{`\n`, Text, nil},
48			{`\s+`, Text, nil},
49			{`[;#].*?\n`, Comment, nil},
50		},
51		"punctuation": {
52			{`[-*,.()\[\]!:]+`, Punctuation, nil},
53		},
54	},
55))