File: armasm.go

package info (click to toggle)
golang-github-alecthomas-chroma 0.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,652 kB
  • sloc: python: 426; javascript: 79; makefile: 34; sh: 32
file content (72 lines) | stat: -rw-r--r-- 1,889 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package a

import (
	. "github.com/alecthomas/chroma" // nolint
	"github.com/alecthomas/chroma/lexers/internal"
)

var ArmAsm = internal.Register(MustNewLazyLexer(
	&Config{
		Name:      "ArmAsm",
		Aliases:   []string{"armasm"},
		EnsureNL:  true,
		Filenames: []string{"*.s", "*.S"},
		MimeTypes: []string{"text/x-armasm", "text/x-asm"},
	},
	armasmRules,
))

func armasmRules() Rules {
	return Rules{
		"commentsandwhitespace": {
			{`\s+`, Text, nil},
			{`[@;].*?\n`, CommentSingle, nil},
			{`/\*.*?\*/`, CommentMultiline, nil},
		},
		"literal": {
			// Binary
			{`0b[01]+`, NumberBin, Pop(1)},
			// Hex
			{`0x\w{1,8}`, NumberHex, Pop(1)},
			// Octal
			{`0\d+`, NumberOct, Pop(1)},
			// Float
			{`\d+?\.\d+?`, NumberFloat, Pop(1)},
			// Integer
			{`\d+`, NumberInteger, Pop(1)},
			// String
			{`(")(.+)(")`, ByGroups(Punctuation, StringDouble, Punctuation), Pop(1)},
			// Char
			{`(')(.{1}|\\.{1})(')`, ByGroups(Punctuation, StringChar, Punctuation), Pop(1)},
		},
		"opcode": {
			// Escape at line end
			{`\n`, Text, Pop(1)},
			// Comment
			{`(@|;).*\n`, CommentSingle, Pop(1)},
			// Whitespace
			{`(\s+|,)`, Text, nil},
			// Register by number
			{`[rapcfxwbhsdqv]\d{1,2}`, NameClass, nil},
			// Address by hex
			{`=0x\w+`, ByGroups(Text, NameLabel), nil},
			// Pseudo address by label
			{`(=)(\w+)`, ByGroups(Text, NameLabel), nil},
			// Immediate
			{`#`, Text, Push("literal")},
		},
		"root": {
			Include("commentsandwhitespace"),
			// Directive with optional param
			{`(\.\w+)([ \t]+\w+\s+?)?`, ByGroups(KeywordNamespace, NameLabel), nil},
			// Label with data
			{`(\w+)(:)(\s+\.\w+\s+)`, ByGroups(NameLabel, Punctuation, KeywordNamespace), Push("literal")},
			// Label
			{`(\w+)(:)`, ByGroups(NameLabel, Punctuation), nil},
			// Syscall Op
			{`svc\s+\w+`, NameNamespace, nil},
			// Opcode
			{`[a-zA-Z]+`, Text, Push("opcode")},
		},
	}
}