1package g
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Go lexer.
9var Graphql = internal.Register(MustNewLexer(
10 &Config{
11 Name: "GraphQL",
12 Aliases: []string{"graphql", "graphqls", "gql"},
13 Filenames: []string{"*.graphql", "*.graphqls"},
14 },
15 Rules{
16 "root": {
17 {`(query|mutation|subscription|fragment|scalar|implements|interface|union|enum|input|type)`, KeywordDeclaration, Push("type")},
18 {`(on|extend|schema|directive|\.\.\.)`, KeywordDeclaration, nil},
19 {`(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},
20 {`[^\W\d]\w*`, NameProperty, nil},
21 {`\@\w+`, NameDecorator, nil},
22 {`:`, Punctuation, Push("type")},
23 {`[\(\)\{\}\[\],!\|=]`, Punctuation, nil},
24 {`\$\w+`, NameVariable, nil},
25 {`\d+i`, LiteralNumber, nil},
26 {`\d+\.\d*([Ee][-+]\d+)?i`, LiteralNumber, nil},
27 {`\.\d+([Ee][-+]\d+)?i`, LiteralNumber, nil},
28 {`\d+[Ee][-+]\d+i`, LiteralNumber, nil},
29 {`\d+(\.\d+[eE][+\-]?\d+|\.\d*|[eE][+\-]?\d+)`, LiteralNumberFloat, nil},
30 {`\.\d+([eE][+\-]?\d+)?`, LiteralNumberFloat, nil},
31 {`(0|[1-9][0-9]*)`, LiteralNumberInteger, nil},
32 {`"""[\x00-\x7F]*?"""`, LiteralString, nil},
33 {`"(\\["\\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},
34 {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
35 {`"(true|false|null)*"`, Literal, nil},
36 {`[\r\n\s]+`, Whitespace, nil},
37 {`#[^\r\n]*`, Comment, nil},
38 },
39 // Treats the next word as a class, default rules it would be a property
40 "type": {
41 {`[^\W\d]\w*`, NameClass, Pop(1)},
42 Include("root"),
43 },
44 },
45))