diff --git a/lexers/a/abap.go b/lexers/a/abap.go index 61c294e..268aa6a 100644 --- a/lexers/a/abap.go +++ b/lexers/a/abap.go @@ -6,7 +6,7 @@ import ( ) // ABAP lexer. -var Abap = internal.Register(MustNewLexer( +var Abap = internal.Register(MustNewLazyLexer( &Config{ Name: "ABAP", Aliases: []string{"abap"}, @@ -14,7 +14,11 @@ var Abap = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-abap"}, CaseInsensitive: true, }, - Rules{ + abapRules, +)) + +func abapRules() Rules { + return Rules{ "common": { {`\s+`, Text, nil}, {`^\*.*$`, CommentSingle, nil}, @@ -52,5 +56,5 @@ var Abap = internal.Register(MustNewLexer( {`[/;:()\[\],.]`, Punctuation, nil}, {`(!)(\w+)`, ByGroups(Operator, Name), nil}, }, - }, -)) + } +} diff --git a/lexers/a/abnf.go b/lexers/a/abnf.go index ff29aed..85c47af 100644 --- a/lexers/a/abnf.go +++ b/lexers/a/abnf.go @@ -6,14 +6,18 @@ import ( ) // Abnf lexer. -var Abnf = internal.Register(MustNewLexer( +var Abnf = internal.Register(MustNewLazyLexer( &Config{ Name: "ABNF", Aliases: []string{"abnf"}, Filenames: []string{"*.abnf"}, MimeTypes: []string{"text/x-abnf"}, }, - Rules{ + abnfRules, +)) + +func abnfRules() Rules { + return Rules{ "root": { {`;.*$`, CommentSingle, nil}, {`(%[si])?"[^"]*"`, Literal, nil}, @@ -34,5 +38,5 @@ var Abnf = internal.Register(MustNewLexer( {`\s+`, Text, nil}, {`.`, Text, nil}, }, - }, -)) + } +} diff --git a/lexers/a/actionscript.go b/lexers/a/actionscript.go index 43d3852..df55d6d 100644 --- a/lexers/a/actionscript.go +++ b/lexers/a/actionscript.go @@ -6,7 +6,7 @@ import ( ) // Actionscript lexer. -var Actionscript = internal.Register(MustNewLexer( +var Actionscript = internal.Register(MustNewLazyLexer( &Config{ Name: "ActionScript", Aliases: []string{"as", "actionscript"}, @@ -15,7 +15,11 @@ var Actionscript = internal.Register(MustNewLexer( NotMultiline: true, DotAll: true, }, - Rules{ + actionscriptRules, +)) + +func actionscriptRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`//.*?\n`, CommentSingle, nil}, @@ -35,5 +39,5 @@ var Actionscript = internal.Register(MustNewLexer( {`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil}, {`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil}, }, - }, -)) + } +} diff --git a/lexers/a/actionscript3.go b/lexers/a/actionscript3.go index 3404bd5..45596dc 100644 --- a/lexers/a/actionscript3.go +++ b/lexers/a/actionscript3.go @@ -6,7 +6,7 @@ import ( ) // Actionscript 3 lexer. -var Actionscript3 = internal.Register(MustNewLexer( +var Actionscript3 = internal.Register(MustNewLazyLexer( &Config{ Name: "ActionScript 3", Aliases: []string{"as3", "actionscript3"}, @@ -14,7 +14,11 @@ var Actionscript3 = internal.Register(MustNewLexer( MimeTypes: []string{"application/x-actionscript3", "text/x-actionscript3", "text/actionscript3"}, DotAll: true, }, - Rules{ + actionscript3Rules, +)) + +func actionscript3Rules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`(function\s+)([$a-zA-Z_]\w*)(\s*)(\()`, ByGroups(KeywordDeclaration, NameFunction, Text, Operator), Push("funcparams")}, @@ -52,5 +56,5 @@ var Actionscript3 = internal.Register(MustNewLexer( {`,`, Operator, Pop(1)}, Default(Pop(1)), }, - }, -)) + } +} diff --git a/lexers/a/ada.go b/lexers/a/ada.go index d9b34e3..9167271 100644 --- a/lexers/a/ada.go +++ b/lexers/a/ada.go @@ -6,7 +6,7 @@ import ( ) // Ada lexer. -var Ada = internal.Register(MustNewLexer( +var Ada = internal.Register(MustNewLazyLexer( &Config{ Name: "Ada", Aliases: []string{"ada", "ada95", "ada2005"}, @@ -14,7 +14,11 @@ var Ada = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-ada"}, CaseInsensitive: true, }, - Rules{ + adaRules, +)) + +func adaRules() Rules { + return Rules{ "root": { {`[^\S\n]+`, Text, nil}, {`--.*?\n`, CommentSingle, nil}, @@ -110,5 +114,5 @@ var Ada = internal.Register(MustNewLexer( {`\)`, Punctuation, Pop(1)}, Include("root"), }, - }, -)) + } +} diff --git a/lexers/a/angular2.go b/lexers/a/angular2.go index 5258c92..a947eda 100644 --- a/lexers/a/angular2.go +++ b/lexers/a/angular2.go @@ -6,14 +6,18 @@ import ( ) // Angular2 lexer. -var Angular2 = internal.Register(MustNewLexer( +var Angular2 = internal.Register(MustNewLazyLexer( &Config{ Name: "Angular2", Aliases: []string{"ng2"}, Filenames: []string{}, MimeTypes: []string{}, }, - Rules{ + angular2Rules, +)) + +func angular2Rules() Rules { + return Rules{ "root": { {`[^{([*#]+`, Other, nil}, {`(\{\{)(\s*)`, ByGroups(CommentPreproc, Text), Push("ngExpression")}, @@ -38,5 +42,5 @@ var Angular2 = internal.Register(MustNewLexer( {`'.*?'`, LiteralString, Pop(1)}, {`[^\s>]+`, LiteralString, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/a/antlr.go b/lexers/a/antlr.go index d7649d4..c744353 100644 --- a/lexers/a/antlr.go +++ b/lexers/a/antlr.go @@ -6,14 +6,18 @@ import ( ) // ANTLR lexer. -var ANTLR = internal.Register(MustNewLexer( +var ANTLR = internal.Register(MustNewLazyLexer( &Config{ Name: "ANTLR", Aliases: []string{"antlr"}, Filenames: []string{}, MimeTypes: []string{}, }, - Rules{ + antlrRules, +)) + +func antlrRules() Rules { + return Rules{ "whitespace": { {`\s+`, TextWhitespace, nil}, }, @@ -97,5 +101,5 @@ var ANTLR = internal.Register(MustNewLexer( {`(\$[a-zA-Z]+)(\.?)(text|value)?`, ByGroups(NameVariable, Punctuation, NameProperty), nil}, {`(\\\\|\\\]|\\\[|[^\[\]])+`, Other, nil}, }, - }, -)) + } +} diff --git a/lexers/a/apache.go b/lexers/a/apache.go index 6c56a1d..5685eb1 100644 --- a/lexers/a/apache.go +++ b/lexers/a/apache.go @@ -6,7 +6,7 @@ import ( ) // Apacheconf lexer. -var Apacheconf = internal.Register(MustNewLexer( +var Apacheconf = internal.Register(MustNewLazyLexer( &Config{ Name: "ApacheConf", Aliases: []string{"apacheconf", "aconf", "apache"}, @@ -14,7 +14,11 @@ var Apacheconf = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-apacheconf"}, CaseInsensitive: true, }, - Rules{ + apacheconfRules, +)) + +func apacheconfRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`(#.*?)$`, Comment, nil}, @@ -34,5 +38,5 @@ var Apacheconf = internal.Register(MustNewLexer( {`"([^"\\]*(?:\\.[^"\\]*)*)"`, LiteralStringDouble, nil}, {`[^\s"\\]+`, Text, nil}, }, - }, -)) + } +} diff --git a/lexers/a/apl.go b/lexers/a/apl.go index 820e13b..6cf1ea0 100644 --- a/lexers/a/apl.go +++ b/lexers/a/apl.go @@ -6,14 +6,18 @@ import ( ) // Apl lexer. -var Apl = internal.Register(MustNewLexer( +var Apl = internal.Register(MustNewLazyLexer( &Config{ Name: "APL", Aliases: []string{"apl"}, Filenames: []string{"*.apl"}, MimeTypes: []string{}, }, - Rules{ + aplRules, +)) + +func aplRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`[⍝#].*$`, CommentSingle, nil}, @@ -32,5 +36,5 @@ var Apl = internal.Register(MustNewLexer( {`[⍺⍵⍶⍹∇:]`, NameBuiltinPseudo, nil}, {`[{}]`, KeywordType, nil}, }, - }, -)) + } +} diff --git a/lexers/a/applescript.go b/lexers/a/applescript.go index db83ed0..b6a53c5 100644 --- a/lexers/a/applescript.go +++ b/lexers/a/applescript.go @@ -6,7 +6,7 @@ import ( ) // Applescript lexer. -var Applescript = internal.Register(MustNewLexer( +var Applescript = internal.Register(MustNewLazyLexer( &Config{ Name: "AppleScript", Aliases: []string{"applescript"}, @@ -14,7 +14,11 @@ var Applescript = internal.Register(MustNewLexer( MimeTypes: []string{}, DotAll: true, }, - Rules{ + applescriptRules, +)) + +func applescriptRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`¬\n`, LiteralStringEscape, nil}, @@ -51,5 +55,5 @@ var Applescript = internal.Register(MustNewLexer( {`[^*(]+`, CommentMultiline, nil}, {`[*(]`, CommentMultiline, nil}, }, - }, -)) + } +} diff --git a/lexers/a/arduino.go b/lexers/a/arduino.go index b0cd8c9..0edbe3f 100644 --- a/lexers/a/arduino.go +++ b/lexers/a/arduino.go @@ -6,7 +6,7 @@ import ( ) // Arduino lexer. -var Arduino = internal.Register(MustNewLexer( +var Arduino = internal.Register(MustNewLazyLexer( &Config{ Name: "Arduino", Aliases: []string{"arduino"}, @@ -14,7 +14,11 @@ var Arduino = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-arduino"}, EnsureNL: true, }, - Rules{ + arduinoRules, +)) + +func arduinoRules() Rules { + return Rules{ "statements": { {Words(``, `\b`, `catch`, `const_cast`, `delete`, `dynamic_cast`, `explicit`, `export`, `friend`, `mutable`, `namespace`, `new`, `operator`, `private`, `protected`, `public`, `reinterpret_cast`, `restrict`, `static_cast`, `template`, `this`, `throw`, `throws`, `try`, `typeid`, `typename`, `using`, `virtual`, `constexpr`, `nullptr`, `decltype`, `thread_local`, `alignas`, `alignof`, `static_assert`, `noexcept`, `override`, `final`), Keyword, nil}, {`char(16_t|32_t)\b`, KeywordType, nil}, @@ -106,5 +110,5 @@ var Arduino = internal.Register(MustNewLexer( {`^\s*#endif.*?(?|\n\x1a]))(?:(?:[^\n\x1a^]|\^[\n\x1a]?[\w\W])*)`, CommentSingle, nil}, {`(?=((?:(?<=^[^:])|^[^:]?)[\t\v\f\r ,;=\xa0]*)(:))`, Text, Push("follow")}, @@ -190,5 +194,5 @@ var Batchfile = internal.Register(MustNewLexer( {`else(?=\^?[\t\v\f\r ,;=\xa0]|[&<>|\n\x1a])`, Keyword, Pop(1)}, Default(Pop(1)), }, - }, -)) + } +} diff --git a/lexers/b/bibtex.go b/lexers/b/bibtex.go index 1d76b1d..d6a0ae3 100644 --- a/lexers/b/bibtex.go +++ b/lexers/b/bibtex.go @@ -6,7 +6,7 @@ import ( ) // Bibtex lexer. -var Bibtex = internal.Register(MustNewLexer( +var Bibtex = internal.Register(MustNewLazyLexer( &Config{ Name: "BibTeX", Aliases: []string{"bib", "bibtex"}, @@ -15,7 +15,11 @@ var Bibtex = internal.Register(MustNewLexer( NotMultiline: true, CaseInsensitive: true, }, - Rules{ + bibtexRules, +)) + +func bibtexRules() Rules { + return Rules{ "root": { Include("whitespace"), {`@comment`, Comment, nil}, @@ -72,5 +76,5 @@ var Bibtex = internal.Register(MustNewLexer( "whitespace": { {`\s+`, Text, nil}, }, - }, -)) + } +} diff --git a/lexers/b/blitz.go b/lexers/b/blitz.go index 5d5ffc8..119f96b 100644 --- a/lexers/b/blitz.go +++ b/lexers/b/blitz.go @@ -6,7 +6,7 @@ import ( ) // Blitzbasic lexer. -var Blitzbasic = internal.Register(MustNewLexer( +var Blitzbasic = internal.Register(MustNewLazyLexer( &Config{ Name: "BlitzBasic", Aliases: []string{"blitzbasic", "b3d", "bplus"}, @@ -14,7 +14,11 @@ var Blitzbasic = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-bb"}, CaseInsensitive: true, }, - Rules{ + blitzbasicRules, +)) + +func blitzbasicRules() Rules { + return Rules{ "root": { {`[ \t]+`, Text, nil}, {`;.*?\n`, CommentSingle, nil}, @@ -44,5 +48,5 @@ var Blitzbasic = internal.Register(MustNewLexer( {`"C?`, LiteralStringDouble, Pop(1)}, {`[^"]+`, LiteralStringDouble, nil}, }, - }, -)) + } +} diff --git a/lexers/b/bnf.go b/lexers/b/bnf.go index 5123a45..dcf7360 100644 --- a/lexers/b/bnf.go +++ b/lexers/b/bnf.go @@ -6,19 +6,23 @@ import ( ) // Bnf lexer. -var Bnf = internal.Register(MustNewLexer( +var Bnf = internal.Register(MustNewLazyLexer( &Config{ Name: "BNF", Aliases: []string{"bnf"}, Filenames: []string{"*.bnf"}, MimeTypes: []string{"text/x-bnf"}, }, - Rules{ + bnfRules, +)) + +func bnfRules() Rules { + return Rules{ "root": { {`(<)([ -;=?-~]+)(>)`, ByGroups(Punctuation, NameClass, Punctuation), nil}, {`::=`, Operator, nil}, {`[^<>:]+`, Text, nil}, {`.`, Text, nil}, }, - }, -)) + } +} diff --git a/lexers/b/brainfuck.go b/lexers/b/brainfuck.go index 6fac5f5..d35e9c6 100644 --- a/lexers/b/brainfuck.go +++ b/lexers/b/brainfuck.go @@ -6,14 +6,18 @@ import ( ) // Brainfuck lexer. -var Brainfuck = internal.Register(MustNewLexer( +var Brainfuck = internal.Register(MustNewLazyLexer( &Config{ Name: "Brainfuck", Aliases: []string{"brainfuck", "bf"}, Filenames: []string{"*.bf", "*.b"}, MimeTypes: []string{"application/x-brainfuck"}, }, - Rules{ + brainfuckRules, +)) + +func brainfuckRules() Rules { + return Rules{ "common": { {`[.,]+`, NameTag, nil}, {`[+-]+`, NameBuiltin, nil}, @@ -30,5 +34,5 @@ var Brainfuck = internal.Register(MustNewLexer( {`\]`, Keyword, Pop(1)}, Include("common"), }, - }, -)) + } +} diff --git a/lexers/c/c.go b/lexers/c/c.go index e695f78..a81e7a8 100644 --- a/lexers/c/c.go +++ b/lexers/c/c.go @@ -6,7 +6,7 @@ import ( ) // C lexer. -var C = internal.Register(MustNewLexer( +var C = internal.Register(MustNewLazyLexer( &Config{ Name: "C", Aliases: []string{"c"}, @@ -14,7 +14,11 @@ var C = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-chdr", "text/x-csrc"}, EnsureNL: true, }, - Rules{ + cRules, +)) + +func cRules() Rules { + return Rules{ "whitespace": { {`^#if\s+0`, CommentPreproc, Push("if0")}, {`^#`, CommentPreproc, Push("macro")}, @@ -88,5 +92,5 @@ var C = internal.Register(MustNewLexer( {`^\s*#endif.*?(?\]`, NameDecorator, Push("matcher")}, - // These cannot have matchers but may have things that look like - // matchers in their arguments, so we just parse as a subdirective. - {`try_files`, Keyword, Push("subdirective")}, - // These are special, they can nest more directives - {`handle_errors|handle|route|handle_path|not`, Keyword, Push("nested_directive")}, - // Any other directive - {`[^\s#]+`, Keyword, Push("directive")}, - Include("base"), - }, - "matcher": { - {`\{`, Punctuation, Push("block")}, - // Not can be one-liner - {`not`, Keyword, Push("deep_not_matcher")}, - // Any other same-line matcher - {`[^\s#]+`, Keyword, Push("arguments")}, - // Terminators - {`\n`, Text, Pop(1)}, - {`\}`, Punctuation, Pop(1)}, - Include("base"), - }, - "block": { - {`\}`, Punctuation, Pop(2)}, - // Not can be one-liner - {`not`, Keyword, Push("not_matcher")}, - // Any other subdirective - {`[^\s#]+`, Keyword, Push("subdirective")}, - Include("base"), - }, - "nested_block": { - {`\}`, Punctuation, Pop(2)}, - // Matcher definition - {`@[^\s]+(?=\s)`, NameDecorator, Push("matcher")}, - // Something that starts with literally < is probably a docs stub - {`\<[^#]+\>`, Keyword, Push("nested_directive")}, - // Any other directive - {`[^\s#]+`, Keyword, Push("nested_directive")}, - Include("base"), - }, - "not_matcher": { - {`\}`, Punctuation, Pop(2)}, - {`\{(?=\s)`, Punctuation, Push("block")}, - {`[^\s#]+`, Keyword, Push("arguments")}, - {`\s+`, Text, nil}, - }, - "deep_not_matcher": { - {`\}`, Punctuation, Pop(2)}, - {`\{(?=\s)`, Punctuation, Push("block")}, - {`[^\s#]+`, Keyword, Push("deep_subdirective")}, - {`\s+`, Text, nil}, - }, - "directive": { - {`\{(?=\s)`, Punctuation, Push("block")}, - Include("matcher_token"), - Include("comments_pop_1"), - {`\n`, Text, Pop(1)}, - Include("base"), - }, - "nested_directive": { - {`\{(?=\s)`, Punctuation, Push("nested_block")}, - Include("matcher_token"), - Include("comments_pop_1"), - {`\n`, Text, Pop(1)}, - Include("base"), - }, - "subdirective": { - {`\{(?=\s)`, Punctuation, Push("block")}, - Include("comments_pop_1"), - {`\n`, Text, Pop(1)}, - Include("base"), - }, - "arguments": { - {`\{(?=\s)`, Punctuation, Push("block")}, - Include("comments_pop_2"), - {`\\\n`, Text, nil}, // Skip escaped newlines - {`\n`, Text, Pop(2)}, - Include("base"), - }, - "deep_subdirective": { - {`\{(?=\s)`, Punctuation, Push("block")}, - Include("comments_pop_3"), - {`\n`, Text, Pop(3)}, - Include("base"), - }, - "matcher_token": { - {`@[^\s]+`, NameDecorator, Push("arguments")}, // Named matcher - {`/[^\s]+`, NameDecorator, Push("arguments")}, // Path matcher - {`\*`, NameDecorator, Push("arguments")}, // Wildcard path matcher - {`\[\\]`, NameDecorator, Push("arguments")}, // Matcher token stub for docs - }, - "comments": { - {`^#.*\n`, CommentSingle, nil}, // Comment at start of line - {`\s+#.*\n`, CommentSingle, nil}, // Comment preceded by whitespace - }, - "comments_pop_1": { - {`^#.*\n`, CommentSingle, Pop(1)}, // Comment at start of line - {`\s+#.*\n`, CommentSingle, Pop(1)}, // Comment preceded by whitespace - }, - "comments_pop_2": { - {`^#.*\n`, CommentSingle, Pop(2)}, // Comment at start of line - {`\s+#.*\n`, CommentSingle, Pop(2)}, // Comment preceded by whitespace - }, - "comments_pop_3": { - {`^#.*\n`, CommentSingle, Pop(3)}, // Comment at start of line - {`\s+#.*\n`, CommentSingle, Pop(3)}, // Comment preceded by whitespace - }, - "base": { - Include("comments"), - {`(on|off|first|last|before|after|internal|strip_prefix|strip_suffix|replace)\b`, NameConstant, nil}, - {`(https?://)?([a-z0-9.-]+)(:)([0-9]+)`, ByGroups(Name, Name, Punctuation, LiteralNumberInteger), nil}, - {`[a-z-]+/[a-z-+]+`, LiteralString, nil}, - {`[0-9]+[km]?\b`, LiteralNumberInteger, nil}, - {`\{[\w+.\$-]+\}`, LiteralStringEscape, nil}, // Placeholder - {`\[(?=[^#{}$]+\])`, Punctuation, nil}, - {`\]|\|`, Punctuation, nil}, - {`[^\s#{}$\]]+`, LiteralString, nil}, - {`/[^\s#]*`, Name, nil}, - {`\s+`, Text, nil}, - }, +func caddyfileCommonRules() Rules { + return Rules{ + "site_block_common": { + // Import keyword + {`(import)(\s+)([^\s]+)`, ByGroups(Keyword, Text, NameVariableMagic), nil}, + // Matcher definition + {`@[^\s]+(?=\s)`, NameDecorator, Push("matcher")}, + // Matcher token stub for docs + {`\[\\]`, NameDecorator, Push("matcher")}, + // These cannot have matchers but may have things that look like + // matchers in their arguments, so we just parse as a subdirective. + {`try_files`, Keyword, Push("subdirective")}, + // These are special, they can nest more directives + {`handle_errors|handle|route|handle_path|not`, Keyword, Push("nested_directive")}, + // Any other directive + {`[^\s#]+`, Keyword, Push("directive")}, + Include("base"), + }, + "matcher": { + {`\{`, Punctuation, Push("block")}, + // Not can be one-liner + {`not`, Keyword, Push("deep_not_matcher")}, + // Any other same-line matcher + {`[^\s#]+`, Keyword, Push("arguments")}, + // Terminators + {`\n`, Text, Pop(1)}, + {`\}`, Punctuation, Pop(1)}, + Include("base"), + }, + "block": { + {`\}`, Punctuation, Pop(2)}, + // Not can be one-liner + {`not`, Keyword, Push("not_matcher")}, + // Any other subdirective + {`[^\s#]+`, Keyword, Push("subdirective")}, + Include("base"), + }, + "nested_block": { + {`\}`, Punctuation, Pop(2)}, + // Matcher definition + {`@[^\s]+(?=\s)`, NameDecorator, Push("matcher")}, + // Something that starts with literally < is probably a docs stub + {`\<[^#]+\>`, Keyword, Push("nested_directive")}, + // Any other directive + {`[^\s#]+`, Keyword, Push("nested_directive")}, + Include("base"), + }, + "not_matcher": { + {`\}`, Punctuation, Pop(2)}, + {`\{(?=\s)`, Punctuation, Push("block")}, + {`[^\s#]+`, Keyword, Push("arguments")}, + {`\s+`, Text, nil}, + }, + "deep_not_matcher": { + {`\}`, Punctuation, Pop(2)}, + {`\{(?=\s)`, Punctuation, Push("block")}, + {`[^\s#]+`, Keyword, Push("deep_subdirective")}, + {`\s+`, Text, nil}, + }, + "directive": { + {`\{(?=\s)`, Punctuation, Push("block")}, + Include("matcher_token"), + Include("comments_pop_1"), + {`\n`, Text, Pop(1)}, + Include("base"), + }, + "nested_directive": { + {`\{(?=\s)`, Punctuation, Push("nested_block")}, + Include("matcher_token"), + Include("comments_pop_1"), + {`\n`, Text, Pop(1)}, + Include("base"), + }, + "subdirective": { + {`\{(?=\s)`, Punctuation, Push("block")}, + Include("comments_pop_1"), + {`\n`, Text, Pop(1)}, + Include("base"), + }, + "arguments": { + {`\{(?=\s)`, Punctuation, Push("block")}, + Include("comments_pop_2"), + {`\\\n`, Text, nil}, // Skip escaped newlines + {`\n`, Text, Pop(2)}, + Include("base"), + }, + "deep_subdirective": { + {`\{(?=\s)`, Punctuation, Push("block")}, + Include("comments_pop_3"), + {`\n`, Text, Pop(3)}, + Include("base"), + }, + "matcher_token": { + {`@[^\s]+`, NameDecorator, Push("arguments")}, // Named matcher + {`/[^\s]+`, NameDecorator, Push("arguments")}, // Path matcher + {`\*`, NameDecorator, Push("arguments")}, // Wildcard path matcher + {`\[\\]`, NameDecorator, Push("arguments")}, // Matcher token stub for docs + }, + "comments": { + {`^#.*\n`, CommentSingle, nil}, // Comment at start of line + {`\s+#.*\n`, CommentSingle, nil}, // Comment preceded by whitespace + }, + "comments_pop_1": { + {`^#.*\n`, CommentSingle, Pop(1)}, // Comment at start of line + {`\s+#.*\n`, CommentSingle, Pop(1)}, // Comment preceded by whitespace + }, + "comments_pop_2": { + {`^#.*\n`, CommentSingle, Pop(2)}, // Comment at start of line + {`\s+#.*\n`, CommentSingle, Pop(2)}, // Comment preceded by whitespace + }, + "comments_pop_3": { + {`^#.*\n`, CommentSingle, Pop(3)}, // Comment at start of line + {`\s+#.*\n`, CommentSingle, Pop(3)}, // Comment preceded by whitespace + }, + "base": { + Include("comments"), + {`(on|off|first|last|before|after|internal|strip_prefix|strip_suffix|replace)\b`, NameConstant, nil}, + {`(https?://)?([a-z0-9.-]+)(:)([0-9]+)`, ByGroups(Name, Name, Punctuation, LiteralNumberInteger), nil}, + {`[a-z-]+/[a-z-+]+`, LiteralString, nil}, + {`[0-9]+[km]?\b`, LiteralNumberInteger, nil}, + {`\{[\w+.\$-]+\}`, LiteralStringEscape, nil}, // Placeholder + {`\[(?=[^#{}$]+\])`, Punctuation, nil}, + {`\]|\|`, Punctuation, nil}, + {`[^\s#{}$\]]+`, LiteralString, nil}, + {`/[^\s#]*`, Name, nil}, + {`\s+`, Text, nil}, + }, + } } // Caddyfile lexer. -var Caddyfile = internal.Register(MustNewLexer( +var Caddyfile = internal.Register(MustNewLazyLexer( &Config{ Name: "Caddyfile", Aliases: []string{"caddyfile", "caddy"}, Filenames: []string{"Caddyfile*"}, MimeTypes: []string{}, }, - Rules{ + caddyfileRules, +)) + +func caddyfileRules() Rules { + return Rules{ "root": { Include("comments"), // Global options block @@ -186,21 +192,25 @@ var Caddyfile = internal.Register(MustNewLexer( {`\}`, Punctuation, Pop(2)}, Include("site_block_common"), }, - }.Merge(caddyfileCommon), -)) + }.Merge(caddyfileCommonRules()) +} // Caddyfile directive-only lexer. -var CaddyfileDirectives = internal.Register(MustNewLexer( +var CaddyfileDirectives = internal.Register(MustNewLazyLexer( &Config{ Name: "Caddyfile Directives", Aliases: []string{"caddyfile-directives", "caddyfile-d", "caddy-d"}, Filenames: []string{}, MimeTypes: []string{}, }, - Rules{ + caddyfileDirectivesRules, +)) + +func caddyfileDirectivesRules() Rules { + return Rules{ // Same as "site_block" in Caddyfile "root": { Include("site_block_common"), }, - }.Merge(caddyfileCommon), -)) + }.Merge(caddyfileCommonRules()) +} diff --git a/lexers/c/capnproto.go b/lexers/c/capnproto.go index 0f9d03c..ec0d892 100644 --- a/lexers/c/capnproto.go +++ b/lexers/c/capnproto.go @@ -6,14 +6,18 @@ import ( ) // Cap'N'Proto Proto lexer. -var CapNProto = internal.Register(MustNewLexer( +var CapNProto = internal.Register(MustNewLazyLexer( &Config{ Name: "Cap'n Proto", Aliases: []string{"capnp"}, Filenames: []string{"*.capnp"}, MimeTypes: []string{}, }, - Rules{ + capNProtoRules, +)) + +func capNProtoRules() Rules { + return Rules{ "root": { {`#.*?$`, CommentSingle, nil}, {`@[0-9a-zA-Z]*`, NameDecorator, nil}, @@ -57,5 +61,5 @@ var CapNProto = internal.Register(MustNewLexer( {`[])]`, NameAttribute, Pop(1)}, Default(Pop(1)), }, - }, -)) + } +} diff --git a/lexers/c/ceylon.go b/lexers/c/ceylon.go index 07324ca..9d424d4 100644 --- a/lexers/c/ceylon.go +++ b/lexers/c/ceylon.go @@ -6,7 +6,7 @@ import ( ) // Ceylon lexer. -var Ceylon = internal.Register(MustNewLexer( +var Ceylon = internal.Register(MustNewLazyLexer( &Config{ Name: "Ceylon", Aliases: []string{"ceylon"}, @@ -14,7 +14,11 @@ var Ceylon = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-ceylon"}, DotAll: true, }, - Rules{ + ceylonRules, +)) + +func ceylonRules() Rules { + return Rules{ "root": { {`^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)([a-zA-Z_]\w*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil}, {`[^\S\n]+`, Text, nil}, @@ -59,5 +63,5 @@ var Ceylon = internal.Register(MustNewLexer( {`\*/`, CommentMultiline, Pop(1)}, {`[*/]`, CommentMultiline, nil}, }, - }, -)) + } +} diff --git a/lexers/c/cfengine3.go b/lexers/c/cfengine3.go index f96252f..f305034 100644 --- a/lexers/c/cfengine3.go +++ b/lexers/c/cfengine3.go @@ -6,14 +6,18 @@ import ( ) // Cfengine3 lexer. -var Cfengine3 = internal.Register(MustNewLexer( +var Cfengine3 = internal.Register(MustNewLazyLexer( &Config{ Name: "CFEngine3", Aliases: []string{"cfengine3", "cf3"}, Filenames: []string{"*.cf"}, MimeTypes: []string{}, }, - Rules{ + cfengine3Rules, +)) + +func cfengine3Rules() Rules { + return Rules{ "root": { {`#.*?\n`, Comment, nil}, {`(body)(\s+)(\S+)(\s+)(control)`, ByGroups(Keyword, Text, Keyword, Text, Keyword), nil}, @@ -52,5 +56,5 @@ var Cfengine3 = internal.Register(MustNewLexer( {`\w+`, NameVariable, nil}, {`\s+`, Text, nil}, }, - }, -)) + } +} diff --git a/lexers/c/chaiscript.go b/lexers/c/chaiscript.go index d2aa50d..58db9aa 100644 --- a/lexers/c/chaiscript.go +++ b/lexers/c/chaiscript.go @@ -6,7 +6,7 @@ import ( ) // Chaiscript lexer. -var Chaiscript = internal.Register(MustNewLexer( +var Chaiscript = internal.Register(MustNewLazyLexer( &Config{ Name: "ChaiScript", Aliases: []string{"chai", "chaiscript"}, @@ -14,7 +14,11 @@ var Chaiscript = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-chaiscript", "application/x-chaiscript"}, DotAll: true, }, - Rules{ + chaiscriptRules, +)) + +func chaiscriptRules() Rules { + return Rules{ "commentsandwhitespace": { {`\s+`, Text, nil}, {`//.*?\n`, CommentSingle, nil}, @@ -59,5 +63,5 @@ var Chaiscript = internal.Register(MustNewLexer( {`[^\\"$]+`, LiteralStringDouble, nil}, {`"`, LiteralStringDouble, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/c/cheetah.go b/lexers/c/cheetah.go index b2cb9c4..bd5fb9d 100644 --- a/lexers/c/cheetah.go +++ b/lexers/c/cheetah.go @@ -7,14 +7,18 @@ import ( ) // Cheetah lexer. -var Cheetah = internal.Register(MustNewLexer( +var Cheetah = internal.Register(MustNewLazyLexer( &Config{ Name: "Cheetah", Aliases: []string{"cheetah", "spitfire"}, Filenames: []string{"*.tmpl", "*.spt"}, MimeTypes: []string{"application/x-cheetah", "application/x-spitfire"}, }, - Rules{ + cheetahRules, +)) + +func cheetahRules() Rules { + return Rules{ "root": { {`(##[^\n]*)$`, ByGroups(Comment), nil}, {`#[*](.|\n)*?[*]#`, Comment, nil}, @@ -33,5 +37,5 @@ var Cheetah = internal.Register(MustNewLexer( `, Other, nil}, {`\s+`, Text, nil}, }, - }, -)) + } +} diff --git a/lexers/c/cl.go b/lexers/c/cl.go index fdc9729..bb16273 100644 --- a/lexers/c/cl.go +++ b/lexers/c/cl.go @@ -230,7 +230,7 @@ var ( ) // Common Lisp lexer. -var CommonLisp = internal.Register(TypeRemappingLexer(MustNewLexer( +var CommonLisp = internal.Register(TypeRemappingLexer(MustNewLazyLexer( &Config{ Name: "Common Lisp", Aliases: []string{"common-lisp", "cl", "lisp"}, @@ -238,7 +238,19 @@ var CommonLisp = internal.Register(TypeRemappingLexer(MustNewLexer( MimeTypes: []string{"text/x-common-lisp"}, CaseInsensitive: true, }, - Rules{ + commonLispRules, +), TypeMapping{ + {NameVariable, NameFunction, clBuiltinFunctions}, + {NameVariable, Keyword, clSpecialForms}, + {NameVariable, NameBuiltin, clMacros}, + {NameVariable, Keyword, clLambdaListKeywords}, + {NameVariable, Keyword, clDeclarations}, + {NameVariable, KeywordType, clBuiltinTypes}, + {NameVariable, NameClass, clBuiltinClasses}, +})) + +func commonLispRules() Rules { + return Rules{ "root": { Default(Push("body")), }, @@ -294,13 +306,5 @@ var CommonLisp = internal.Register(TypeRemappingLexer(MustNewLexer( {`\(`, Punctuation, Push("body")}, {`\)`, Punctuation, Pop(1)}, }, - }, -), TypeMapping{ - {NameVariable, NameFunction, clBuiltinFunctions}, - {NameVariable, Keyword, clSpecialForms}, - {NameVariable, NameBuiltin, clMacros}, - {NameVariable, Keyword, clLambdaListKeywords}, - {NameVariable, Keyword, clDeclarations}, - {NameVariable, KeywordType, clBuiltinTypes}, - {NameVariable, NameClass, clBuiltinClasses}, -})) + } +} diff --git a/lexers/c/clojure.go b/lexers/c/clojure.go index e63752a..f99f906 100644 --- a/lexers/c/clojure.go +++ b/lexers/c/clojure.go @@ -6,14 +6,18 @@ import ( ) // Clojure lexer. -var Clojure = internal.Register(MustNewLexer( +var Clojure = internal.Register(MustNewLazyLexer( &Config{ Name: "Clojure", Aliases: []string{"clojure", "clj"}, Filenames: []string{"*.clj"}, MimeTypes: []string{"text/x-clojure", "application/x-clojure"}, }, - Rules{ + clojureRules, +)) + +func clojureRules() Rules { + return Rules{ "root": { {`;.*$`, CommentSingle, nil}, {`[,\s]+`, Text, nil}, @@ -34,5 +38,5 @@ var Clojure = internal.Register(MustNewLexer( {`(\{|\})`, Punctuation, nil}, {`(\(|\))`, Punctuation, nil}, }, - }, -)) + } +} diff --git a/lexers/c/cmake.go b/lexers/c/cmake.go index 163f17d..0e0708d 100644 --- a/lexers/c/cmake.go +++ b/lexers/c/cmake.go @@ -6,14 +6,18 @@ import ( ) // Cmake lexer. -var Cmake = internal.Register(MustNewLexer( +var Cmake = internal.Register(MustNewLazyLexer( &Config{ Name: "CMake", Aliases: []string{"cmake"}, Filenames: []string{"*.cmake", "CMakeLists.txt"}, MimeTypes: []string{"text/x-cmake"}, }, - Rules{ + cmakeRules, +)) + +func cmakeRules() Rules { + return Rules{ "root": { {`\b(\w+)([ \t]*)(\()`, ByGroups(NameBuiltin, Text, Punctuation), Push("args")}, Include("keywords"), @@ -40,5 +44,5 @@ var Cmake = internal.Register(MustNewLexer( {`[ \t]+`, Text, nil}, {`#.*\n`, Comment, nil}, }, - }, -)) + } +} diff --git a/lexers/c/cobol.go b/lexers/c/cobol.go index e9ae0bb..8b2f6d9 100644 --- a/lexers/c/cobol.go +++ b/lexers/c/cobol.go @@ -6,7 +6,7 @@ import ( ) // Cobol lexer. -var Cobol = internal.Register(MustNewLexer( +var Cobol = internal.Register(MustNewLazyLexer( &Config{ Name: "COBOL", Aliases: []string{"cobol"}, @@ -14,7 +14,11 @@ var Cobol = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-cobol"}, CaseInsensitive: true, }, - Rules{ + cobolRules, +)) + +func cobolRules() Rules { + return Rules{ "root": { Include("comment"), Include("strings"), @@ -47,5 +51,5 @@ var Cobol = internal.Register(MustNewLexer( {`[+-]?\d*\.\d+(E[-+]?\d+)?`, LiteralNumberFloat, nil}, {`[+-]?\d+\.\d*(E[-+]?\d+)?`, LiteralNumberFloat, nil}, }, - }, -)) + } +} diff --git a/lexers/c/coffee.go b/lexers/c/coffee.go index e402b8f..381a8fe 100644 --- a/lexers/c/coffee.go +++ b/lexers/c/coffee.go @@ -6,7 +6,7 @@ import ( ) // Coffeescript lexer. -var Coffeescript = internal.Register(MustNewLexer( +var Coffeescript = internal.Register(MustNewLazyLexer( &Config{ Name: "CoffeeScript", Aliases: []string{"coffee-script", "coffeescript", "coffee"}, @@ -15,7 +15,11 @@ var Coffeescript = internal.Register(MustNewLexer( NotMultiline: true, DotAll: true, }, - Rules{ + coffeescriptRules, +)) + +func coffeescriptRules() Rules { + return Rules{ "commentsandwhitespace": { {`\s+`, Text, nil}, {`###[^#].*?###`, CommentMultiline, nil}, @@ -87,5 +91,5 @@ var Coffeescript = internal.Register(MustNewLexer( {`#|\\.|\'|"`, LiteralString, nil}, Include("strings"), }, - }, -)) + } +} diff --git a/lexers/c/coldfusion.go b/lexers/c/coldfusion.go index 2f12472..bc28bc3 100644 --- a/lexers/c/coldfusion.go +++ b/lexers/c/coldfusion.go @@ -6,7 +6,7 @@ import ( ) // Cfstatement lexer. -var Cfstatement = internal.Register(MustNewLexer( +var Cfstatement = internal.Register(MustNewLazyLexer( &Config{ Name: "cfstatement", Aliases: []string{"cfs"}, @@ -15,7 +15,11 @@ var Cfstatement = internal.Register(MustNewLexer( NotMultiline: true, CaseInsensitive: true, }, - Rules{ + cfstatementRules, +)) + +func cfstatementRules() Rules { + return Rules{ "root": { {`//.*?\n`, CommentSingle, nil}, {`/\*(?:.|\n)*?\*/`, CommentMultiline, nil}, @@ -44,5 +48,5 @@ var Cfstatement = internal.Register(MustNewLexer( {`#`, LiteralStringDouble, nil}, {`"`, LiteralStringDouble, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/c/coq.go b/lexers/c/coq.go index e69a5c1..e0103ef 100644 --- a/lexers/c/coq.go +++ b/lexers/c/coq.go @@ -6,14 +6,18 @@ import ( ) // Coq lexer. -var Coq = internal.Register(MustNewLexer( +var Coq = internal.Register(MustNewLazyLexer( &Config{ Name: "Coq", Aliases: []string{"coq"}, Filenames: []string{"*.v"}, MimeTypes: []string{"text/x-coq"}, }, - Rules{ + coqRules, +)) + +func coqRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`false|true|\(\)|\[\]`, NameBuiltinPseudo, nil}, @@ -59,5 +63,5 @@ var Coq = internal.Register(MustNewLexer( {`[a-z][a-z0-9_\']*`, Name, Pop(1)}, Default(Pop(1)), }, - }, -)) + } +} diff --git a/lexers/c/cpp.go b/lexers/c/cpp.go index 104be24..3f4a1fd 100644 --- a/lexers/c/cpp.go +++ b/lexers/c/cpp.go @@ -6,7 +6,7 @@ import ( ) // CPP lexer. -var CPP = internal.Register(MustNewLexer( +var CPP = internal.Register(MustNewLazyLexer( &Config{ Name: "C++", Aliases: []string{"cpp", "c++"}, @@ -14,7 +14,11 @@ var CPP = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-c++hdr", "text/x-c++src"}, EnsureNL: true, }, - Rules{ + cppRules, +)) + +func cppRules() Rules { + return Rules{ "statements": { {Words(``, `\b`, `catch`, `const_cast`, `delete`, `dynamic_cast`, `explicit`, `export`, `friend`, `mutable`, `namespace`, `new`, `operator`, `private`, `protected`, `public`, `reinterpret_cast`, `restrict`, `static_cast`, `template`, `this`, `throw`, `throws`, `try`, `typeid`, `typename`, `using`, `virtual`, `constexpr`, `nullptr`, `decltype`, `thread_local`, `alignas`, `alignof`, `static_assert`, `noexcept`, `override`, `final`, `concept`, `requires`, `consteval`, `co_await`, `co_return`, `co_yield`), Keyword, nil}, {`(enum)\b(\s+)(class)\b(\s*)`, ByGroups(Keyword, Text, Keyword, Text), Push("classname")}, @@ -102,5 +106,5 @@ var CPP = internal.Register(MustNewLexer( {`^\s*#endif.*?(?=~!@#%^&|`?-]+", Operator, nil}, - {`(?s)(java|javascript)(\s+)(AS)(\s+)('|\$\$)(.*?)(\5)`, + { + `(?s)(java|javascript)(\s+)(AS)(\s+)('|\$\$)(.*?)(\5)`, UsingByGroup( internal.Get, 1, 6, @@ -65,5 +70,5 @@ var CassandraCQL = internal.Register(MustNewLexer( {`[^\$]+`, LiteralStringHeredoc, nil}, {`\$\$`, LiteralStringHeredoc, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/c/crystal.go b/lexers/c/crystal.go index 69e053c..f06830d 100644 --- a/lexers/c/crystal.go +++ b/lexers/c/crystal.go @@ -6,7 +6,7 @@ import ( ) // Crystal lexer. -var Crystal = internal.Register(MustNewLexer( +var Crystal = internal.Register(MustNewLazyLexer( &Config{ Name: "Crystal", Aliases: []string{"cr", "crystal"}, @@ -14,7 +14,11 @@ var Crystal = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-crystal"}, DotAll: true, }, - Rules{ + crystalRules, +)) + +func crystalRules() Rules { + return Rules{ "root": { {`#.*?$`, CommentSingle, nil}, {Words(``, `\b`, `abstract`, `asm`, `as`, `begin`, `break`, `case`, `do`, `else`, `elsif`, `end`, `ensure`, `extend`, `ifdef`, `if`, `include`, `instance_sizeof`, `next`, `of`, `pointerof`, `private`, `protected`, `rescue`, `return`, `require`, `sizeof`, `super`, `then`, `typeof`, `unless`, `until`, `when`, `while`, `with`, `yield`), Keyword, nil}, @@ -258,5 +262,5 @@ var Crystal = internal.Register(MustNewLexer( {`[\\#<>]`, LiteralStringRegex, nil}, {`[^\\#<>]+`, LiteralStringRegex, nil}, }, - }, -)) + } +} diff --git a/lexers/c/csharp.go b/lexers/c/csharp.go index a2781bd..725bcb8 100644 --- a/lexers/c/csharp.go +++ b/lexers/c/csharp.go @@ -6,7 +6,7 @@ import ( ) // CSharp lexer. -var CSharp = internal.Register(MustNewLexer( +var CSharp = internal.Register(MustNewLazyLexer( &Config{ Name: "C#", Aliases: []string{"csharp", "c#"}, @@ -15,7 +15,11 @@ var CSharp = internal.Register(MustNewLexer( DotAll: true, EnsureNL: true, }, - Rules{ + cSharpRules, +)) + +func cSharpRules() Rules { + return Rules{ "root": { {`^\s*\[.*?\]`, NameAttribute, nil}, {`[^\S\n]+`, Text, nil}, @@ -47,5 +51,5 @@ var CSharp = internal.Register(MustNewLexer( {`(?=\()`, Text, Pop(1)}, {`(@?[_a-zA-Z]\w*|\.)+`, NameNamespace, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/c/css.go b/lexers/c/css.go index 78251b7..9f3a01d 100644 --- a/lexers/c/css.go +++ b/lexers/c/css.go @@ -6,14 +6,18 @@ import ( ) // CSS lexer. -var CSS = internal.Register(MustNewLexer( +var CSS = internal.Register(MustNewLazyLexer( &Config{ Name: "CSS", Aliases: []string{"css"}, Filenames: []string{"*.css"}, MimeTypes: []string{"text/css"}, }, - Rules{ + cssRules, +)) + +func cssRules() Rules { + return Rules{ "root": { Include("basics"), }, @@ -113,5 +117,5 @@ var CSS = internal.Register(MustNewLexer( {`%`, KeywordType, nil}, Default(Pop(1)), }, - }, -)) + } +} diff --git a/lexers/c/cython.go b/lexers/c/cython.go index 701e2b7..0cce204 100644 --- a/lexers/c/cython.go +++ b/lexers/c/cython.go @@ -6,14 +6,18 @@ import ( ) // Cython lexer. -var Cython = internal.Register(MustNewLexer( +var Cython = internal.Register(MustNewLazyLexer( &Config{ Name: "Cython", Aliases: []string{"cython", "pyx", "pyrex"}, Filenames: []string{"*.pyx", "*.pxd", "*.pxi"}, MimeTypes: []string{"text/x-cython", "application/x-cython"}, }, - Rules{ + cythonRules, +)) + +func cythonRules() Rules { + return Rules{ "root": { {`\n`, Text, nil}, {`^(\s*)("""(?:.|\n)*?""")`, ByGroups(Text, LiteralStringDoc), nil}, @@ -131,5 +135,5 @@ var Cython = internal.Register(MustNewLexer( Include("strings"), Include("nl"), }, - }, -)) + } +} diff --git a/lexers/circular/php.go b/lexers/circular/php.go index 9954589..7e207a9 100644 --- a/lexers/circular/php.go +++ b/lexers/circular/php.go @@ -6,7 +6,7 @@ import ( ) // PHP lexer for pure PHP code (not embedded in HTML). -var PHP = internal.Register(MustNewLexer( +var PHP = internal.Register(MustNewLazyLexer( &Config{ Name: "PHP", Aliases: []string{"php", "php3", "php4", "php5"}, @@ -16,65 +16,71 @@ var PHP = internal.Register(MustNewLexer( CaseInsensitive: true, EnsureNL: true, }, - phpCommonRules.Rename("php", "root"), + phpRules, )) -var phpCommonRules = Rules{ - "php": { - {`\?>`, CommentPreproc, Pop(1)}, - {`(<<<)([\'"]?)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)(\2\n.*?\n\s*)(\3)(;?)(\n)`, ByGroups(LiteralString, LiteralString, LiteralStringDelimiter, LiteralString, LiteralStringDelimiter, Punctuation, Text), nil}, - {`\s+`, Text, nil}, - {`#.*?\n`, CommentSingle, nil}, - {`//.*?\n`, CommentSingle, nil}, - {`/\*\*/`, CommentMultiline, nil}, - {`/\*\*.*?\*/`, LiteralStringDoc, nil}, - {`/\*.*?\*/`, CommentMultiline, nil}, - {`(->|::)(\s*)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)`, ByGroups(Operator, Text, NameAttribute), nil}, - {`[~!%^&*+=|:.<>/@-]+`, Operator, nil}, - {`\?`, Operator, nil}, - {`[\[\]{}();,]+`, Punctuation, nil}, - {`(class)(\s+)`, ByGroups(Keyword, Text), Push("classname")}, - {`(function)(\s*)(?=\()`, ByGroups(Keyword, Text), nil}, - {`(function)(\s+)(&?)(\s*)`, ByGroups(Keyword, Text, Operator, Text), Push("functionname")}, - {`(const)(\s+)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)`, ByGroups(Keyword, Text, NameConstant), nil}, - {`(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|FALSE|print|for|require|continue|foreach|require_once|declare|return|default|static|do|switch|die|stdClass|echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|virtual|endfor|include_once|while|endforeach|global|endif|list|endswitch|new|endwhile|not|array|E_ALL|NULL|final|php_user_filter|interface|implements|public|private|protected|abstract|clone|try|catch|throw|this|use|namespace|trait|yield|finally)\b`, Keyword, nil}, - {`(true|false|null)\b`, KeywordConstant, nil}, - Include("magicconstants"), - {`\$\{\$+(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*\}`, NameVariable, nil}, - {`\$+(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*`, NameVariable, nil}, - {`(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*`, NameOther, nil}, - {`(\d+\.\d*|\d*\.\d+)(e[+-]?[0-9]+)?`, LiteralNumberFloat, nil}, - {`\d+e[+-]?[0-9]+`, LiteralNumberFloat, nil}, - {`0[0-7]+`, LiteralNumberOct, nil}, - {`0x[a-f0-9]+`, LiteralNumberHex, nil}, - {`[\d_]+`, LiteralNumberInteger, nil}, - {`0b[01]+`, LiteralNumberBin, nil}, - {`'([^'\\]*(?:\\.[^'\\]*)*)'`, LiteralStringSingle, nil}, - {"`([^`\\\\]*(?:\\\\.[^`\\\\]*)*)`", LiteralStringBacktick, nil}, - {`"`, LiteralStringDouble, Push("string")}, - }, - "magicfuncs": { - {Words(``, `\b`, `__construct`, `__destruct`, `__call`, `__callStatic`, `__get`, `__set`, `__isset`, `__unset`, `__sleep`, `__wakeup`, `__toString`, `__invoke`, `__set_state`, `__clone`, `__debugInfo`), NameFunctionMagic, nil}, - }, - "magicconstants": { - {Words(``, `\b`, `__LINE__`, `__FILE__`, `__DIR__`, `__FUNCTION__`, `__CLASS__`, `__TRAIT__`, `__METHOD__`, `__NAMESPACE__`), NameConstant, nil}, - }, - "classname": { - {`(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*`, NameClass, Pop(1)}, - }, - "functionname": { - Include("magicfuncs"), - {`(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*`, NameFunction, Pop(1)}, - Default(Pop(1)), - }, - "string": { - {`"`, LiteralStringDouble, Pop(1)}, - {`[^{$"\\]+`, LiteralStringDouble, nil}, - {`\\([nrt"$\\]|[0-7]{1,3}|x[0-9a-f]{1,2})`, LiteralStringEscape, nil}, - {`\$(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*(\[\S+?\]|->(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)?`, LiteralStringInterpol, nil}, - {`(\{\$\{)(.*?)(\}\})`, ByGroups(LiteralStringInterpol, UsingSelf("root"), LiteralStringInterpol), nil}, - {`(\{)(\$.*?)(\})`, ByGroups(LiteralStringInterpol, UsingSelf("root"), LiteralStringInterpol), nil}, - {`(\$\{)(\S+)(\})`, ByGroups(LiteralStringInterpol, NameVariable, LiteralStringInterpol), nil}, - {`[${\\]`, LiteralStringDouble, nil}, - }, +func phpRules() Rules { + return phpCommonRules().Rename("php", "root") +} + +func phpCommonRules() Rules { + return Rules{ + "php": { + {`\?>`, CommentPreproc, Pop(1)}, + {`(<<<)([\'"]?)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)(\2\n.*?\n\s*)(\3)(;?)(\n)`, ByGroups(LiteralString, LiteralString, LiteralStringDelimiter, LiteralString, LiteralStringDelimiter, Punctuation, Text), nil}, + {`\s+`, Text, nil}, + {`#.*?\n`, CommentSingle, nil}, + {`//.*?\n`, CommentSingle, nil}, + {`/\*\*/`, CommentMultiline, nil}, + {`/\*\*.*?\*/`, LiteralStringDoc, nil}, + {`/\*.*?\*/`, CommentMultiline, nil}, + {`(->|::)(\s*)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)`, ByGroups(Operator, Text, NameAttribute), nil}, + {`[~!%^&*+=|:.<>/@-]+`, Operator, nil}, + {`\?`, Operator, nil}, + {`[\[\]{}();,]+`, Punctuation, nil}, + {`(class)(\s+)`, ByGroups(Keyword, Text), Push("classname")}, + {`(function)(\s*)(?=\()`, ByGroups(Keyword, Text), nil}, + {`(function)(\s+)(&?)(\s*)`, ByGroups(Keyword, Text, Operator, Text), Push("functionname")}, + {`(const)(\s+)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)`, ByGroups(Keyword, Text, NameConstant), nil}, + {`(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|FALSE|print|for|require|continue|foreach|require_once|declare|return|default|static|do|switch|die|stdClass|echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|virtual|endfor|include_once|while|endforeach|global|endif|list|endswitch|new|endwhile|not|array|E_ALL|NULL|final|php_user_filter|interface|implements|public|private|protected|abstract|clone|try|catch|throw|this|use|namespace|trait|yield|finally)\b`, Keyword, nil}, + {`(true|false|null)\b`, KeywordConstant, nil}, + Include("magicconstants"), + {`\$\{\$+(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*\}`, NameVariable, nil}, + {`\$+(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*`, NameVariable, nil}, + {`(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*`, NameOther, nil}, + {`(\d+\.\d*|\d*\.\d+)(e[+-]?[0-9]+)?`, LiteralNumberFloat, nil}, + {`\d+e[+-]?[0-9]+`, LiteralNumberFloat, nil}, + {`0[0-7]+`, LiteralNumberOct, nil}, + {`0x[a-f0-9]+`, LiteralNumberHex, nil}, + {`[\d_]+`, LiteralNumberInteger, nil}, + {`0b[01]+`, LiteralNumberBin, nil}, + {`'([^'\\]*(?:\\.[^'\\]*)*)'`, LiteralStringSingle, nil}, + {"`([^`\\\\]*(?:\\\\.[^`\\\\]*)*)`", LiteralStringBacktick, nil}, + {`"`, LiteralStringDouble, Push("string")}, + }, + "magicfuncs": { + {Words(``, `\b`, `__construct`, `__destruct`, `__call`, `__callStatic`, `__get`, `__set`, `__isset`, `__unset`, `__sleep`, `__wakeup`, `__toString`, `__invoke`, `__set_state`, `__clone`, `__debugInfo`), NameFunctionMagic, nil}, + }, + "magicconstants": { + {Words(``, `\b`, `__LINE__`, `__FILE__`, `__DIR__`, `__FUNCTION__`, `__CLASS__`, `__TRAIT__`, `__METHOD__`, `__NAMESPACE__`), NameConstant, nil}, + }, + "classname": { + {`(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*`, NameClass, Pop(1)}, + }, + "functionname": { + Include("magicfuncs"), + {`(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*`, NameFunction, Pop(1)}, + Default(Pop(1)), + }, + "string": { + {`"`, LiteralStringDouble, Pop(1)}, + {`[^{$"\\]+`, LiteralStringDouble, nil}, + {`\\([nrt"$\\]|[0-7]{1,3}|x[0-9a-f]{1,2})`, LiteralStringEscape, nil}, + {`\$(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*(\[\S+?\]|->(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w]|[^\x00-\x7f])*)?`, LiteralStringInterpol, nil}, + {`(\{\$\{)(.*?)(\}\})`, ByGroups(LiteralStringInterpol, UsingSelf("root"), LiteralStringInterpol), nil}, + {`(\{)(\$.*?)(\})`, ByGroups(LiteralStringInterpol, UsingSelf("root"), LiteralStringInterpol), nil}, + {`(\$\{)(\S+)(\})`, ByGroups(LiteralStringInterpol, NameVariable, LiteralStringInterpol), nil}, + {`[${\\]`, LiteralStringDouble, nil}, + }, + } } diff --git a/lexers/circular/phtml.go b/lexers/circular/phtml.go index b9bffd3..f0824b5 100644 --- a/lexers/circular/phtml.go +++ b/lexers/circular/phtml.go @@ -9,7 +9,7 @@ import ( ) // PHTML lexer is PHP in HTML. -var PHTML = internal.Register(DelegatingLexer(h.HTML, MustNewLexer( +var PHTML = internal.Register(DelegatingLexer(h.HTML, MustNewLazyLexer( &Config{ Name: "PHTML", Aliases: []string{"phtml"}, @@ -19,16 +19,20 @@ var PHTML = internal.Register(DelegatingLexer(h.HTML, MustNewLexer( CaseInsensitive: true, EnsureNL: true, }, - Rules{ - "root": { - {`<\?(php)?`, CommentPreproc, Push("php")}, - {`[^<]+`, Other, nil}, - {`<`, Other, nil}, - }, - }.Merge(phpCommonRules), + phtmlRules, ).SetAnalyser(func(text string) float32 { if strings.Contains(text, "\s|()?+*,]+`, NameAttribute, nil}, {`>`, Keyword, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/e/ebnf.go b/lexers/e/ebnf.go index 42a3a37..5ccdd38 100644 --- a/lexers/e/ebnf.go +++ b/lexers/e/ebnf.go @@ -6,14 +6,18 @@ import ( ) // Ebnf lexer. -var Ebnf = internal.Register(MustNewLexer( +var Ebnf = internal.Register(MustNewLazyLexer( &Config{ Name: "EBNF", Aliases: []string{"ebnf"}, Filenames: []string{"*.ebnf"}, MimeTypes: []string{"text/x-ebnf"}, }, - Rules{ + ebnfRules, +)) + +func ebnfRules() Rules { + return Rules{ "root": { Include("whitespace"), Include("comment_start"), @@ -47,5 +51,5 @@ var Ebnf = internal.Register(MustNewLexer( "identifier": { {`([a-zA-Z][\w \-]*)`, Keyword, nil}, }, - }, -)) + } +} diff --git a/lexers/e/elixir.go b/lexers/e/elixir.go index 11dc844..f283f84 100644 --- a/lexers/e/elixir.go +++ b/lexers/e/elixir.go @@ -6,14 +6,18 @@ import ( ) // Elixir lexer. -var Elixir = internal.Register(MustNewLexer( +var Elixir = internal.Register(MustNewLazyLexer( &Config{ Name: "Elixir", Aliases: []string{"elixir", "ex", "exs"}, Filenames: []string{"*.ex", "*.exs"}, MimeTypes: []string{"text/x-elixir"}, }, - Rules{ + elixirRules, +)) + +func elixirRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`#.*$`, CommentSingle, nil}, @@ -273,5 +277,5 @@ var Elixir = internal.Register(MustNewLexer( {`\\.`, LiteralStringOther, nil}, {`'[a-zA-Z]*`, LiteralStringOther, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/e/elm.go b/lexers/e/elm.go index a71c627..0fb6689 100644 --- a/lexers/e/elm.go +++ b/lexers/e/elm.go @@ -6,14 +6,18 @@ import ( ) // Elm lexer. -var Elm = internal.Register(MustNewLexer( +var Elm = internal.Register(MustNewLazyLexer( &Config{ Name: "Elm", Aliases: []string{"elm"}, Filenames: []string{"*.elm"}, MimeTypes: []string{"text/x-elm"}, }, - Rules{ + elmRules, +)) + +func elmRules() Rules { + return Rules{ "root": { {`\{-`, CommentMultiline, Push("comment")}, {`--.*`, CommentSingle, nil}, @@ -55,5 +59,5 @@ var Elm = internal.Register(MustNewLexer( {`\|\]`, NameEntity, Pop(1)}, {`.*\n`, NameEntity, nil}, }, - }, -)) + } +} diff --git a/lexers/e/emacs.go b/lexers/e/emacs.go index 78ffda1..51c4910 100644 --- a/lexers/e/emacs.go +++ b/lexers/e/emacs.go @@ -522,14 +522,24 @@ var ( ) // EmacsLisp lexer. -var EmacsLisp = internal.Register(TypeRemappingLexer(MustNewLexer( +var EmacsLisp = internal.Register(TypeRemappingLexer(MustNewLazyLexer( &Config{ Name: "EmacsLisp", Aliases: []string{"emacs", "elisp", "emacs-lisp"}, Filenames: []string{"*.el"}, MimeTypes: []string{"text/x-elisp", "application/x-elisp"}, }, - Rules{ + emacsLispRules, +), TypeMapping{ + {NameVariable, NameFunction, emacsBuiltinFunction}, + {NameVariable, NameBuiltin, emacsSpecialForms}, + {NameVariable, NameException, emacsErrorKeywords}, + {NameVariable, NameBuiltin, append(emacsBuiltinFunctionHighlighted, emacsMacros...)}, + {NameVariable, KeywordPseudo, emacsLambdaListKeywords}, +})) + +func emacsLispRules() Rules { + return Rules{ "root": { Default(Push("body")), }, @@ -572,11 +582,5 @@ var EmacsLisp = internal.Register(TypeRemappingLexer(MustNewLexer( {`\\\n`, LiteralString, nil}, {`"`, LiteralString, Pop(1)}, }, - }, -), TypeMapping{ - {NameVariable, NameFunction, emacsBuiltinFunction}, - {NameVariable, NameBuiltin, emacsSpecialForms}, - {NameVariable, NameException, emacsErrorKeywords}, - {NameVariable, NameBuiltin, append(emacsBuiltinFunctionHighlighted, emacsMacros...)}, - {NameVariable, KeywordPseudo, emacsLambdaListKeywords}, -})) + } +} diff --git a/lexers/e/erlang.go b/lexers/e/erlang.go index 63cd59a..5f5c9ca 100644 --- a/lexers/e/erlang.go +++ b/lexers/e/erlang.go @@ -6,14 +6,18 @@ import ( ) // Erlang lexer. -var Erlang = internal.Register(MustNewLexer( +var Erlang = internal.Register(MustNewLazyLexer( &Config{ Name: "Erlang", Aliases: []string{"erlang"}, Filenames: []string{"*.erl", "*.hrl", "*.es", "*.escript"}, MimeTypes: []string{"text/x-erlang"}, }, - Rules{ + erlangRules, +)) + +func erlangRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`%.*\n`, Comment, nil}, @@ -62,5 +66,5 @@ var Erlang = internal.Register(MustNewLexer( {`,`, Punctuation, Pop(1)}, {`(?=\})`, Punctuation, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/f/factor.go b/lexers/f/factor.go index 26c0d56..d88beb2 100644 --- a/lexers/f/factor.go +++ b/lexers/f/factor.go @@ -6,14 +6,18 @@ import ( ) // Factor lexer. -var Factor = internal.Register(MustNewLexer( +var Factor = internal.Register(MustNewLazyLexer( &Config{ Name: "Factor", Aliases: []string{"factor"}, Filenames: []string{"*.factor"}, MimeTypes: []string{"text/x-factor"}, }, - Rules{ + factorRules, +)) + +func factorRules() Rules { + return Rules{ "root": { {`#!.*$`, CommentPreproc, nil}, Default(Push("base")), @@ -111,5 +115,5 @@ var Factor = internal.Register(MustNewLexer( {`;\s`, Keyword, Pop(1)}, {`\S+`, NameFunction, nil}, }, - }, -)) + } +} diff --git a/lexers/f/fish.go b/lexers/f/fish.go index 185fc92..3678cfa 100644 --- a/lexers/f/fish.go +++ b/lexers/f/fish.go @@ -6,14 +6,18 @@ import ( ) // Fish lexer. -var Fish = internal.Register(MustNewLexer( +var Fish = internal.Register(MustNewLazyLexer( &Config{ Name: "Fish", Aliases: []string{"fish", "fishshell"}, Filenames: []string{"*.fish", "*.load"}, MimeTypes: []string{"application/x-fish"}, }, - Rules{ + fishRules, +)) + +func fishRules() Rules { + return Rules{ "root": { Include("basic"), Include("data"), @@ -61,5 +65,5 @@ var Fish = internal.Register(MustNewLexer( {`\d+`, LiteralNumber, nil}, Include("root"), }, - }, -)) + } +} diff --git a/lexers/f/forth.go b/lexers/f/forth.go index 47de636..8d66708 100644 --- a/lexers/f/forth.go +++ b/lexers/f/forth.go @@ -6,7 +6,7 @@ import ( ) // Forth lexer. -var Forth = internal.Register(MustNewLexer( +var Forth = internal.Register(MustNewLazyLexer( &Config{ Name: "Forth", Aliases: []string{"forth"}, @@ -14,7 +14,11 @@ var Forth = internal.Register(MustNewLexer( MimeTypes: []string{"application/x-forth"}, CaseInsensitive: true, }, - Rules{ + forthRules, +)) + +func forthRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`\\.*?\n`, CommentSingle, nil}, @@ -36,5 +40,5 @@ var Forth = internal.Register(MustNewLexer( "stringdef": { {`[^"]+`, LiteralString, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/f/fortran.go b/lexers/f/fortran.go index 6c57afa..af4a969 100644 --- a/lexers/f/fortran.go +++ b/lexers/f/fortran.go @@ -6,7 +6,7 @@ import ( ) // Fortran lexer. -var Fortran = internal.Register(MustNewLexer( +var Fortran = internal.Register(MustNewLazyLexer( &Config{ Name: "Fortran", Aliases: []string{"fortran"}, @@ -14,7 +14,11 @@ var Fortran = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-fortran"}, CaseInsensitive: true, }, - Rules{ + fortranRules, +)) + +func fortranRules() Rules { + return Rules{ "root": { {`^#.*\n`, CommentPreproc, nil}, {`!.*\n`, Comment, nil}, @@ -43,5 +47,5 @@ var Fortran = internal.Register(MustNewLexer( {`[+-]?\d*\.\d+([ed][-+]?\d+)?(_[a-z]\w+)?`, LiteralNumberFloat, nil}, {`[+-]?\d+\.\d*([ed][-+]?\d+)?(_[a-z]\w+)?`, LiteralNumberFloat, nil}, }, - }, -)) + } +} diff --git a/lexers/f/fsharp.go b/lexers/f/fsharp.go index d00f63d..44fced4 100644 --- a/lexers/f/fsharp.go +++ b/lexers/f/fsharp.go @@ -6,14 +6,18 @@ import ( ) // Fsharp lexer. -var Fsharp = internal.Register(MustNewLexer( +var Fsharp = internal.Register(MustNewLazyLexer( &Config{ Name: "FSharp", Aliases: []string{"fsharp"}, Filenames: []string{"*.fs", "*.fsi"}, MimeTypes: []string{"text/x-fsharp"}, }, - Rules{ + fsharpRules, +)) + +func fsharpRules() Rules { + return Rules{ "escape-sequence": { {`\\[\\"\'ntbrafv]`, LiteralStringEscape, nil}, {`\\[0-9]{3}`, LiteralStringEscape, nil}, @@ -90,5 +94,5 @@ var Fsharp = internal.Register(MustNewLexer( {`"""B?`, LiteralString, Pop(1)}, {`"`, LiteralString, nil}, }, - }, -)) + } +} diff --git a/lexers/g/gas.go b/lexers/g/gas.go index a922806..1f733f6 100644 --- a/lexers/g/gas.go +++ b/lexers/g/gas.go @@ -6,14 +6,18 @@ import ( ) // Gas lexer. -var Gas = internal.Register(MustNewLexer( +var Gas = internal.Register(MustNewLazyLexer( &Config{ Name: "GAS", Aliases: []string{"gas", "asm"}, Filenames: []string{"*.s", "*.S"}, MimeTypes: []string{"text/x-gas"}, }, - Rules{ + gasRules, +)) + +func gasRules() Rules { + return Rules{ "root": { Include("whitespace"), {`(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+):`, NameLabel, nil}, @@ -51,5 +55,5 @@ var Gas = internal.Register(MustNewLexer( "punctuation": { {`[-*,.()\[\]!:]+`, Punctuation, nil}, }, - }, -)) + } +} diff --git a/lexers/g/gdscript.go b/lexers/g/gdscript.go index bfe3063..2b6af97 100644 --- a/lexers/g/gdscript.go +++ b/lexers/g/gdscript.go @@ -6,14 +6,18 @@ import ( ) // GDScript lexer. -var GDScript = internal.Register(MustNewLexer( +var GDScript = internal.Register(MustNewLazyLexer( &Config{ Name: "GDScript", Aliases: []string{"gdscript", "gd"}, Filenames: []string{"*.gd"}, MimeTypes: []string{"text/x-gdscript", "application/x-gdscript"}, }, - Rules{ + gdscriptRules, +)) + +func gdscriptRules() Rules { + return Rules{ "root": { {`\n`, Text, nil}, {`^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")`, ByGroups(Text, LiteralStringAffix, LiteralStringDoc), nil}, @@ -120,5 +124,5 @@ var GDScript = internal.Register(MustNewLexer( Include("strings-single"), {`\n`, LiteralStringSingle, nil}, }, - }, -)) + } +} diff --git a/lexers/g/genshi.go b/lexers/g/genshi.go index 0d3663a..dc4d4b1 100644 --- a/lexers/g/genshi.go +++ b/lexers/g/genshi.go @@ -7,14 +7,18 @@ import ( ) // Genshi Text lexer. -var GenshiText = internal.Register(MustNewLexer( +var GenshiText = internal.Register(MustNewLazyLexer( &Config{ Name: "Genshi Text", Aliases: []string{"genshitext"}, Filenames: []string{}, MimeTypes: []string{"application/x-genshi-text", "text/x-genshi"}, }, - Rules{ + genshiTextRules, +)) + +func genshiTextRules() Rules { + return Rules{ "root": { {`[^#$\s]+`, Other, nil}, {`^(\s*)(##.*)$`, ByGroups(Text, Comment), nil}, @@ -33,11 +37,11 @@ var GenshiText = internal.Register(MustNewLexer( {`(?)`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil}, - {`<\s*(script|style)\s*.*?>.*?<\s*/\1\s*>`, Other, nil}, - {`<\s*py:[a-zA-Z0-9]+`, NameTag, Push("pytag")}, - {`<\s*[a-zA-Z0-9:.]+`, NameTag, Push("tag")}, - Include("variable"), - {`[<$]`, Other, nil}, - }, - "pytag": { - {`\s+`, Text, nil}, - {`[\w:-]+\s*=`, NameAttribute, Push("pyattr")}, - {`/?\s*>`, NameTag, Pop(1)}, - }, - "pyattr": { - {`(")(.*?)(")`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)}, - {`(')(.*?)(')`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)}, - {`[^\s>]+`, LiteralString, Pop(1)}, - }, - "tag": { - {`\s+`, Text, nil}, - {`py:[\w-]+\s*=`, NameAttribute, Push("pyattr")}, - {`[\w:-]+\s*=`, NameAttribute, Push("attr")}, - {`/?\s*>`, NameTag, Pop(1)}, - }, - "attr": { - {`"`, LiteralString, Push("attr-dstring")}, - {`'`, LiteralString, Push("attr-sstring")}, - {`[^\s>]*`, LiteralString, Pop(1)}, - }, - "attr-dstring": { - {`"`, LiteralString, Pop(1)}, - Include("strings"), - {`'`, LiteralString, nil}, - }, - "attr-sstring": { - {`'`, LiteralString, Pop(1)}, - Include("strings"), - {`'`, LiteralString, nil}, - }, - "strings": { - {`[^"'$]+`, LiteralString, nil}, - Include("variable"), - }, - "variable": { - {`(?)`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil}, + {`<\s*(script|style)\s*.*?>.*?<\s*/\1\s*>`, Other, nil}, + {`<\s*py:[a-zA-Z0-9]+`, NameTag, Push("pytag")}, + {`<\s*[a-zA-Z0-9:.]+`, NameTag, Push("tag")}, + Include("variable"), + {`[<$]`, Other, nil}, + }, + "pytag": { + {`\s+`, Text, nil}, + {`[\w:-]+\s*=`, NameAttribute, Push("pyattr")}, + {`/?\s*>`, NameTag, Pop(1)}, + }, + "pyattr": { + {`(")(.*?)(")`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)}, + {`(')(.*?)(')`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)}, + {`[^\s>]+`, LiteralString, Pop(1)}, + }, + "tag": { + {`\s+`, Text, nil}, + {`py:[\w-]+\s*=`, NameAttribute, Push("pyattr")}, + {`[\w:-]+\s*=`, NameAttribute, Push("attr")}, + {`/?\s*>`, NameTag, Pop(1)}, + }, + "attr": { + {`"`, LiteralString, Push("attr-dstring")}, + {`'`, LiteralString, Push("attr-sstring")}, + {`[^\s>]*`, LiteralString, Pop(1)}, + }, + "attr-dstring": { + {`"`, LiteralString, Pop(1)}, + Include("strings"), + {`'`, LiteralString, nil}, + }, + "attr-sstring": { + {`'`, LiteralString, Pop(1)}, + Include("strings"), + {`'`, LiteralString, nil}, + }, + "strings": { + {`[^"'$]+`, LiteralString, nil}, + Include("variable"), + }, + "variable": { + {`(?=!()\[\]{}.,;:]`, Punctuation, nil}, {`[^\W\d]\w*`, NameOther, nil}, }, - }, -).SetAnalyser(func(text string) float32 { - if strings.Contains(text, "fmt.") && strings.Contains(text, "package ") { - return 0.5 } - if strings.Contains(text, "package ") { - return 0.1 - } - return 0.0 -})) - -var goTemplateRules = Rules{ - "root": { - {`{{(- )?/\*(.|\n)*?\*/( -)?}}`, CommentMultiline, nil}, - {`{{[-]?`, CommentPreproc, Push("template")}, - {`[^{]+`, Other, nil}, - {`{`, Other, nil}, - }, - "template": { - {`[-]?}}`, CommentPreproc, Pop(1)}, - {`(?=}})`, CommentPreproc, Pop(1)}, // Terminate the pipeline - {`\(`, Operator, Push("subexpression")}, - {`"(\\\\|\\"|[^"])*"`, LiteralString, nil}, - Include("expression"), - }, - "subexpression": { - {`\)`, Operator, Pop(1)}, - Include("expression"), - }, - "expression": { - {`\s+`, Whitespace, nil}, - {`\(`, Operator, Push("subexpression")}, - {`(range|if|else|while|with|template|end|true|false|nil|and|call|html|index|js|len|not|or|print|printf|println|urlquery|eq|ne|lt|le|gt|ge)\b`, Keyword, nil}, - {`\||:?=|,`, Operator, nil}, - {`[$]?[^\W\d]\w*`, NameOther, nil}, - {`[$]?\.(?:[^\W\d]\w*)?`, NameAttribute, nil}, - {`"(\\\\|\\"|[^"])*"`, LiteralString, nil}, - {`-?\d+i`, LiteralNumber, nil}, - {`-?\d+\.\d*([Ee][-+]\d+)?i`, LiteralNumber, nil}, - {`\.\d+([Ee][-+]\d+)?i`, LiteralNumber, nil}, - {`-?\d+[Ee][-+]\d+i`, LiteralNumber, nil}, - {`-?\d+(\.\d+[eE][+\-]?\d+|\.\d*|[eE][+\-]?\d+)`, LiteralNumberFloat, nil}, - {`-?\.\d+([eE][+\-]?\d+)?`, LiteralNumberFloat, nil}, - {`-?0[0-7]+`, LiteralNumberOct, nil}, - {`-?0[xX][0-9a-fA-F]+`, LiteralNumberHex, nil}, - {`-?(0|[1-9][0-9]*)`, LiteralNumberInteger, nil}, - {`'(\\['"\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])'`, LiteralStringChar, nil}, - {"`[^`]*`", LiteralString, nil}, - }, } -var GoHTMLTemplate = internal.Register(DelegatingLexer(h.HTML, MustNewLexer( +func goTemplateRules() Rules { + return Rules{ + "root": { + {`{{(- )?/\*(.|\n)*?\*/( -)?}}`, CommentMultiline, nil}, + {`{{[-]?`, CommentPreproc, Push("template")}, + {`[^{]+`, Other, nil}, + {`{`, Other, nil}, + }, + "template": { + {`[-]?}}`, CommentPreproc, Pop(1)}, + {`(?=}})`, CommentPreproc, Pop(1)}, // Terminate the pipeline + {`\(`, Operator, Push("subexpression")}, + {`"(\\\\|\\"|[^"])*"`, LiteralString, nil}, + Include("expression"), + }, + "subexpression": { + {`\)`, Operator, Pop(1)}, + Include("expression"), + }, + "expression": { + {`\s+`, Whitespace, nil}, + {`\(`, Operator, Push("subexpression")}, + {`(range|if|else|while|with|template|end|true|false|nil|and|call|html|index|js|len|not|or|print|printf|println|urlquery|eq|ne|lt|le|gt|ge)\b`, Keyword, nil}, + {`\||:?=|,`, Operator, nil}, + {`[$]?[^\W\d]\w*`, NameOther, nil}, + {`[$]?\.(?:[^\W\d]\w*)?`, NameAttribute, nil}, + {`"(\\\\|\\"|[^"])*"`, LiteralString, nil}, + {`-?\d+i`, LiteralNumber, nil}, + {`-?\d+\.\d*([Ee][-+]\d+)?i`, LiteralNumber, nil}, + {`\.\d+([Ee][-+]\d+)?i`, LiteralNumber, nil}, + {`-?\d+[Ee][-+]\d+i`, LiteralNumber, nil}, + {`-?\d+(\.\d+[eE][+\-]?\d+|\.\d*|[eE][+\-]?\d+)`, LiteralNumberFloat, nil}, + {`-?\.\d+([eE][+\-]?\d+)?`, LiteralNumberFloat, nil}, + {`-?0[0-7]+`, LiteralNumberOct, nil}, + {`-?0[xX][0-9a-fA-F]+`, LiteralNumberHex, nil}, + {`-?(0|[1-9][0-9]*)`, LiteralNumberInteger, nil}, + {`'(\\['"\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])'`, LiteralStringChar, nil}, + {"`[^`]*`", LiteralString, nil}, + }, + } +} + +var GoHTMLTemplate = internal.Register(DelegatingLexer(h.HTML, MustNewLazyLexer( &Config{ Name: "Go HTML Template", Aliases: []string{"go-html-template"}, @@ -106,7 +112,7 @@ var GoHTMLTemplate = internal.Register(DelegatingLexer(h.HTML, MustNewLexer( goTemplateRules, ))) -var GoTextTemplate = internal.Register(MustNewLexer( +var GoTextTemplate = internal.Register(MustNewLazyLexer( &Config{ Name: "Go Text Template", Aliases: []string{"go-text-template"}, diff --git a/lexers/g/graphql.go b/lexers/g/graphql.go index a57e693..7d465cd 100644 --- a/lexers/g/graphql.go +++ b/lexers/g/graphql.go @@ -6,13 +6,17 @@ import ( ) // Go lexer. -var Graphql = internal.Register(MustNewLexer( +var Graphql = internal.Register(MustNewLazyLexer( &Config{ Name: "GraphQL", Aliases: []string{"graphql", "graphqls", "gql"}, Filenames: []string{"*.graphql", "*.graphqls"}, }, - Rules{ + graphqlRules, +)) + +func graphqlRules() Rules { + return Rules{ "root": { {`(query|mutation|subscription|fragment|scalar|implements|interface|union|enum|input|type)`, KeywordDeclaration, Push("type")}, {`(on|extend|schema|directive|\.\.\.)`, KeywordDeclaration, nil}, @@ -41,5 +45,5 @@ var Graphql = internal.Register(MustNewLexer( {`[^\W\d]\w*`, NameClass, Pop(1)}, Include("root"), }, - }, -)) + } +} diff --git a/lexers/g/groovy.go b/lexers/g/groovy.go index a395415..8d37bd8 100644 --- a/lexers/g/groovy.go +++ b/lexers/g/groovy.go @@ -6,7 +6,7 @@ import ( ) // Groovy lexer. -var Groovy = internal.Register(MustNewLexer( +var Groovy = internal.Register(MustNewLazyLexer( &Config{ Name: "Groovy", Aliases: []string{"groovy"}, @@ -14,7 +14,11 @@ var Groovy = internal.Register(MustNewLexer( MimeTypes: []string{"text/x-groovy"}, DotAll: true, }, - Rules{ + groovyRules, +)) + +func groovyRules() Rules { + return Rules{ "root": { {`#!(.*?)$`, CommentPreproc, Push("base")}, Default(Push("base")), @@ -54,5 +58,5 @@ var Groovy = internal.Register(MustNewLexer( "import": { {`[\w.]+\*?`, NameNamespace, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/h/handlebars.go b/lexers/h/handlebars.go index fda7b34..d34ef3a 100644 --- a/lexers/h/handlebars.go +++ b/lexers/h/handlebars.go @@ -6,14 +6,18 @@ import ( ) // Handlebars lexer. -var Handlebars = internal.Register(MustNewLexer( +var Handlebars = internal.Register(MustNewLazyLexer( &Config{ Name: "Handlebars", Aliases: []string{"handlebars", "hbs"}, Filenames: []string{"*.handlebars", "*.hbs"}, MimeTypes: []string{}, }, - Rules{ + handlebarsRules, +)) + +func handlebarsRules() Rules { + return Rules{ "root": { {`[^{]+`, Other, nil}, {`\{\{!.*\}\}`, Comment, nil}, @@ -52,5 +56,5 @@ var Handlebars = internal.Register(MustNewLexer( {`:?'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil}, {`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil}, }, - }, -)) + } +} diff --git a/lexers/h/haskell.go b/lexers/h/haskell.go index b018eab..9780481 100644 --- a/lexers/h/haskell.go +++ b/lexers/h/haskell.go @@ -6,14 +6,18 @@ import ( ) // Haskell lexer. -var Haskell = internal.Register(MustNewLexer( +var Haskell = internal.Register(MustNewLazyLexer( &Config{ Name: "Haskell", Aliases: []string{"haskell", "hs"}, Filenames: []string{"*.hs"}, MimeTypes: []string{"text/x-haskell"}, }, - Rules{ + haskellRules, +)) + +func haskellRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`--(?![!#$%&*+./<=>?@^|_~:\\]).*?$`, CommentSingle, nil}, @@ -95,5 +99,5 @@ var Haskell = internal.Register(MustNewLexer( {`\d+`, LiteralStringEscape, Pop(1)}, {`\s+\\`, LiteralStringEscape, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/h/haxe.go b/lexers/h/haxe.go index 5958543..cc8c693 100644 --- a/lexers/h/haxe.go +++ b/lexers/h/haxe.go @@ -6,7 +6,7 @@ import ( ) // Haxe lexer. -var Haxe = internal.Register(MustNewLexer( +var Haxe = internal.Register(MustNewLazyLexer( &Config{ Name: "Haxe", Aliases: []string{"hx", "haxe", "hxsl"}, @@ -14,7 +14,11 @@ var Haxe = internal.Register(MustNewLexer( MimeTypes: []string{"text/haxe", "text/x-haxe", "text/x-hx"}, DotAll: true, }, - Rules{ + haxeRules, +)) + +func haxeRules() Rules { + return Rules{ "root": { Include("spaces"), Include("meta"), @@ -609,8 +613,8 @@ var Haxe = internal.Register(MustNewLexer( {`\}`, Punctuation, Pop(1)}, {`,`, Punctuation, Push("#pop", "object")}, }, - }, -)) + } +} func haxePreProcMutator(state *LexerState) error { stack, ok := state.Get("haxe-pre-proc").([][]string) diff --git a/lexers/h/hcl.go b/lexers/h/hcl.go index ce7064b..7206fba 100644 --- a/lexers/h/hcl.go +++ b/lexers/h/hcl.go @@ -6,14 +6,18 @@ import ( ) // HCL lexer. -var HCL = internal.Register(MustNewLexer( +var HCL = internal.Register(MustNewLazyLexer( &Config{ Name: "HCL", Aliases: []string{"hcl"}, Filenames: []string{"*.hcl"}, MimeTypes: []string{"application/x-hcl"}, }, - Rules{ + hclRules, +)) + +func hclRules() Rules { + return Rules{ "root": { Include("string"), Include("punctuation"), @@ -65,5 +69,5 @@ var HCL = internal.Register(MustNewLexer( {`\s+`, Text, nil}, {`\\\n`, Text, nil}, }, - }, -)) + } +} diff --git a/lexers/h/hexdump.go b/lexers/h/hexdump.go index 8b7e7bd..0893537 100644 --- a/lexers/h/hexdump.go +++ b/lexers/h/hexdump.go @@ -6,14 +6,18 @@ import ( ) // Hexdump lexer. -var Hexdump = internal.Register(MustNewLexer( +var Hexdump = internal.Register(MustNewLazyLexer( &Config{ Name: "Hexdump", Aliases: []string{"hexdump"}, Filenames: []string{}, MimeTypes: []string{}, }, - Rules{ + hexdumpRules, +)) + +func hexdumpRules() Rules { + return Rules{ "root": { {`\n`, Text, nil}, Include("offset"), @@ -63,5 +67,5 @@ var Hexdump = internal.Register(MustNewLexer( {`\s`, Text, nil}, {`^\*`, Punctuation, nil}, }, - }, -)) + } +} diff --git a/lexers/h/hlb.go b/lexers/h/hlb.go index 3b32e75..6c5f637 100644 --- a/lexers/h/hlb.go +++ b/lexers/h/hlb.go @@ -6,14 +6,18 @@ import ( ) // HLB lexer. -var HLB = internal.Register(MustNewLexer( +var HLB = internal.Register(MustNewLazyLexer( &Config{ Name: "HLB", Aliases: []string{"hlb"}, Filenames: []string{"*.hlb"}, MimeTypes: []string{}, }, - Rules{ + hlbRules, +)) + +func hlbRules() Rules { + return Rules{ "root": { {`(#.*)`, ByGroups(CommentSingle), nil}, {`((\b(0(b|B|o|O|x|X)[a-fA-F0-9]+)\b)|(\b(0|[1-9][0-9]*)\b))`, ByGroups(LiteralNumber), nil}, @@ -50,5 +54,5 @@ var HLB = internal.Register(MustNewLexer( {`(\n|\r|\r\n)`, Text, nil}, {`.`, Text, nil}, }, - }, -)) + } +} diff --git a/lexers/h/html.go b/lexers/h/html.go index 07fc27e..b9ca1e1 100644 --- a/lexers/h/html.go +++ b/lexers/h/html.go @@ -8,7 +8,7 @@ import ( ) // HTML lexer. -var HTML = internal.Register(MustNewLexer( +var HTML = internal.Register(MustNewLazyLexer( &Config{ Name: "HTML", Aliases: []string{"html"}, @@ -18,7 +18,11 @@ var HTML = internal.Register(MustNewLexer( DotAll: true, CaseInsensitive: true, }, - Rules{ + htmlRules, +)) + +func htmlRules() Rules { + return Rules{ "root": { {`[^<&]+`, Text, nil}, {`&\S*?;`, NameEntity, nil}, @@ -55,5 +59,5 @@ var HTML = internal.Register(MustNewLexer( {`'.*?'`, LiteralString, Pop(1)}, {`[^\s>]+`, LiteralString, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/h/http.go b/lexers/h/http.go index 135ec73..1a0c138 100644 --- a/lexers/h/http.go +++ b/lexers/h/http.go @@ -8,7 +8,7 @@ import ( ) // HTTP lexer. -var HTTP = internal.Register(httpBodyContentTypeLexer(MustNewLexer( +var HTTP = internal.Register(httpBodyContentTypeLexer(MustNewLazyLexer( &Config{ Name: "HTTP", Aliases: []string{"http"}, @@ -17,7 +17,11 @@ var HTTP = internal.Register(httpBodyContentTypeLexer(MustNewLexer( NotMultiline: true, DotAll: true, }, - Rules{ + httpRules, +))) + +func httpRules() Rules { + return Rules{ "root": { {`(GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE|PATCH|CONNECT)( +)([^ ]+)( +)(HTTP)(/)([12]\.[01])(\r?\n|\Z)`, ByGroups(NameFunction, Text, NameNamespace, Text, KeywordReserved, Operator, LiteralNumber, Text), Push("headers")}, {`(HTTP)(/)([12]\.[01])( +)(\d{3})( +)([^\r\n]+)(\r?\n|\Z)`, ByGroups(KeywordReserved, Operator, LiteralNumber, Text, LiteralNumber, Text, NameException, Text), Push("headers")}, @@ -30,8 +34,8 @@ var HTTP = internal.Register(httpBodyContentTypeLexer(MustNewLexer( "content": { {`.+`, EmitterFunc(httpContentBlock), nil}, }, - }, -))) + } +} func httpContentBlock(groups []string, lexer Lexer) Iterator { tokens := []Token{ diff --git a/lexers/h/hy.go b/lexers/h/hy.go index 17385e8..7a07897 100644 --- a/lexers/h/hy.go +++ b/lexers/h/hy.go @@ -6,14 +6,18 @@ import ( ) // Hy lexer. -var Hy = internal.Register(MustNewLexer( +var Hy = internal.Register(MustNewLazyLexer( &Config{ Name: "Hy", Aliases: []string{"hylang"}, Filenames: []string{"*.hy"}, MimeTypes: []string{"text/x-hy", "application/x-hy"}, }, - Rules{ + hyRules, +)) + +func hyRules() Rules { + return Rules{ "root": { {`;.*$`, CommentSingle, nil}, {`[,\s]+`, Text, nil}, @@ -47,5 +51,5 @@ var Hy = internal.Register(MustNewLexer( {`(??@^|_~:\\]).*?)$`, ByGroups(Text, CommentSingle), nil}, @@ -76,5 +80,5 @@ var Idris = internal.Register(MustNewLexer( {`\d+`, LiteralStringEscape, Pop(1)}, {`\s+\\`, LiteralStringEscape, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/i/igor.go b/lexers/i/igor.go index d704a4f..bbb1d72 100644 --- a/lexers/i/igor.go +++ b/lexers/i/igor.go @@ -6,7 +6,7 @@ import ( ) // Igor lexer. -var Igor = internal.Register(MustNewLexer( +var Igor = internal.Register(MustNewLazyLexer( &Config{ Name: "Igor", Aliases: []string{"igor", "igorpro"}, @@ -14,7 +14,11 @@ var Igor = internal.Register(MustNewLexer( MimeTypes: []string{"text/ipf"}, CaseInsensitive: true, }, - Rules{ + igorRules, +)) + +func igorRules() Rules { + return Rules{ "root": { {`//.*$`, CommentSingle, nil}, {`"([^"\\]|\\.)*"`, LiteralString, nil}, @@ -28,5 +32,5 @@ var Igor = internal.Register(MustNewLexer( {`.`, Text, nil}, {`\n|\r`, Text, nil}, }, - }, -)) + } +} diff --git a/lexers/i/ini.go b/lexers/i/ini.go index e57f865..46b2ce2 100644 --- a/lexers/i/ini.go +++ b/lexers/i/ini.go @@ -6,14 +6,18 @@ import ( ) // Ini lexer. -var Ini = internal.Register(MustNewLexer( +var Ini = internal.Register(MustNewLazyLexer( &Config{ Name: "INI", Aliases: []string{"ini", "cfg", "dosini"}, Filenames: []string{"*.ini", "*.cfg", "*.inf", ".gitconfig", ".editorconfig"}, MimeTypes: []string{"text/x-ini", "text/inf"}, }, - Rules{ + iniRules, +)) + +func iniRules() Rules { + return Rules{ "root": { {`\s+`, Text, nil}, {`[;#].*`, CommentSingle, nil}, @@ -21,5 +25,5 @@ var Ini = internal.Register(MustNewLexer( {`(.*?)([ \t]*)(=)([ \t]*)(.*(?:\n[ \t].+)*)`, ByGroups(NameAttribute, Text, Operator, Text, LiteralString), nil}, {`(.+?)$`, NameAttribute, nil}, }, - }, -)) + } +} diff --git a/lexers/i/io.go b/lexers/i/io.go index 840feea..8b2e53a 100644 --- a/lexers/i/io.go +++ b/lexers/i/io.go @@ -6,14 +6,18 @@ import ( ) // Io lexer. -var Io = internal.Register(MustNewLexer( +var Io = internal.Register(MustNewLazyLexer( &Config{ Name: "Io", Aliases: []string{"io"}, Filenames: []string{"*.io"}, MimeTypes: []string{"text/x-iosrc"}, }, - Rules{ + ioRules, +)) + +func ioRules() Rules { + return Rules{ "root": { {`\n`, Text, nil}, {`\s+`, Text, nil}, @@ -36,5 +40,5 @@ var Io = internal.Register(MustNewLexer( {`\+/`, CommentMultiline, Pop(1)}, {`[+/]`, CommentMultiline, nil}, }, - }, -)) + } +} diff --git a/lexers/internal/api.go b/lexers/internal/api.go index 08ec6ff..c10eb3a 100644 --- a/lexers/internal/api.go +++ b/lexers/internal/api.go @@ -146,16 +146,19 @@ func Register(lexer chroma.Lexer) chroma.Lexer { return lexer } -// Used for the fallback lexer as well as the explicit plaintext lexer -var PlaintextRules = chroma.Rules{ - "root": []chroma.Rule{ - {`.+`, chroma.Text, nil}, - {`\n`, chroma.Text, nil}, - }, +// PlaintextRules is used for the fallback lexer as well as the explicit +// plaintext lexer. +func PlaintextRules() chroma.Rules { + return chroma.Rules{ + "root": []chroma.Rule{ + {`.+`, chroma.Text, nil}, + {`\n`, chroma.Text, nil}, + }, + } } // Fallback lexer if no other is found. -var Fallback chroma.Lexer = chroma.MustNewLexer(&chroma.Config{ +var Fallback chroma.Lexer = chroma.MustNewLazyLexer(&chroma.Config{ Name: "fallback", Filenames: []string{"*"}, }, PlaintextRules) diff --git a/lexers/j/j.go b/lexers/j/j.go index 686e53b..9a2a4e3 100644 --- a/lexers/j/j.go +++ b/lexers/j/j.go @@ -6,14 +6,18 @@ import ( ) // J lexer. -var J = internal.Register(MustNewLexer( +var J = internal.Register(MustNewLazyLexer( &Config{ Name: "J", Aliases: []string{"j"}, Filenames: []string{"*.ijs"}, MimeTypes: []string{"text/x-j"}, }, - Rules{ + jRules, +)) + +func jRules() Rules { + return Rules{ "root": { {`#!.*$`, CommentPreproc, nil}, {`NB\..*`, CommentSingle, nil}, @@ -69,5 +73,5 @@ var J = internal.Register(MustNewLexer( {`''`, LiteralString, nil}, {`'`, LiteralString, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/j/java.go b/lexers/j/java.go index e9204a3..48a9d9f 100644 --- a/lexers/j/java.go +++ b/lexers/j/java.go @@ -6,7 +6,7 @@ import ( ) // Java lexer. -var Java = internal.Register(MustNewLexer( +var Java = internal.Register(MustNewLazyLexer( &Config{ Name: "Java", Aliases: []string{"java"}, @@ -15,7 +15,11 @@ var Java = internal.Register(MustNewLexer( DotAll: true, EnsureNL: true, }, - Rules{ + javaRules, +)) + +func javaRules() Rules { + return Rules{ "root": { {`[^\S\n]+`, Text, nil}, {`//.*?\n`, CommentSingle, nil}, @@ -48,5 +52,5 @@ var Java = internal.Register(MustNewLexer( "import": { {`[\w.]+\*?`, NameNamespace, Pop(1)}, }, - }, -)) + } +} diff --git a/lexers/j/json.go b/lexers/j/json.go index 203adc4..9a4a3ee 100644 --- a/lexers/j/json.go +++ b/lexers/j/json.go @@ -6,7 +6,7 @@ import ( ) // JSON lexer. -var JSON = internal.Register(MustNewLexer( +var JSON = internal.Register(MustNewLazyLexer( &Config{ Name: "JSON", Aliases: []string{"json"}, @@ -15,7 +15,11 @@ var JSON = internal.Register(MustNewLexer( NotMultiline: true, DotAll: true, }, - Rules{ + jsonRules, +)) + +func jsonRules() Rules { + return Rules{ "whitespace": { {`\s+`, Text, nil}, }, @@ -51,5 +55,5 @@ var JSON = internal.Register(MustNewLexer( "root": { Include("value"), }, - }, -)) + } +} diff --git a/lexers/j/jsx.go b/lexers/j/jsx.go index d5ef0a1..2347538 100644 --- a/lexers/j/jsx.go +++ b/lexers/j/jsx.go @@ -8,7 +8,7 @@ import ( // JSX lexer. // // This was generated from https://github.com/fcurella/jsx-lexer -var JSX = internal.Register(MustNewLexer( +var JSX = internal.Register(MustNewLazyLexer( &Config{ Name: "react", Aliases: []string{"jsx", "react"}, @@ -16,7 +16,11 @@ var JSX = internal.Register(MustNewLexer( MimeTypes: []string{"text/jsx", "text/typescript-jsx"}, DotAll: true, }, - Rules{ + jsxRules, +)) + +func jsxRules() Rules { + return Rules{ "commentsandwhitespace": { {`\s+`, Text, nil}, {`