1 package t
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Tasm = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "TASM",
12 Aliases: []string{"tasm"},
13 Filenames: []string{"*.asm", "*.ASM", "*.tasm"},
14 MimeTypes: []string{"text/x-tasm"},
15 CaseInsensitive: true,
16 },
17 tasmRules,
18 ))
19
20 func tasmRules() Rules {
21 return Rules{
22 "root": {
23 {`^\s*%`, CommentPreproc, Push("preproc")},
24 Include("whitespace"),
25 {`[@a-z$._?][\w$.?#@~]*:`, NameLabel, nil},
26 {`BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|ORG|ALIGN|STRUC|ENDSTRUC|ENDS|COMMON|CPU|GROUP|UPPERCASE|INCLUDE|EXPORT|LIBRARY|MODULE|PROC|ENDP|USES|ARG|DATASEG|UDATASEG|END|IDEAL|P386|MODEL|ASSUME|CODESEG|SIZE`, Keyword, Push("instruction-args")},
27 {`([@a-z$._?][\w$.?#@~]*)(\s+)(db|dd|dw|T[A-Z][a-z]+)`, ByGroups(NameConstant, KeywordDeclaration, KeywordDeclaration), Push("instruction-args")},
28 {`(?:res|d)[bwdqt]|times`, KeywordDeclaration, Push("instruction-args")},
29 {`[@a-z$._?][\w$.?#@~]*`, NameFunction, Push("instruction-args")},
30 {`[\r\n]+`, Text, nil},
31 },
32 "instruction-args": {
33 {"\"(\\\\\"|[^\"\\n])*\"|'(\\\\'|[^'\\n])*'|`(\\\\`|[^`\\n])*`", LiteralString, nil},
34 {`(?:0x[0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)`, LiteralNumberHex, nil},
35 {`[0-7]+q`, LiteralNumberOct, nil},
36 {`[01]+b`, LiteralNumberBin, nil},
37 {`[0-9]+\.e?[0-9]+`, LiteralNumberFloat, nil},
38 {`[0-9]+`, LiteralNumberInteger, nil},
39 Include("punctuation"),
40 {`r[0-9][0-5]?[bwd]|[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]`, NameBuiltin, nil},
41 {`[@a-z$._?][\w$.?#@~]*`, NameVariable, nil},
42 {`(\\\s*)(;.*)([\r\n])`, ByGroups(Text, CommentSingle, Text), nil},
43 {`[\r\n]+`, Text, Pop(1)},
44 Include("whitespace"),
45 },
46 "preproc": {
47 {`[^;\n]+`, CommentPreproc, nil},
48 {`;.*?\n`, CommentSingle, Pop(1)},
49 {`\n`, CommentPreproc, Pop(1)},
50 },
51 "whitespace": {
52 {`[\n\r]`, Text, nil},
53 {`\\[\n\r]`, Text, nil},
54 {`[ \t]+`, Text, nil},
55 {`;.*`, CommentSingle, nil},
56 },
57 "punctuation": {
58 {`[,():\[\]]+`, Punctuation, nil},
59 {`[&|^<>+*=/%~-]+`, Operator, nil},
60 {`[$]+`, KeywordConstant, nil},
61 {`seg|wrt|strict`, OperatorWord, nil},
62 {`byte|[dq]?word`, KeywordType, nil},
63 },
64 }
65 }
66
View as plain text