mirror of
https://github.com/alecthomas/chroma.git
synced 2025-01-14 02:23:16 +02:00
Imported: css, html, java, php.
This commit is contained in:
parent
8ec7ab9986
commit
6aea285ca4
106
lexers/css.go
Normal file
106
lexers/css.go
Normal file
File diff suppressed because one or more lines are too long
56
lexers/html.go
Normal file
56
lexers/html.go
Normal file
@ -0,0 +1,56 @@
|
||||
package lexers
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
)
|
||||
|
||||
// Html lexer.
|
||||
var Html = Register(NewLexer(
|
||||
&Config{
|
||||
Name: "HTML",
|
||||
Aliases: []string{"html"},
|
||||
Filenames: []string{"*.html", "*.htm", "*.xhtml", "*.xslt"},
|
||||
MimeTypes: []string{"text/html", "application/xhtml+xml"},
|
||||
NotMultiline: true,
|
||||
DotAll: true,
|
||||
CaseInsensitive: true,
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
{`[^<&]+`, Text, nil},
|
||||
{`&\S*?;`, NameEntity, nil},
|
||||
{`\<\!\[CDATA\[.*?\]\]\>`, CommentPreproc, nil},
|
||||
{`<!--`, Comment, Push("comment")},
|
||||
{`<\?.*?\?>`, CommentPreproc, nil},
|
||||
{`<![^>]*>`, CommentPreproc, nil},
|
||||
{`(<)(\s*)(script)(\s*)`, ByGroups(Punctuation, Text, NameTag, Text), Push("script-content", "tag")},
|
||||
{`(<)(\s*)(style)(\s*)`, ByGroups(Punctuation, Text, NameTag, Text), Push("style-content", "tag")},
|
||||
{`(<)(\s*)([\w:.-]+)`, ByGroups(Punctuation, Text, NameTag), Push("tag")},
|
||||
{`(<)(\s*)(/)(\s*)([\w:.-]+)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), nil},
|
||||
},
|
||||
"comment": {
|
||||
{`[^-]+`, Comment, nil},
|
||||
{`-->`, Comment, Pop(1)},
|
||||
{`-`, Comment, nil},
|
||||
},
|
||||
"tag": {
|
||||
{`\s+`, Text, nil},
|
||||
{`([\w:-]+\s*)(=)(\s*)`, ByGroups(NameAttribute, Operator, Text), Push("attr")},
|
||||
{`[\w:-]+`, NameAttribute, nil},
|
||||
{`(/?)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation), Pop(1)},
|
||||
},
|
||||
"script-content": {
|
||||
{`(<)(\s*)(/)(\s*)(script)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)},
|
||||
{`.+?(?=<\s*/\s*script\s*>)`, Using(JavascriptLexer, nil), nil},
|
||||
},
|
||||
"style-content": {
|
||||
{`(<)(\s*)(/)(\s*)(style)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation, Text, NameTag, Text, Punctuation), Pop(1)},
|
||||
{`.+?(?=<\s*/\s*style\s*>)`, Using(CssLexer, nil), nil},
|
||||
},
|
||||
"attr": {
|
||||
{`".*?"`, LiteralString, Pop(1)},
|
||||
{`'.*?'`, LiteralString, Pop(1)},
|
||||
{`[^\s>]+`, LiteralString, Pop(1)},
|
||||
},
|
||||
},
|
||||
))
|
52
lexers/java.go
Normal file
52
lexers/java.go
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
package lexers
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
)
|
||||
|
||||
// Java lexer.
|
||||
var Java = Register(NewLexer(
|
||||
&Config{
|
||||
Name: "Java",
|
||||
Aliases: []string{ "java", },
|
||||
Filenames: []string{ "*.java", },
|
||||
MimeTypes: []string{ "text/x-java", },
|
||||
DotAll: true,
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
{ `[^\S\n]+`, Text, nil },
|
||||
{ `//.*?\n`, CommentSingle, nil },
|
||||
{ `/\*.*?\*/`, CommentMultiline, nil },
|
||||
{ `(assert|break|case|catch|continue|default|do|else|finally|for|if|goto|instanceof|new|return|switch|this|throw|try|while)\b`, Keyword, nil },
|
||||
{ `((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)((?:[^\W\d]|\$)[\w$]*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil },
|
||||
{ `@[^\W\d][\w.]*`, NameDecorator, nil },
|
||||
{ `(abstract|const|enum|extends|final|implements|native|private|protected|public|static|strictfp|super|synchronized|throws|transient|volatile)\b`, KeywordDeclaration, nil },
|
||||
{ `(boolean|byte|char|double|float|int|long|short|void)\b`, KeywordType, nil },
|
||||
{ `(package)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import") },
|
||||
{ `(true|false|null)\b`, KeywordConstant, nil },
|
||||
{ `(class|interface)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class") },
|
||||
{ `(import(?:\s+static)?)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import") },
|
||||
{ `"(\\\\|\\"|[^"])*"`, LiteralString, nil },
|
||||
{ `'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'`, LiteralStringChar, nil },
|
||||
{ `(\.)((?:[^\W\d]|\$)[\w$]*)`, ByGroups(Operator, NameAttribute), nil },
|
||||
{ `^\s*([^\W\d]|\$)[\w$]*:`, NameLabel, nil },
|
||||
{ `([^\W\d]|\$)[\w$]*`, Name, nil },
|
||||
{ `([0-9][0-9_]*\.([0-9][0-9_]*)?|\.[0-9][0-9_]*)([eE][+\-]?[0-9][0-9_]*)?[fFdD]?|[0-9][eE][+\-]?[0-9][0-9_]*[fFdD]?|[0-9]([eE][+\-]?[0-9][0-9_]*)?[fFdD]|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_]*[fFdD]?`, 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 },
|
||||
{ `[~^*!%&\[\](){}<>|+=:;,./?-]`, Operator, nil },
|
||||
{ `\n`, Text, nil },
|
||||
},
|
||||
"class": {
|
||||
{ `([^\W\d]|\$)[\w$]*`, NameClass, Pop(1) },
|
||||
},
|
||||
"import": {
|
||||
{ `[\w.]+\*?`, NameNamespace, Pop(1) },
|
||||
},
|
||||
},
|
||||
))
|
||||
|
81
lexers/php.go
Normal file
81
lexers/php.go
Normal file
@ -0,0 +1,81 @@
|
||||
package lexers
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
)
|
||||
|
||||
// Php lexer.
|
||||
var Php = Register(NewLexer(
|
||||
&Config{
|
||||
Name: "PHP",
|
||||
Aliases: []string{"php", "php3", "php4", "php5"},
|
||||
Filenames: []string{"*.php", "*.php[345]", "*.inc"},
|
||||
MimeTypes: []string{"text/x-php"},
|
||||
DotAll: true,
|
||||
CaseInsensitive: true,
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
{`<\?(php)?`, CommentPreproc, Push("php")},
|
||||
{`[^<]+`, Other, nil},
|
||||
{`<`, Other, nil},
|
||||
},
|
||||
"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": {
|
||||
{`(?:__construct|__destruct|__call|__callStatic|__get|__set|__isset|__unset|__sleep|__wakeup|__toString|__invoke|__set_state|__clone|__debugInfo)\b`, NameFunctionMagic, nil},
|
||||
},
|
||||
"magicconstants": {
|
||||
{`(?:__LINE__|__FILE__|__DIR__|__FUNCTION__|__CLASS__|__TRAIT__|__METHOD__|__NAMESPACE__)\b`, 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},
|
||||
},
|
||||
},
|
||||
))
|
Loading…
Reference in New Issue
Block a user