Created
March 22, 2017 21:54
-
-
Save owulveryck/17a049d413ff8e3affa9c68a3010a089 to your computer and use it in GitHub Desktop.
pygments for graphql (see http://www.catchmecode.com/2013/03/custom-syntax-in-pygments.html)
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
""" | |
pygments.lexers.graphql | |
~~~~~~~~~~~~~~~~~~~~ | |
Lexers for GraphQL formats. | |
:copyright: Copyright 2017 by Martin Zlámal. | |
:license: BSD, see LICENSE for details. | |
""" | |
from pygments.lexer import RegexLexer | |
from pygments.token import * | |
__all__ = ['GraphqlLexer'] | |
class GraphqlLexer(RegexLexer): | |
""" | |
Lexer for GraphQL. | |
""" | |
name = 'GraphQL' | |
aliases = ['graphql', 'gql'] | |
filenames = ['*.graphql', '*.gql'] | |
mimetypes = ['application/graphql'] | |
tokens = { | |
'root': [ | |
(r'#.*', Comment.Singline), | |
(r'\.\.\.', Operator), | |
(ur'"[\u0009\u000A\u000D\u0020-\uFFFF]*"', String.Double), | |
(r'(-?0|-?[1-9][0-9]*)(\.[0-9]+[eE][+-]?[0-9]+|\.[0-9]+|[eE][+-]?[0-9]+)', Number.Float), | |
(r'(-?0|-?[1-9][0-9]*)', Number.Integer), | |
(r'\$+[_A-Za-z][_0-9A-Za-z]*', Name.Variable), | |
(r'[_A-Za-z][_0-9A-Za-z]+\s?:', Text), | |
(r'(type|query|mutation|@[a-z]+|on|true|false|null)\b', Keyword.Type), | |
(r'[!$():=@\[\]{|}]+?', Punctuation), | |
(r'[_A-Za-z][_0-9A-Za-z]*', Keyword), | |
(r'(\s|,)', Text), | |
] | |
} |
This file contains hidden or 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
sudo apt install python-setuptools | |
sudo apt install python-pygments | |
touch graphqllexer/__init__.py | |
sudo python setup.py develop |
This file contains hidden or 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
from setuptools import setup, find_packages | |
setup ( | |
name='graphqllexer', | |
packages=find_packages(), | |
entry_points = | |
""" | |
[pygments.lexers] | |
graphqllexer = graphqllexer.lexer:GraphqlLexer | |
""", | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment