Skip to content

Instantly share code, notes, and snippets.

@owulveryck
Created March 22, 2017 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owulveryck/17a049d413ff8e3affa9c68a3010a089 to your computer and use it in GitHub Desktop.
Save owulveryck/17a049d413ff8e3affa9c68a3010a089 to your computer and use it in GitHub Desktop.
# -*- 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),
]
}
sudo apt install python-setuptools
sudo apt install python-pygments
touch graphqllexer/__init__.py
sudo python setup.py develop
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