package n

import "github.com/alecthomas/chroma/lexers/n"

Index

Variables

var Nasm = internal.Register(MustNewLexer(
	&Config{
		Name:            "NASM",
		Aliases:         []string{"nasm"},
		Filenames:       []string{"*.asm", "*.ASM"},
		MimeTypes:       []string{"text/x-nasm"},
		CaseInsensitive: true,
	},
	Rules{
		"root": {
			{`^\s*%`, CommentPreproc, Push("preproc")},
			Include("whitespace"),
			{`[a-z$._?][\w$.?#@~]*:`, NameLabel, nil},
			{`([a-z$._?][\w$.?#@~]*)(\s+)(equ)`, ByGroups(NameConstant, KeywordDeclaration, KeywordDeclaration), Push("instruction-args")},
			{"" /* 138 byte string literal not displayed */, Keyword, Push("instruction-args")},
			{`(?:res|d)[bwdqt]|times`, KeywordDeclaration, Push("instruction-args")},
			{`[a-z$._?][\w$.?#@~]*`, NameFunction, Push("instruction-args")},
			{`[\r\n]+`, Text, nil},
		},
		"instruction-args": {
			{"\"(\\\\\"|[^\"\\n])*\"|'(\\\\'|[^'\\n])*'|`(\\\\`|[^`\\n])*`", LiteralString, nil},
			{`(?:0x[0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)`, LiteralNumberHex, nil},
			{`[0-7]+q`, LiteralNumberOct, nil},
			{`[01]+b`, LiteralNumberBin, nil},
			{`[0-9]+\.e?[0-9]+`, LiteralNumberFloat, nil},
			{`[0-9]+`, LiteralNumberInteger, nil},
			Include("punctuation"),
			{`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},
			{`[a-z$._?][\w$.?#@~]*`, NameVariable, nil},
			{`[\r\n]+`, Text, Pop(1)},
			Include("whitespace"),
		},
		"preproc": {
			{`[^;\n]+`, CommentPreproc, nil},
			{`;.*?\n`, CommentSingle, Pop(1)},
			{`\n`, CommentPreproc, Pop(1)},
		},
		"whitespace": {
			{`\n`, Text, nil},
			{`[ \t]+`, Text, nil},
			{`;.*`, CommentSingle, nil},
		},
		"punctuation": {
			{`[,():\[\]]+`, Punctuation, nil},
			{`[&|^<>+*/%~-]+`, Operator, nil},
			{`[$]+`, KeywordConstant, nil},
			{`seg|wrt|strict`, OperatorWord, nil},
			{`byte|[dq]?word`, KeywordType, nil},
		},
	},
))

Nasm lexer.

var Newspeak = internal.Register(MustNewLexer(
	&Config{
		Name:      "Newspeak",
		Aliases:   []string{"newspeak"},
		Filenames: []string{"*.ns2"},
		MimeTypes: []string{"text/x-newspeak"},
	},
	Rules{
		"root": {
			{`\b(Newsqueak2)\b`, KeywordDeclaration, nil},
			{`'[^']*'`, LiteralString, nil},
			{`\b(class)(\s+)(\w+)(\s*)`, ByGroups(KeywordDeclaration, Text, NameClass, Text), nil},
			{`\b(mixin|self|super|private|public|protected|nil|true|false)\b`, Keyword, nil},
			{`(\w+\:)(\s*)([a-zA-Z_]\w+)`, ByGroups(NameFunction, Text, NameVariable), nil},
			{`(\w+)(\s*)(=)`, ByGroups(NameAttribute, Text, Operator), nil},
			{`<\w+>`, CommentSpecial, nil},
			Include("expressionstat"),
			Include("whitespace"),
		},
		"expressionstat": {
			{`(\d+\.\d*|\.\d+|\d+[fF])[fF]?`, LiteralNumberFloat, nil},
			{`\d+`, LiteralNumberInteger, nil},
			{`:\w+`, NameVariable, nil},
			{`(\w+)(::)`, ByGroups(NameVariable, Operator), nil},
			{`\w+:`, NameFunction, nil},
			{`\w+`, NameVariable, nil},
			{`\(|\)`, Punctuation, nil},
			{`\[|\]`, Punctuation, nil},
			{`\{|\}`, Punctuation, nil},
			{`(\^|\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-|:)`, Operator, nil},
			{`\.|;`, Punctuation, nil},
			Include("whitespace"),
			Include("literals"),
		},
		"literals": {
			{`\$.`, LiteralString, nil},
			{`'[^']*'`, LiteralString, nil},
			{`#'[^']*'`, LiteralStringSymbol, nil},
			{`#\w+:?`, LiteralStringSymbol, nil},
			{`#(\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-)+`, LiteralStringSymbol, nil},
		},
		"whitespace": {
			{`\s+`, Text, nil},
			{`"[^"]*"`, Comment, nil},
		},
	},
))

Newspeak lexer.

var Nginx = internal.Register(MustNewLexer(
	&Config{
		Name:      "Nginx configuration file",
		Aliases:   []string{"nginx"},
		Filenames: []string{"nginx.conf"},
		MimeTypes: []string{"text/x-nginx-conf"},
	},
	Rules{
		"root": {
			{`(include)(\s+)([^\s;]+)`, ByGroups(Keyword, Text, Name), nil},
			{`[^\s;#]+`, Keyword, Push("stmt")},
			Include("base"),
		},
		"block": {
			{`\}`, Punctuation, Pop(2)},
			{`[^\s;#]+`, KeywordNamespace, Push("stmt")},
			Include("base"),
		},
		"stmt": {
			{`\{`, Punctuation, Push("block")},
			{`;`, Punctuation, Pop(1)},
			Include("base"),
		},
		"base": {
			{`#.*\n`, CommentSingle, nil},
			{`on|off`, NameConstant, nil},
			{`\$[^\s;#()]+`, NameVariable, nil},
			{`([a-z0-9.-]+)(:)([0-9]+)`, ByGroups(Name, Punctuation, LiteralNumberInteger), nil},
			{`[a-z-]+/[a-z-+]+`, LiteralString, nil},
			{`[0-9]+[km]?\b`, LiteralNumberInteger, nil},
			{`(~)(\s*)([^\s{]+)`, ByGroups(Punctuation, Text, LiteralStringRegex), nil},
			{`[:=~]`, Punctuation, nil},
			{`[^\s;#{}$]+`, LiteralString, nil},
			{`/[^\s;#]*`, Name, nil},
			{`\s+`, Text, nil},
			{`[$;]`, Text, nil},
		},
	},
))

Nginx Configuration File lexer.

var Nim = internal.Register(MustNewLexer(
	&Config{
		Name:            "Nim",
		Aliases:         []string{"nim", "nimrod"},
		Filenames:       []string{"*.nim", "*.nimrod"},
		MimeTypes:       []string{"text/x-nim"},
		CaseInsensitive: true,
	},
	Rules{
		"root": {
			{`##.*$`, LiteralStringDoc, nil},
			{`#.*$`, Comment, nil},
			{`[*=><+\-/@$~&%!?|\\\[\]]`, Operator, nil},
			{"\\.\\.|\\.|,|\\[\\.|\\.\\]|\\{\\.|\\.\\}|\\(\\.|\\.\\)|\\{|\\}|\\(|\\)|:|\\^|`|;", Punctuation, nil},
			{`(?:[\w]+)"`, LiteralString, Push("rdqs")},
			{`"""`, LiteralString, Push("tdqs")},
			{`"`, LiteralString, Push("dqs")},
			{`'`, LiteralStringChar, Push("chars")},
			{`(a_?n_?d_?|o_?r_?|n_?o_?t_?|x_?o_?r_?|s_?h_?l_?|s_?h_?r_?|d_?i_?v_?|m_?o_?d_?|i_?n_?|n_?o_?t_?i_?n_?|i_?s_?|i_?s_?n_?o_?t_?)\b`, OperatorWord, nil},
			{`(p_?r_?o_?c_?\s)(?![(\[\]])`, Keyword, Push("funcname")},
			{"" /* 948 byte string literal not displayed */, Keyword, nil},
			{`(f_?r_?o_?m_?|i_?m_?p_?o_?r_?t_?|i_?n_?c_?l_?u_?d_?e_?)\b`, KeywordNamespace, nil},
			{`(v_?a_?r)\b`, KeywordDeclaration, nil},
			{"" /* 233 byte string literal not displayed */, KeywordType, nil},
			{`(n_?i_?l_?|t_?r_?u_?e_?|f_?a_?l_?s_?e_?)\b`, KeywordPseudo, nil},
			{`\b_\b`, Name, nil},
			{`\b((?![_\d])\w)(((?!_)\w)|(_(?!_)\w))*`, Name, nil},
			{`[0-9][0-9_]*(?=([e.]|\'f(32|64)))`, LiteralNumberFloat, Push("float-suffix", "float-number")},
			{`0x[a-f0-9][a-f0-9_]*`, LiteralNumberHex, Push("int-suffix")},
			{`0b[01][01_]*`, LiteralNumberBin, Push("int-suffix")},
			{`0o[0-7][0-7_]*`, LiteralNumberOct, Push("int-suffix")},
			{`[0-9][0-9_]*`, LiteralNumberInteger, Push("int-suffix")},
			{`\s+`, Text, nil},
			{`.+$`, Error, nil},
		},
		"chars": {
			{`\\([\\abcefnrtvl"\']|x[a-f0-9]{2}|[0-9]{1,3})`, LiteralStringEscape, nil},
			{`'`, LiteralStringChar, Pop(1)},
			{`.`, LiteralStringChar, nil},
		},
		"strings": {
			{`(?<!\$)\$(\d+|#|\w+)+`, LiteralStringInterpol, nil},
			{`[^\\\'"$\n]+`, LiteralString, nil},
			{`[\'"\\]`, LiteralString, nil},
			{`\$`, LiteralString, nil},
		},
		"dqs": {
			{`\\([\\abcefnrtvl"\']|\n|x[a-f0-9]{2}|[0-9]{1,3})`, LiteralStringEscape, nil},
			{`"`, LiteralString, Pop(1)},
			Include("strings"),
		},
		"rdqs": {
			{`"(?!")`, LiteralString, Pop(1)},
			{`""`, LiteralStringEscape, nil},
			Include("strings"),
		},
		"tdqs": {
			{`"""(?!")`, LiteralString, Pop(1)},
			Include("strings"),
			Include("nl"),
		},
		"funcname": {
			{`((?![\d_])\w)(((?!_)\w)|(_(?!_)\w))*`, NameFunction, Pop(1)},
			{"`.+`", NameFunction, Pop(1)},
		},
		"nl": {
			{`\n`, LiteralString, nil},
		},
		"float-number": {
			{`\.(?!\.)[0-9_]*`, LiteralNumberFloat, nil},
			{`e[+-]?[0-9][0-9_]*`, LiteralNumberFloat, nil},
			Default(Pop(1)),
		},
		"float-suffix": {
			{`\'f(32|64)`, LiteralNumberFloat, nil},
			Default(Pop(1)),
		},
		"int-suffix": {
			{`\'i(32|64)`, LiteralNumberIntegerLong, nil},
			{`\'i(8|16)`, LiteralNumberInteger, nil},
			Default(Pop(1)),
		},
	},
))

Nim lexer.

var Nix = internal.Register(MustNewLexer(
	&Config{
		Name:      "Nix",
		Aliases:   []string{"nixos", "nix"},
		Filenames: []string{"*.nix"},
		MimeTypes: []string{"text/x-nix"},
	},
	Rules{
		"root": {
			Include("keywords"),
			Include("builtins"),

			Include("literals"),
			Include("operators"),
			{`#.*$`, CommentSingle, nil},
			{`/\*`, CommentMultiline, Push("comment")},
			{`\(`, Punctuation, Push("paren")},
			{`\[`, Punctuation, Push("list")},
			{`"`, StringDouble, Push("qstring")},
			{`''`, StringSingle, Push("istring")},
			{`{`, Punctuation, Push("scope")},
			{`let` + nixb, Keyword, Push("scope")},
			Include("id"),
			Include("space"),
		},
		"keywords": {
			{`import` + nixb, KeywordNamespace, nil},
			{Words(``, nixb, strings.Fields("rec inherit with if then else assert")...), Keyword, nil},
		},
		"builtins": {
			{`throw` + nixb, NameException, nil},
			{Words(``, nixb, strings.Fields("" /* 161 byte string literal not displayed */)...), NameBuiltin, nil},
		},
		"literals": {
			{Words(``, nixb, strings.Fields("true false null")...), NameConstant, nil},
			Include("uri"),
			Include("path"),
			Include("int"),
			Include("float"),
		},
		"operators": {
			{` [/-] `, Operator, nil},
			{`(\.)(\${)`, ByGroups(Operator, StringInterpol), Push("interpol")},
			{`(\?)(\s*)(\${)`, ByGroups(Operator, Text, StringInterpol), Push("interpol")},
			{Words(``, ``, strings.Fields("@ . ? ++ + != ! // == && || -> <= < >= > *")...), Operator, nil},
			{`[;:]`, Punctuation, nil},
		},
		"comment": {
			{`\*/`, CommentMultiline, Pop(1)},
			{`.|\n`, CommentMultiline, nil},
		},
		"paren": {
			{`\)`, Punctuation, Pop(1)},
			Include("root"),
		},
		"list": {
			{`\]`, Punctuation, Pop(1)},
			Include("root"),
		},
		"qstring": {
			{`"`, StringDouble, Pop(1)},
			{`\${`, StringInterpol, Push("interpol")},
			{`\\.`, StringEscape, nil},
			{`.|\n`, StringDouble, nil},
		},
		"istring": {
			{`''\$`, StringEscape, nil},
			{`'''`, StringEscape, nil},
			{`''\\.`, StringEscape, nil},
			{`''`, StringSingle, Pop(1)},
			{`\${`, StringInterpol, Push("interpol")},

			{`\$.`, StringSingle, nil},
			{`.|\n`, StringSingle, nil},
		},
		"scope": {
			{`}:`, Punctuation, Pop(1)},
			{`}`, Punctuation, Pop(1)},
			{`in` + nixb, Keyword, Pop(1)},
			{`\${`, StringInterpol, Push("interpol")},
			Include("root"),
			{Words(``, ``, strings.Fields("= ? ,")...), Operator, nil},
		},
		"interpol": {
			{`}`, StringInterpol, Pop(1)},
			Include("root"),
		},
		"id": {
			{`[a-zA-Z_][a-zA-Z0-9_'-]*`, Name, nil},
		},
		"uri": {
			{`[a-zA-Z][a-zA-Z0-9+.-]*:[a-zA-Z0-9%/?:@&=+$,_.!~*'-]+`, StringDoc, nil},
		},
		"path": {
			{`[a-zA-Z0-9._+-]*(/[a-zA-Z0-9._+-]+)+`, StringRegex, nil},
			{`~(/[a-zA-Z0-9._+-]+)+/?`, StringRegex, nil},
			{`<[a-zA-Z0-9._+-]+(/[a-zA-Z0-9._+-]+)*>`, StringRegex, nil},
		},
		"int": {
			{`-?[0-9]+` + nixb, NumberInteger, nil},
		},
		"float": {
			{`-?(([1-9][0-9]*\.[0-9]*)|(0?\.[0-9]+))([Ee][+-]?[0-9]+)?` + nixb, NumberFloat, nil},
		},
		"space": {
			{`[ \t\r\n]+`, Text, nil},
		},
	},
))

Nix lexer.

Source Files

nasm.go newspeak.go nginx.go nim.go nix.go

Version
v0.6.6
Published
Jul 20, 2019
Platform
js/wasm
Imports
3 packages
Last checked
35 minutes ago

Tools for package owners.