...

Source file src/github.com/alecthomas/chroma/lexers/n/nasm.go

Documentation: github.com/alecthomas/chroma/lexers/n

     1  package n
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Nasm lexer.
     9  var Nasm = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:            "NASM",
    12  		Aliases:         []string{"nasm"},
    13  		Filenames:       []string{"*.asm", "*.ASM"},
    14  		MimeTypes:       []string{"text/x-nasm"},
    15  		CaseInsensitive: true,
    16  	},
    17  	nasmRules,
    18  ))
    19  
    20  func nasmRules() Rules {
    21  	return Rules{
    22  		"root": {
    23  			{`^\s*%`, CommentPreproc, Push("preproc")},
    24  			Include("whitespace"),
    25  			{`[a-z$._?][\w$.?#@~]*:`, NameLabel, nil},
    26  			{`([a-z$._?][\w$.?#@~]*)(\s+)(equ)`, ByGroups(NameConstant, KeywordDeclaration, KeywordDeclaration), Push("instruction-args")},
    27  			{`BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|ORG|ALIGN|STRUC|ENDSTRUC|COMMON|CPU|GROUP|UPPERCASE|IMPORT|EXPORT|LIBRARY|MODULE`, Keyword, 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  			{`[\r\n]+`, Text, Pop(1)},
    43  			Include("whitespace"),
    44  		},
    45  		"preproc": {
    46  			{`[^;\n]+`, CommentPreproc, nil},
    47  			{`;.*?\n`, CommentSingle, Pop(1)},
    48  			{`\n`, CommentPreproc, Pop(1)},
    49  		},
    50  		"whitespace": {
    51  			{`\n`, Text, nil},
    52  			{`[ \t]+`, Text, nil},
    53  			{`;.*`, CommentSingle, nil},
    54  		},
    55  		"punctuation": {
    56  			{`[,():\[\]]+`, Punctuation, nil},
    57  			{`[&|^<>+*/%~-]+`, Operator, nil},
    58  			{`[$]+`, KeywordConstant, nil},
    59  			{`seg|wrt|strict`, OperatorWord, nil},
    60  			{`byte|[dq]?word`, KeywordType, nil},
    61  		},
    62  	}
    63  }
    64  

View as plain text