...

Source file src/github.com/alecthomas/chroma/lexers/e/elm.go

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

     1  package e
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Elm lexer.
     9  var Elm = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "Elm",
    12  		Aliases:   []string{"elm"},
    13  		Filenames: []string{"*.elm"},
    14  		MimeTypes: []string{"text/x-elm"},
    15  	},
    16  	elmRules,
    17  ))
    18  
    19  func elmRules() Rules {
    20  	return Rules{
    21  		"root": {
    22  			{`\{-`, CommentMultiline, Push("comment")},
    23  			{`--.*`, CommentSingle, nil},
    24  			{`\s+`, Text, nil},
    25  			{`"`, LiteralString, Push("doublequote")},
    26  			{`^\s*module\s*`, KeywordNamespace, Push("imports")},
    27  			{`^\s*import\s*`, KeywordNamespace, Push("imports")},
    28  			{`\[glsl\|.*`, NameEntity, Push("shader")},
    29  			{Words(``, `\b`, `alias`, `as`, `case`, `else`, `if`, `import`, `in`, `let`, `module`, `of`, `port`, `then`, `type`, `where`), KeywordReserved, nil},
    30  			{`[A-Z]\w*`, KeywordType, nil},
    31  			{`^main `, KeywordReserved, nil},
    32  			{Words(`\(`, `\)`, `~`, `||`, `|>`, `|`, "`", `^`, `\`, `'`, `>>`, `>=`, `>`, `==`, `=`, `<~`, `<|`, `<=`, `<<`, `<-`, `<`, `::`, `:`, `/=`, `//`, `/`, `..`, `.`, `->`, `-`, `++`, `+`, `*`, `&&`, `%`), NameFunction, nil},
    33  			{Words(``, ``, `~`, `||`, `|>`, `|`, "`", `^`, `\`, `'`, `>>`, `>=`, `>`, `==`, `=`, `<~`, `<|`, `<=`, `<<`, `<-`, `<`, `::`, `:`, `/=`, `//`, `/`, `..`, `.`, `->`, `-`, `++`, `+`, `*`, `&&`, `%`), NameFunction, nil},
    34  			Include("numbers"),
    35  			{`[a-z_][a-zA-Z_\']*`, NameVariable, nil},
    36  			{`[,()\[\]{}]`, Punctuation, nil},
    37  		},
    38  		"comment": {
    39  			{`-(?!\})`, CommentMultiline, nil},
    40  			{`\{-`, CommentMultiline, Push("comment")},
    41  			{`[^-}]`, CommentMultiline, nil},
    42  			{`-\}`, CommentMultiline, Pop(1)},
    43  		},
    44  		"doublequote": {
    45  			{`\\u[0-9a-fA-F]{4}`, LiteralStringEscape, nil},
    46  			{`\\[nrfvb\\"]`, LiteralStringEscape, nil},
    47  			{`[^"]`, LiteralString, nil},
    48  			{`"`, LiteralString, Pop(1)},
    49  		},
    50  		"imports": {
    51  			{`\w+(\.\w+)*`, NameClass, Pop(1)},
    52  		},
    53  		"numbers": {
    54  			{`_?\d+\.(?=\d+)`, LiteralNumberFloat, nil},
    55  			{`_?\d+`, LiteralNumberInteger, nil},
    56  		},
    57  		"shader": {
    58  			{`\|(?!\])`, NameEntity, nil},
    59  			{`\|\]`, NameEntity, Pop(1)},
    60  			{`.*\n`, NameEntity, nil},
    61  		},
    62  	}
    63  }
    64  

View as plain text