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