...

Source file src/github.com/alecthomas/chroma/lexers/g/graphql.go

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

     1  package g
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Go lexer.
     9  var Graphql = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "GraphQL",
    12  		Aliases:   []string{"graphql", "graphqls", "gql"},
    13  		Filenames: []string{"*.graphql", "*.graphqls"},
    14  	},
    15  	graphqlRules,
    16  ))
    17  
    18  func graphqlRules() Rules {
    19  	return Rules{
    20  		"root": {
    21  			{`(query|mutation|subscription|fragment|scalar|implements|interface|union|enum|input|type)`, KeywordDeclaration, Push("type")},
    22  			{`(on|extend|schema|directive|\.\.\.)`, KeywordDeclaration, nil},
    23  			{`(QUERY|MUTATION|SUBSCRIPTION|FIELD|FRAGMENT_DEFINITION|FRAGMENT_SPREAD|INLINE_FRAGMENT|SCHEMA|SCALAR|OBJECT|FIELD_DEFINITION|ARGUMENT_DEFINITION|INTERFACE|UNION|ENUM|ENUM_VALUE|INPUT_OBJECT|INPUT_FIELD_DEFINITION)\b`, KeywordConstant, nil},
    24  			{`[^\W\d]\w*`, NameProperty, nil},
    25  			{`\@\w+`, NameDecorator, nil},
    26  			{`:`, Punctuation, Push("type")},
    27  			{`[\(\)\{\}\[\],!\|=]`, Punctuation, nil},
    28  			{`\$\w+`, NameVariable, nil},
    29  			{`\d+i`, LiteralNumber, nil},
    30  			{`\d+\.\d*([Ee][-+]\d+)?i`, LiteralNumber, nil},
    31  			{`\.\d+([Ee][-+]\d+)?i`, LiteralNumber, nil},
    32  			{`\d+[Ee][-+]\d+i`, LiteralNumber, nil},
    33  			{`\d+(\.\d+[eE][+\-]?\d+|\.\d*|[eE][+\-]?\d+)`, LiteralNumberFloat, nil},
    34  			{`\.\d+([eE][+\-]?\d+)?`, LiteralNumberFloat, nil},
    35  			{`(0|[1-9][0-9]*)`, LiteralNumberInteger, nil},
    36  			{`"""[\x00-\x7F]*?"""`, LiteralString, nil},
    37  			{`"(\\["\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])"`, LiteralStringChar, nil},
    38  			{`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
    39  			{`"(true|false|null)*"`, Literal, nil},
    40  			{`[\r\n\s]+`, Whitespace, nil},
    41  			{`#[^\r\n]*`, Comment, nil},
    42  		},
    43  		// Treats the next word as a class, default rules it would be a property
    44  		"type": {
    45  			{`[^\W\d]\w*`, NameClass, Pop(1)},
    46  			Include("root"),
    47  		},
    48  	}
    49  }
    50  

View as plain text