-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c6b341
commit 4b6319e
Showing
4 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package g | ||
|
||
import ( | ||
. "github.com/alecthomas/chroma" // nolint | ||
"github.com/alecthomas/chroma/lexers/internal" | ||
) | ||
|
||
// Go lexer. | ||
var Graphql = internal.Register(MustNewLexer( | ||
&Config{ | ||
Name: "GraphQL", | ||
Aliases: []string{"graphql", "graphqls", "gql"}, | ||
Filenames: []string{"*.graphql", "*.graphqls"}, | ||
}, | ||
Rules{ | ||
"root": { | ||
{`(query|mutation|subscription|fragment|scalar|implements|interface|union|enum|input|type)`, KeywordDeclaration, Push("type")}, | ||
{`(on|extend|schema|directive|\.\.\.)`, KeywordDeclaration, nil}, | ||
{`(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}, | ||
{`[^\W\d]\w*`, NameProperty, nil}, | ||
{`\@\w+`, NameDecorator, nil}, | ||
{`:`, Punctuation, Push("type")}, | ||
{`[\(\)\{\}\[\],!\|=]`, Punctuation, nil}, | ||
{`\$\w+`, NameVariable, nil}, | ||
{`\d+i`, LiteralNumber, nil}, | ||
{`\d+\.\d*([Ee][-+]\d+)?i`, LiteralNumber, nil}, | ||
{`\.\d+([Ee][-+]\d+)?i`, LiteralNumber, nil}, | ||
{`\d+[Ee][-+]\d+i`, LiteralNumber, nil}, | ||
{`\d+(\.\d+[eE][+\-]?\d+|\.\d*|[eE][+\-]?\d+)`, LiteralNumberFloat, nil}, | ||
{`\.\d+([eE][+\-]?\d+)?`, LiteralNumberFloat, nil}, | ||
{`(0|[1-9][0-9]*)`, LiteralNumberInteger, nil}, | ||
{`"""[\x00-\x7F]*?"""`, LiteralString, nil}, | ||
{`"(\\["\\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}, | ||
{`"(\\\\|\\"|[^"])*"`, LiteralString, nil}, | ||
{`"(true|false|null)*"`, Literal, nil}, | ||
{`[\r\n\s]+`, Whitespace, nil}, | ||
{`#[^\r\n]*`, Comment, nil}, | ||
}, | ||
// Treats the next word as a class, default rules it would be a property | ||
"type": { | ||
{`[^\W\d]\w*`, NameClass, Pop(1)}, | ||
Include("root"), | ||
}, | ||
}, | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
query Hero($episode: Episode, $withFriends: Boolean!) { | ||
hero(episode: $episode) { | ||
name | ||
friends @include(if: $withFriends) { | ||
name | ||
...frag | ||
|
||
... { | ||
inlineFrag | ||
} | ||
} | ||
} | ||
} | ||
|
||
fragment frag on User { | ||
id | ||
name | ||
profilePic(size: 50) | ||
} | ||
|
||
# Switching to schema | ||
"Description for the type" | ||
type MyObjectType { | ||
""" | ||
Description for field | ||
Supports **multi-line** description for your [API](http://example.com)! | ||
""" | ||
myField: String! @deprecated(reason: "Use `newField`.") | ||
|
||
otherField( | ||
"Description for argument" | ||
arg: Int | ||
) | ||
} | ||
|
||
input Foo { | ||
bar [String!]! = ["baz"] | ||
} | ||
|
||
directive @deprecated( | ||
reason: String = "No longer supported" | ||
) on FIELD_DEFINITION | ENUM_VALUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
[ | ||
{"type":"KeywordDeclaration","value":"query"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"Hero"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"NameVariable","value":"$episode"}, | ||
{"type":"Punctuation","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"Episode"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameVariable","value":"$withFriends"}, | ||
{"type":"Punctuation","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"Boolean"}, | ||
{"type":"Punctuation","value":"!)"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"hero"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"NameProperty","value":"episode"}, | ||
{"type":"Punctuation","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameVariable","value":"$episode"}, | ||
{"type":"Punctuation","value":")"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameClass","value":"name"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"friends"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameDecorator","value":"@include"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"NameProperty","value":"if"}, | ||
{"type":"Punctuation","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameVariable","value":"$withFriends"}, | ||
{"type":"Punctuation","value":")"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameClass","value":"name"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"KeywordDeclaration","value":"..."}, | ||
{"type":"NameProperty","value":"frag"}, | ||
{"type":"TextWhitespace","value":"\n\n "}, | ||
{"type":"KeywordDeclaration","value":"..."}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"inlineFrag"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n\n"}, | ||
{"type":"KeywordDeclaration","value":"fragment"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"frag"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"KeywordDeclaration","value":"on"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameProperty","value":"User"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"id"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"name"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"profilePic"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"NameProperty","value":"size"}, | ||
{"type":"Punctuation","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"50"}, | ||
{"type":"Punctuation","value":")"}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n\n"}, | ||
{"type":"Comment","value":"# Switching to schema"}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"LiteralString","value":"\"Description for the type\""}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"KeywordDeclaration","value":"type"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"MyObjectType"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"LiteralString","value":"\"\"\"\n Description for field\n Supports **multi-line** description for your [API](http://example.com)!\n \"\"\""}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"myField"}, | ||
{"type":"Punctuation","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"String"}, | ||
{"type":"Punctuation","value":"!"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameDecorator","value":"@deprecated"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"NameProperty","value":"reason"}, | ||
{"type":"Punctuation","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralString","value":"\"Use `newField`.\""}, | ||
{"type":"Punctuation","value":")"}, | ||
{"type":"TextWhitespace","value":"\n\n "}, | ||
{"type":"NameClass","value":"otherField"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"LiteralString","value":"\"Description for argument\""}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"arg"}, | ||
{"type":"Punctuation","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"Int"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"Punctuation","value":")"}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n\n"}, | ||
{"type":"KeywordDeclaration","value":"input"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"Foo"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"bar"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"["}, | ||
{"type":"NameProperty","value":"String"}, | ||
{"type":"Punctuation","value":"!]!"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"="}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"["}, | ||
{"type":"LiteralString","value":"\"baz\""}, | ||
{"type":"Punctuation","value":"]"}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"TextWhitespace","value":"\n\n"}, | ||
{"type":"KeywordDeclaration","value":"directive"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameDecorator","value":"@deprecated"}, | ||
{"type":"Punctuation","value":"("}, | ||
{"type":"TextWhitespace","value":"\n "}, | ||
{"type":"NameProperty","value":"reason"}, | ||
{"type":"Punctuation","value":":"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"NameClass","value":"String"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"="}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"LiteralString","value":"\"No longer supported\""}, | ||
{"type":"TextWhitespace","value":"\n"}, | ||
{"type":"Punctuation","value":")"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"KeywordDeclaration","value":"on"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"KeywordConstant","value":"FIELD_DEFINITION"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"Punctuation","value":"|"}, | ||
{"type":"TextWhitespace","value":" "}, | ||
{"type":"KeywordConstant","value":"ENUM_VALUE"}, | ||
{"type":"TextWhitespace","value":"\n"} | ||
] |