d

package
v0.6.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2019 License: MIT Imports: 4 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var D = internal.Register(MustNewLexer(
	&Config{
		Name:      "D",
		Aliases:   []string{"d"},
		Filenames: []string{"*.d", "*.di"},
		MimeTypes: []string{"text/x-d"},
		EnsureNL:  true,
	},
	Rules{
		"root": {
			{`[^\S\n]+`, Text, nil},

			{`//.*?\n`, CommentSingle, nil},
			{`/\*.*?\*/`, CommentMultiline, nil},
			{`/\+.*?\+/`, CommentMultiline, nil},

			{`(asm|assert|body|break|case|cast|catch|continue|default|debug|delete|deprecated|do|else|finally|for|foreach|foreach_reverse|goto|if|in|invariant|is|macro|mixin|new|out|pragma|return|super|switch|this|throw|try|version|while|with)\b`, Keyword, nil},
			{`__(FILE|FILE_FULL_PATH|MODULE|LINE|FUNCTION|PRETTY_FUNCTION|DATE|EOF|TIME|TIMESTAMP|VENDOR|VERSION)__\b`, NameBuiltin, nil},
			{`__(traits|vector|parameters)\b`, NameBuiltin, nil},
			{`((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)((?:[^\W\d]|\$)[\w$]*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil},

			{`@[\w.]*`, NameDecorator, nil},
			{`(abstract|auto|alias|align|const|delegate|enum|export|final|function|inout|lazy|nothrow|override|package|private|protected|public|pure|static|synchronized|template|volatile|__gshared)\b`, KeywordDeclaration, nil},

			{`(void|bool|byte|ubyte|short|ushort|int|uint|long|ulong|cent|ucent|float|double|real|ifloat|idouble|ireal|cfloat|cdouble|creal|char|wchar|dchar|string|wstring|dstring)\b`, KeywordType, nil},
			{`(module)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
			{`(true|false|null)\b`, KeywordConstant, nil},
			{`(class|interface|struct|template|union)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class")},
			{`(import)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},

			{`[qr]?"(\\\\|\\"|[^"])*"[cwd]?`, LiteralString, nil},
			{"(`)([^`]*)(`)[cwd]?", LiteralString, nil},
			{`'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'`, LiteralStringChar, nil},
			{`(\.)((?:[^\W\d]|\$)[\w$]*)`, ByGroups(Operator, NameAttribute), nil},
			{`^\s*([^\W\d]|\$)[\w$]*:`, NameLabel, nil},

			{`([0-9][0-9_]*\.([0-9][0-9_]*)?|\.[0-9][0-9_]*)([eE][+\-]?[0-9][0-9_]*)?[fFL]?i?|[0-9][eE][+\-]?[0-9][0-9_]*[fFL]?|[0-9]([eE][+\-]?[0-9][0-9_]*)?[fFL]|0[xX]([0-9a-fA-F][0-9a-fA-F_]*\.?|([0-9a-fA-F][0-9a-fA-F_]*)?\.[0-9a-fA-F][0-9a-fA-F_]*)[pP][+\-]?[0-9][0-9_]*[fFL]?`, LiteralNumberFloat, nil},

			{`0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?`, LiteralNumberHex, nil},
			{`0[bB][01][01_]*[lL]?`, LiteralNumberBin, nil},
			{`0[0-7_]+[lL]?`, LiteralNumberOct, nil},
			{`0|[1-9][0-9_]*[lL]?`, LiteralNumberInteger, nil},
			{`([~^*!%&\[\](){}<>|+=:;,./?-]|q{)`, Operator, nil},
			{`([^\W\d]|\$)[\w$]*`, Name, nil},
			{`\n`, Text, nil},
		},
		"class": {
			{`([^\W\d]|\$)[\w$]*`, NameClass, Pop(1)},
		},
		"import": {
			{`[\w.]+\*?`, NameNamespace, Pop(1)},
		},
	},
))

D lexer. https://dlang.org/spec/lex.html

View Source
var Dart = internal.Register(MustNewLexer(
	&Config{
		Name:      "Dart",
		Aliases:   []string{"dart"},
		Filenames: []string{"*.dart"},
		MimeTypes: []string{"text/x-dart"},
		DotAll:    true,
	},
	Rules{
		"root": {
			Include("string_literal"),
			{`#!(.*?)$`, CommentPreproc, nil},
			{`\b(import|export)\b`, Keyword, Push("import_decl")},
			{`\b(library|source|part of|part)\b`, Keyword, nil},
			{`[^\S\n]+`, Text, nil},
			{`//.*?\n`, CommentSingle, nil},
			{`/\*.*?\*/`, CommentMultiline, nil},
			{`\b(class)\b(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class")},
			{`\b(assert|break|case|catch|continue|default|do|else|finally|for|if|in|is|new|return|super|switch|this|throw|try|while)\b`, Keyword, nil},
			{`\b(abstract|async|await|const|extends|factory|final|get|implements|native|operator|set|static|sync|typedef|var|with|yield)\b`, KeywordDeclaration, nil},
			{`\b(bool|double|dynamic|int|num|Object|String|void)\b`, KeywordType, nil},
			{`\b(false|null|true)\b`, KeywordConstant, nil},
			{`[~!%^&*+=|?:<>/-]|as\b`, Operator, nil},
			{`[a-zA-Z_$]\w*:`, NameLabel, nil},
			{`[a-zA-Z_$]\w*`, Name, nil},
			{`[(){}\[\],.;]`, Punctuation, nil},
			{`0[xX][0-9a-fA-F]+`, LiteralNumberHex, nil},
			{`\d+(\.\d*)?([eE][+-]?\d+)?`, LiteralNumber, nil},
			{`\.\d+([eE][+-]?\d+)?`, LiteralNumber, nil},
			{`\n`, Text, nil},
		},
		"class": {
			{`[a-zA-Z_$]\w*`, NameClass, Pop(1)},
		},
		"import_decl": {
			Include("string_literal"),
			{`\s+`, Text, nil},
			{`\b(as|show|hide)\b`, Keyword, nil},
			{`[a-zA-Z_$]\w*`, Name, nil},
			{`\,`, Punctuation, nil},
			{`\;`, Punctuation, Pop(1)},
		},
		"string_literal": {
			{`r"""([\w\W]*?)"""`, LiteralStringDouble, nil},
			{`r'''([\w\W]*?)'''`, LiteralStringSingle, nil},
			{`r"(.*?)"`, LiteralStringDouble, nil},
			{`r'(.*?)'`, LiteralStringSingle, nil},
			{`"""`, LiteralStringDouble, Push("string_double_multiline")},
			{`'''`, LiteralStringSingle, Push("string_single_multiline")},
			{`"`, LiteralStringDouble, Push("string_double")},
			{`'`, LiteralStringSingle, Push("string_single")},
		},
		"string_common": {
			{`\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z'\"$\\])`, LiteralStringEscape, nil},
			{`(\$)([a-zA-Z_]\w*)`, ByGroups(LiteralStringInterpol, Name), nil},
			{`(\$\{)(.*?)(\})`, ByGroups(LiteralStringInterpol, UsingSelf("root"), LiteralStringInterpol), nil},
		},
		"string_double": {
			{`"`, LiteralStringDouble, Pop(1)},
			{`[^"$\\\n]+`, LiteralStringDouble, nil},
			Include("string_common"),
			{`\$+`, LiteralStringDouble, nil},
		},
		"string_double_multiline": {
			{`"""`, LiteralStringDouble, Pop(1)},
			{`[^"$\\]+`, LiteralStringDouble, nil},
			Include("string_common"),
			{`(\$|\")+`, LiteralStringDouble, nil},
		},
		"string_single": {
			{`'`, LiteralStringSingle, Pop(1)},
			{`[^'$\\\n]+`, LiteralStringSingle, nil},
			Include("string_common"),
			{`\$+`, LiteralStringSingle, nil},
		},
		"string_single_multiline": {
			{`'''`, LiteralStringSingle, Pop(1)},
			{`[^\'$\\]+`, LiteralStringSingle, nil},
			Include("string_common"),
			{`(\$|\')+`, LiteralStringSingle, nil},
		},
	},
))

Dart lexer.

View Source
var Diff = internal.Register(MustNewLexer(
	&Config{
		Name:      "Diff",
		Aliases:   []string{"diff", "udiff"},
		EnsureNL:  true,
		Filenames: []string{"*.diff", "*.patch"},
		MimeTypes: []string{"text/x-diff", "text/x-patch"},
	},
	Rules{
		"root": {
			{` .*\n`, Text, nil},
			{`\+.*\n`, GenericInserted, nil},
			{`-.*\n`, GenericDeleted, nil},
			{`!.*\n`, GenericStrong, nil},
			{`@.*\n`, GenericSubheading, nil},
			{`([Ii]ndex|diff).*\n`, GenericHeading, nil},
			{`=.*\n`, GenericHeading, nil},
			{`.*\n`, Text, nil},
		},
	},
))

Diff lexer.

View Source
var DjangoJinja = internal.Register(MustNewLexer(
	&Config{
		Name:      "Django/Jinja",
		Aliases:   []string{"django", "jinja"},
		Filenames: []string{},
		MimeTypes: []string{"application/x-django-templating", "application/x-jinja"},
		DotAll:    true,
	},
	Rules{
		"root": {
			{`[^{]+`, Other, nil},
			{`\{\{`, CommentPreproc, Push("var")},
			{`\{[*#].*?[*#]\}`, Comment, nil},
			{`(\{%)(-?\s*)(comment)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endcomment)(\s*-?)(%\})`, ByGroups(CommentPreproc, Text, Keyword, Text, CommentPreproc, Comment, CommentPreproc, Text, Keyword, Text, CommentPreproc), nil},
			{`(\{%)(-?\s*)(raw)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endraw)(\s*-?)(%\})`, ByGroups(CommentPreproc, Text, Keyword, Text, CommentPreproc, Text, CommentPreproc, Text, Keyword, Text, CommentPreproc), nil},
			{`(\{%)(-?\s*)(filter)(\s+)([a-zA-Z_]\w*)`, ByGroups(CommentPreproc, Text, Keyword, Text, NameFunction), Push("block")},
			{`(\{%)(-?\s*)([a-zA-Z_]\w*)`, ByGroups(CommentPreproc, Text, Keyword), Push("block")},
			{`\{`, Other, nil},
		},
		"varnames": {
			{`(\|)(\s*)([a-zA-Z_]\w*)`, ByGroups(Operator, Text, NameFunction), nil},
			{`(is)(\s+)(not)?(\s+)?([a-zA-Z_]\w*)`, ByGroups(Keyword, Text, Keyword, Text, NameFunction), nil},
			{`(_|true|false|none|True|False|None)\b`, KeywordPseudo, nil},
			{`(in|as|reversed|recursive|not|and|or|is|if|else|import|with(?:(?:out)?\s*context)?|scoped|ignore\s+missing)\b`, Keyword, nil},
			{`(loop|block|super|forloop)\b`, NameBuiltin, nil},
			{`[a-zA-Z_][\w-]*`, NameVariable, nil},
			{`\.\w+`, NameVariable, nil},
			{`:?"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
			{`:?'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
			{`([{}()\[\]+\-*/,:~]|[><=]=?)`, Operator, nil},
			{`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil},
		},
		"var": {
			{`\s+`, Text, nil},
			{`(-?)(\}\})`, ByGroups(Text, CommentPreproc), Pop(1)},
			Include("varnames"),
		},
		"block": {
			{`\s+`, Text, nil},
			{`(-?)(%\})`, ByGroups(Text, CommentPreproc), Pop(1)},
			Include("varnames"),
			{`.`, Punctuation, nil},
		},
	},
))

Django/Jinja lexer.

View Source
var Docker = internal.Register(MustNewLexer(
	&Config{
		Name:            "Docker",
		Aliases:         []string{"docker", "dockerfile"},
		Filenames:       []string{"Dockerfile", "*.docker"},
		MimeTypes:       []string{"text/x-dockerfile-config"},
		CaseInsensitive: true,
	},
	Rules{
		"root": {
			{`#.*`, Comment, nil},
			{`(ONBUILD)((?:\s*\\?\s*))`, ByGroups(Keyword, Using(b.Bash)), nil},
			{`(HEALTHCHECK)(((?:\s*\\?\s*)--\w+=\w+(?:\s*\\?\s*))*)`, ByGroups(Keyword, Using(b.Bash)), nil},
			{`(VOLUME|ENTRYPOINT|CMD|SHELL)((?:\s*\\?\s*))(\[.*?\])`, ByGroups(Keyword, Using(b.Bash), Using(j.JSON)), nil},
			{`(LABEL|ENV|ARG)((?:(?:\s*\\?\s*)\w+=\w+(?:\s*\\?\s*))*)`, ByGroups(Keyword, Using(b.Bash)), nil},
			{`((?:FROM|MAINTAINER|EXPOSE|WORKDIR|USER|STOPSIGNAL)|VOLUME)\b(.*)`, ByGroups(Keyword, LiteralString), nil},
			{`((?:RUN|CMD|ENTRYPOINT|ENV|ARG|LABEL|ADD|COPY))`, Keyword, nil},
			{`(.*\\\n)*.+`, Using(b.Bash), nil},
		},
	},
))

Docker lexer.

View Source
var Dtd = internal.Register(MustNewLexer(
	&Config{
		Name:      "DTD",
		Aliases:   []string{"dtd"},
		Filenames: []string{"*.dtd"},
		MimeTypes: []string{"application/xml-dtd"},
		DotAll:    true,
	},
	Rules{
		"root": {
			Include("common"),
			{`(<!ELEMENT)(\s+)(\S+)`, ByGroups(Keyword, Text, NameTag), Push("element")},
			{`(<!ATTLIST)(\s+)(\S+)`, ByGroups(Keyword, Text, NameTag), Push("attlist")},
			{`(<!ENTITY)(\s+)(\S+)`, ByGroups(Keyword, Text, NameEntity), Push("entity")},
			{`(<!NOTATION)(\s+)(\S+)`, ByGroups(Keyword, Text, NameTag), Push("notation")},
			{`(<!\[)([^\[\s]+)(\s*)(\[)`, ByGroups(Keyword, NameEntity, Text, Keyword), nil},
			{`(<!DOCTYPE)(\s+)([^>\s]+)`, ByGroups(Keyword, Text, NameTag), nil},
			{`PUBLIC|SYSTEM`, KeywordConstant, nil},
			{`[\[\]>]`, Keyword, nil},
		},
		"common": {
			{`\s+`, Text, nil},
			{`(%|&)[^;]*;`, NameEntity, nil},
			{`<!--`, Comment, Push("comment")},
			{`[(|)*,?+]`, Operator, nil},
			{`"[^"]*"`, LiteralStringDouble, nil},
			{`\'[^\']*\'`, LiteralStringSingle, nil},
		},
		"comment": {
			{`[^-]+`, Comment, nil},
			{`-->`, Comment, Pop(1)},
			{`-`, Comment, nil},
		},
		"element": {
			Include("common"),
			{`EMPTY|ANY|#PCDATA`, KeywordConstant, nil},
			{`[^>\s|()?+*,]+`, NameTag, nil},
			{`>`, Keyword, Pop(1)},
		},
		"attlist": {
			Include("common"),
			{`CDATA|IDREFS|IDREF|ID|NMTOKENS|NMTOKEN|ENTITIES|ENTITY|NOTATION`, KeywordConstant, nil},
			{`#REQUIRED|#IMPLIED|#FIXED`, KeywordConstant, nil},
			{`xml:space|xml:lang`, KeywordReserved, nil},
			{`[^>\s|()?+*,]+`, NameAttribute, nil},
			{`>`, Keyword, Pop(1)},
		},
		"entity": {
			Include("common"),
			{`SYSTEM|PUBLIC|NDATA`, KeywordConstant, nil},
			{`[^>\s|()?+*,]+`, NameEntity, nil},
			{`>`, Keyword, Pop(1)},
		},
		"notation": {
			Include("common"),
			{`SYSTEM|PUBLIC`, KeywordConstant, nil},
			{`[^>\s|()?+*,]+`, NameAttribute, nil},
			{`>`, Keyword, Pop(1)},
		},
	},
))

Dtd lexer.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL