...

Source file src/github.com/alecthomas/chroma/lexers/v/vue.go

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

     1  package v
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Vue lexer.
     9  //
    10  // This was generated from https://github.com/testdrivenio/vue-lexer
    11  var Vue = internal.Register(MustNewLazyLexer(
    12  	&Config{
    13  		Name:      "vue",
    14  		Aliases:   []string{"vue", "vuejs"},
    15  		Filenames: []string{"*.vue"},
    16  		MimeTypes: []string{"text/x-vue", "application/x-vue"},
    17  		DotAll:    true,
    18  	},
    19  	vueRules,
    20  ))
    21  
    22  func vueRules() Rules {
    23  	return Rules{
    24  		"commentsandwhitespace": {
    25  			{`\s+`, Text, nil},
    26  			{`<!--`, Comment, nil},
    27  			{`//.*?\n`, CommentSingle, nil},
    28  			{`/\*.*?\*/`, CommentMultiline, nil},
    29  		},
    30  		"slashstartsregex": {
    31  			Include("commentsandwhitespace"),
    32  			{`/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/([gimuy]+\b|\B)`, LiteralStringRegex, Pop(1)},
    33  			{`(?=/)`, Text, Push("#pop", "badregex")},
    34  			Default(Pop(1)),
    35  		},
    36  		"badregex": {
    37  			{`\n`, Text, Pop(1)},
    38  		},
    39  		"root": {
    40  			Include("vue"),
    41  			{`\A#! ?/.*?\n`, CommentHashbang, nil},
    42  			{`^(?=\s|/|<!--)`, Text, Push("slashstartsregex")},
    43  			Include("commentsandwhitespace"),
    44  			{`(\.\d+|[0-9]+\.[0-9]*)([eE][-+]?[0-9]+)?`, LiteralNumberFloat, nil},
    45  			{`0[bB][01]+`, LiteralNumberBin, nil},
    46  			{`0[oO][0-7]+`, LiteralNumberOct, nil},
    47  			{`0[xX][0-9a-fA-F]+`, LiteralNumberHex, nil},
    48  			{`[0-9]+`, LiteralNumberInteger, nil},
    49  			{`\.\.\.|=>`, Punctuation, nil},
    50  			{`\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?`, Operator, Push("slashstartsregex")},
    51  			{`[{(\[;,]`, Punctuation, Push("slashstartsregex")},
    52  			{`[})\].]`, Punctuation, nil},
    53  			{`(for|in|while|do|break|return|continue|switch|case|default|if|else|throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|this|of)\b`, Keyword, Push("slashstartsregex")},
    54  			{`(var|let|with|function)\b`, KeywordDeclaration, Push("slashstartsregex")},
    55  			{`(abstract|boolean|byte|char|class|const|debugger|double|enum|export|extends|final|float|goto|implements|import|int|interface|long|native|package|private|protected|public|short|static|super|synchronized|throws|transient|volatile)\b`, KeywordReserved, nil},
    56  			{`(true|false|null|NaN|Infinity|undefined)\b`, KeywordConstant, nil},
    57  			{`(Array|Boolean|Date|Error|Function|Math|netscape|Number|Object|Packages|RegExp|String|Promise|Proxy|sun|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|Error|eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|document|this|window)\b`, NameBuiltin, nil},
    58  			{`(?:[$_\p{L}\p{N}]|\\u[a-fA-F0-9]{4})(?:(?:[$\p{L}\p{N}]|\\u[a-fA-F0-9]{4}))*`, NameOther, nil},
    59  			{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
    60  			{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
    61  			{"`", LiteralStringBacktick, Push("interp")},
    62  		},
    63  		"interp": {
    64  			{"`", LiteralStringBacktick, Pop(1)},
    65  			{`\\\\`, LiteralStringBacktick, nil},
    66  			{"\\\\`", LiteralStringBacktick, nil},
    67  			{`\$\{`, LiteralStringInterpol, Push("interp-inside")},
    68  			{`\$`, LiteralStringBacktick, nil},
    69  			{"[^`\\\\$]+", LiteralStringBacktick, nil},
    70  		},
    71  		"interp-inside": {
    72  			{`\}`, LiteralStringInterpol, Pop(1)},
    73  			Include("root"),
    74  		},
    75  		"vue": {
    76  			{`(<)([\w]+)`, ByGroups(Punctuation, NameTag), Push("tag")},
    77  			{`(<)(/)([\w]+)(>)`, ByGroups(Punctuation, Punctuation, NameTag, Punctuation), nil},
    78  		},
    79  		"tag": {
    80  			{`\s+`, Text, nil},
    81  			{`(-)([\w]+)`, NameTag, nil},
    82  			{`(@[\w]+)(="[\S]+")(>)`, ByGroups(NameTag, LiteralString, Punctuation), nil},
    83  			{`(@[\w]+)(="[\S]+")`, ByGroups(NameTag, LiteralString), nil},
    84  			{`(@[\S]+)(="[\S]+")`, ByGroups(NameTag, LiteralString), nil},
    85  			{`(:[\S]+)(="[\S]+")`, ByGroups(NameTag, LiteralString), nil},
    86  			{`(:)`, Operator, nil},
    87  			{`(v-b-[\S]+)`, NameTag, nil},
    88  			{`(v-[\w]+)(=".+)([:][\w]+)(="[\w]+")(>)`, ByGroups(NameTag, LiteralString, NameTag, LiteralString, Punctuation), nil},
    89  			{`(v-[\w]+)(="[\S]+")(>)`, ByGroups(NameTag, LiteralString, Punctuation), nil},
    90  			{`(v-[\w]+)(>)`, ByGroups(NameTag, Punctuation), nil},
    91  			{`(v-[\w]+)(=".+")(>)`, ByGroups(NameTag, LiteralString, Punctuation), nil},
    92  			{`(<)([\w]+)`, ByGroups(Punctuation, NameTag), nil},
    93  			{`(<)(/)([\w]+)(>)`, ByGroups(Punctuation, Punctuation, NameTag, Punctuation), nil},
    94  			{`([\w]+\s*)(=)(\s*)`, ByGroups(NameAttribute, Operator, Text), Push("attr")},
    95  			{`[{}]+`, Punctuation, nil},
    96  			{`[\w\.]+`, NameAttribute, nil},
    97  			{`(/?)(\s*)(>)`, ByGroups(Punctuation, Text, Punctuation), Pop(1)},
    98  		},
    99  		"attr": {
   100  			{`{`, Punctuation, Push("expression")},
   101  			{`".*?"`, LiteralString, Pop(1)},
   102  			{`'.*?'`, LiteralString, Pop(1)},
   103  			Default(Pop(1)),
   104  		},
   105  		"expression": {
   106  			{`{`, Punctuation, Push()},
   107  			{`}`, Punctuation, Pop(1)},
   108  			Include("root"),
   109  		},
   110  	}
   111  }
   112  

View as plain text