...

Source file src/github.com/alecthomas/chroma/lexers/c/chaiscript.go

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

     1  package c
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Chaiscript lexer.
     9  var Chaiscript = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "ChaiScript",
    12  		Aliases:   []string{"chai", "chaiscript"},
    13  		Filenames: []string{"*.chai"},
    14  		MimeTypes: []string{"text/x-chaiscript", "application/x-chaiscript"},
    15  		DotAll:    true,
    16  	},
    17  	chaiscriptRules,
    18  ))
    19  
    20  func chaiscriptRules() Rules {
    21  	return Rules{
    22  		"commentsandwhitespace": {
    23  			{`\s+`, Text, nil},
    24  			{`//.*?\n`, CommentSingle, nil},
    25  			{`/\*.*?\*/`, CommentMultiline, nil},
    26  			{`^\#.*?\n`, CommentSingle, nil},
    27  		},
    28  		"slashstartsregex": {
    29  			Include("commentsandwhitespace"),
    30  			{`/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/([gim]+\b|\B)`, LiteralStringRegex, Pop(1)},
    31  			{`(?=/)`, Text, Push("#pop", "badregex")},
    32  			Default(Pop(1)),
    33  		},
    34  		"badregex": {
    35  			{`\n`, Text, Pop(1)},
    36  		},
    37  		"root": {
    38  			Include("commentsandwhitespace"),
    39  			{`\n`, Text, nil},
    40  			{`[^\S\n]+`, Text, nil},
    41  			{`\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|\.\.(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?`, Operator, Push("slashstartsregex")},
    42  			{`[{(\[;,]`, Punctuation, Push("slashstartsregex")},
    43  			{`[})\].]`, Punctuation, nil},
    44  			{`[=+\-*/]`, Operator, nil},
    45  			{`(for|in|while|do|break|return|continue|if|else|throw|try|catch)\b`, Keyword, Push("slashstartsregex")},
    46  			{`(var)\b`, KeywordDeclaration, Push("slashstartsregex")},
    47  			{`(attr|def|fun)\b`, KeywordReserved, nil},
    48  			{`(true|false)\b`, KeywordConstant, nil},
    49  			{`(eval|throw)\b`, NameBuiltin, nil},
    50  			{"`\\S+`", NameBuiltin, nil},
    51  			{`[$a-zA-Z_]\w*`, NameOther, nil},
    52  			{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
    53  			{`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
    54  			{`[0-9]+`, LiteralNumberInteger, nil},
    55  			{`"`, LiteralStringDouble, Push("dqstring")},
    56  			{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
    57  		},
    58  		"dqstring": {
    59  			{`\$\{[^"}]+?\}`, LiteralStringInterpol, nil},
    60  			{`\$`, LiteralStringDouble, nil},
    61  			{`\\\\`, LiteralStringDouble, nil},
    62  			{`\\"`, LiteralStringDouble, nil},
    63  			{`[^\\"$]+`, LiteralStringDouble, nil},
    64  			{`"`, LiteralStringDouble, Pop(1)},
    65  		},
    66  	}
    67  }
    68  

View as plain text