...

Source file src/github.com/alecthomas/chroma/lexers/r/ragel.go

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

     1  package r
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Ragel lexer.
     9  var Ragel = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "Ragel",
    12  		Aliases:   []string{"ragel"},
    13  		Filenames: []string{},
    14  		MimeTypes: []string{},
    15  	},
    16  	ragelRules,
    17  ))
    18  
    19  func ragelRules() Rules {
    20  	return Rules{
    21  		"whitespace": {
    22  			{`\s+`, TextWhitespace, nil},
    23  		},
    24  		"comments": {
    25  			{`\#.*$`, Comment, nil},
    26  		},
    27  		"keywords": {
    28  			{`(access|action|alphtype)\b`, Keyword, nil},
    29  			{`(getkey|write|machine|include)\b`, Keyword, nil},
    30  			{`(any|ascii|extend|alpha|digit|alnum|lower|upper)\b`, Keyword, nil},
    31  			{`(xdigit|cntrl|graph|print|punct|space|zlen|empty)\b`, Keyword, nil},
    32  		},
    33  		"numbers": {
    34  			{`0x[0-9A-Fa-f]+`, LiteralNumberHex, nil},
    35  			{`[+-]?[0-9]+`, LiteralNumberInteger, nil},
    36  		},
    37  		"literals": {
    38  			{`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
    39  			{`'(\\\\|\\'|[^'])*'`, LiteralString, nil},
    40  			{`\[(\\\\|\\\]|[^\]])*\]`, LiteralString, nil},
    41  			{`/(?!\*)(\\\\|\\/|[^/])*/`, LiteralStringRegex, nil},
    42  		},
    43  		"identifiers": {
    44  			{`[a-zA-Z_]\w*`, NameVariable, nil},
    45  		},
    46  		"operators": {
    47  			{`,`, Operator, nil},
    48  			{`\||&|--?`, Operator, nil},
    49  			{`\.|<:|:>>?`, Operator, nil},
    50  			{`:`, Operator, nil},
    51  			{`->`, Operator, nil},
    52  			{`(>|\$|%|<|@|<>)(/|eof\b)`, Operator, nil},
    53  			{`(>|\$|%|<|@|<>)(!|err\b)`, Operator, nil},
    54  			{`(>|\$|%|<|@|<>)(\^|lerr\b)`, Operator, nil},
    55  			{`(>|\$|%|<|@|<>)(~|to\b)`, Operator, nil},
    56  			{`(>|\$|%|<|@|<>)(\*|from\b)`, Operator, nil},
    57  			{`>|@|\$|%`, Operator, nil},
    58  			{`\*|\?|\+|\{[0-9]*,[0-9]*\}`, Operator, nil},
    59  			{`!|\^`, Operator, nil},
    60  			{`\(|\)`, Operator, nil},
    61  		},
    62  		"root": {
    63  			Include("literals"),
    64  			Include("whitespace"),
    65  			Include("comments"),
    66  			Include("keywords"),
    67  			Include("numbers"),
    68  			Include("identifiers"),
    69  			Include("operators"),
    70  			{`\{`, Punctuation, Push("host")},
    71  			{`=`, Operator, nil},
    72  			{`;`, Punctuation, nil},
    73  		},
    74  		"host": {
    75  			{`([^{}\'"/#]+|[^\\]\\[{}]|"(\\\\|\\"|[^"])*"|'(\\\\|\\'|[^'])*'|//.*$\n?|/\*(.|\n)*?\*/|\#.*$\n?|/(?!\*)(\\\\|\\/|[^/])*/|/)+`, Other, nil},
    76  			{`\{`, Punctuation, Push()},
    77  			{`\}`, Punctuation, Pop(1)},
    78  		},
    79  	}
    80  }
    81  

View as plain text