-
Notifications
You must be signed in to change notification settings - Fork 766
Add support for GraphQL #2088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for GraphQL #2088
Conversation
jeanas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for preparing this. Here are some preliminary comments. I think you can simplify it a lot with the ("#pop", "other_state") principle.
| @@ -0,0 +1,205 @@ | |||
| from pygments.lexer import RegexLexer, words, include, bygroups | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file is missing a docstring with module info and copyright header. See other files for a template, and run make check to ensure it's correct (the CI won't pass without this).
| ) | ||
|
|
||
|
|
||
| class GraphQLLexer(RegexLexer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add a docstring, for consumption by https://pygments.org/docs/lexers/. Don't forget the .. versionadded:: 2.12 directive.
|
|
||
| tokens = { | ||
| "ignored_tokens": [ | ||
| (r"([ \t]|[\r\n]|\r\n)+", Text), # Whitespaces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just \s+? Also, please use Whitespace instead of Text (see #1905).
| ), | ||
| (r"-?\d+", Number.Integer, "#pop"), | ||
| (r'"', String, "string0"), | ||
| (words(BOOLEAN_VALUES, suffix=r"\b"), Name.Builtin, "#pop"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Keyword.Pseudo apply here? (I don't know the language.) See https://pygments.org/docs/tokens/ for a description.
| (r"-?\d+", Number.Integer, "#pop"), | ||
| (r'"', String, "string0"), | ||
| (words(BOOLEAN_VALUES, suffix=r"\b"), Name.Builtin, "#pop"), | ||
| (r"\$[a-zA-Z_]\w*", Name.Variable, "#pop"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Unicode supported? If so, [^\W\d] would be better than [a-zA-Z_] (same thing in other places).
| (words(BOOLEAN_VALUES, suffix=r"\b"), Name.Builtin, "#pop"), | ||
| (r"\$[a-zA-Z_]\w*", Name.Variable, "#pop"), | ||
| (r"[a-zA-Z_]\w*", Name.Constant, "#pop"), | ||
| (r"\[", Punctuation, "list_value0"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the include() dance between list_value0 and list_value, I think it would be simpler to do
(r"\[", Punctuation, ("#pop", "list_value")),
and keep just one list_value state. The same seems to apply to your remark above about state duplication.
| ], | ||
| "selection_set": [ | ||
| include("ignored_tokens"), | ||
| (r"([a-zA-Z_]\w*)(\s*)(:)", bygroups(Name.Label, Text, Punctuation)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace
| (r"[a-zA-Z_]\w*", Name), # Field | ||
| ( | ||
| r"(\.\.\.)(\s+)(on)\b", | ||
| bygroups(Punctuation, Text, Keyword), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
| (56, Punctuation, "}"), | ||
| (57, Text, "\n"), | ||
| ] | ||
| assert_tokens_equal(self, text, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this file: this is a lot of test code, and generally most of it can simply go as the other tests in tests/examplefiles/, or better yet, tests/snippets/ (which is a bit more practical for small test files; you could also move the other tests there). You could keep the tests that start on a specific state, but maybe there is a simple pattern that you can use to get in a value context, to keep everything in tests/snippets/?
|
Is this branch / feature dead / stale? Is the original PR opener planning on going through these changes? |
|
I think it's fair to say it's been a while, if you want to pick up the work from here, this would be great so we can eventually land GraphQL support. |
|
Closing in favor of #2428 |
Closes #1634.