...

Source file src/github.com/alecthomas/chroma/lexers/a/armasm.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  var ArmAsm = internal.Register(MustNewLazyLexer(
     9  	&Config{
    10  		Name:      "ArmAsm",
    11  		Aliases:   []string{"armasm"},
    12  		EnsureNL:  true,
    13  		Filenames: []string{"*.s", "*.S"},
    14  		MimeTypes: []string{"text/x-armasm", "text/x-asm"},
    15  	},
    16  	armasmRules,
    17  ))
    18  
    19  func armasmRules() Rules {
    20  	return Rules{
    21  		"commentsandwhitespace": {
    22  			{`\s+`, Text, nil},
    23  			{`[@;].*?\n`, CommentSingle, nil},
    24  			{`/\*.*?\*/`, CommentMultiline, nil},
    25  		},
    26  		"literal": {
    27  			// Binary
    28  			{`0b[01]+`, NumberBin, Pop(1)},
    29  			// Hex
    30  			{`0x\w{1,8}`, NumberHex, Pop(1)},
    31  			// Octal
    32  			{`0\d+`, NumberOct, Pop(1)},
    33  			// Float
    34  			{`\d+?\.\d+?`, NumberFloat, Pop(1)},
    35  			// Integer
    36  			{`\d+`, NumberInteger, Pop(1)},
    37  			// String
    38  			{`(")(.+)(")`, ByGroups(Punctuation, StringDouble, Punctuation), Pop(1)},
    39  			// Char
    40  			{`(')(.{1}|\\.{1})(')`, ByGroups(Punctuation, StringChar, Punctuation), Pop(1)},
    41  		},
    42  		"opcode": {
    43  			// Escape at line end
    44  			{`\n`, Text, Pop(1)},
    45  			// Comment
    46  			{`(@|;).*\n`, CommentSingle, Pop(1)},
    47  			// Whitespace
    48  			{`(\s+|,)`, Text, nil},
    49  			// Register by number
    50  			{`[rapcfxwbhsdqv]\d{1,2}`, NameClass, nil},
    51  			// Address by hex
    52  			{`=0x\w+`, ByGroups(Text, NameLabel), nil},
    53  			// Pseudo address by label
    54  			{`(=)(\w+)`, ByGroups(Text, NameLabel), nil},
    55  			// Immediate
    56  			{`#`, Text, Push("literal")},
    57  		},
    58  		"root": {
    59  			Include("commentsandwhitespace"),
    60  			// Directive with optional param
    61  			{`(\.\w+)([ \t]+\w+\s+?)?`, ByGroups(KeywordNamespace, NameLabel), nil},
    62  			// Label with data
    63  			{`(\w+)(:)(\s+\.\w+\s+)`, ByGroups(NameLabel, Punctuation, KeywordNamespace), Push("literal")},
    64  			// Label
    65  			{`(\w+)(:)`, ByGroups(NameLabel, Punctuation), nil},
    66  			// Syscall Op
    67  			{`svc\s+\w+`, NameNamespace, nil},
    68  			// Opcode
    69  			{`[a-zA-Z]+`, Text, Push("opcode")},
    70  		},
    71  	}
    72  }
    73  

View as plain text