<commit_before>##
# Copyright (c) 2016 MagicStack Inc.
# All rights reserved.
#
# See LICENSE for details.
##


import re

from edgedb.lang.common import ast, parsing


class Base(ast.AST):
    ns = 'graphql'
    __fields = [('context', parsing.ParserContext, None,
                 True, None, True  # this last True is "hidden" attribute
                 )]

    def _extra_repr(self):
        return ''

    def __repr__(self):
        ar = self._extra_repr()
        return '<{}.{} at {:#x}{}>'.format(self.__class__.ns,
                                           self.__class__.__name__,
                                           id(self),
                                           ar)


class LiteralNode(Base):
    __fields = ['value']

    def topython(self):
        return self.value


class StringLiteral(LiteralNode):
    def tosource(self):
        value = self.value
        # generic substitutions for '\b' and '\f'
        #
        value = value.replace('\b', '\\b').replace('\f', '\\f')
        value = repr(value)
        # escape \b \f \u1234 and \/ correctly
        #
        value = re.sub(r'\\\\([fb])', r'\\\1', value)
        value = re.sub(r'\\\\(u[0-9a-fA-F]{4})', r'\\\1', value)
        value = value.replace('/', r'\/')

        if value[0] == "'":
            # need to change quotation style
            #
            value = value[1:-1].replace(R'\'', "'").replace('"', R'\"')
            value = '"' + value + '"'

        return value


class IntegerLiteral(LiteralNode):
    pass


class FloatLiteral(LiteralNode):
    pass


class BooleanLiteral(LiteralNode):
    pass


class EnumLiteral(LiteralNode):
    pass


class ListLiteral(LiteralNode):
    def topython(self):
        return [val.topython() for val in self.value]


class ObjectLiteral(LiteralNode):
    def topython(self):
        return {field.name: field.value.topython() for field in self.value}


class Variable(Base):
    __fields = ['value']


class Document(Base):
    __fields = [('definitions', list, list)]


class Definition(Base):
    __fields = [
        ('name', str, None),
        'selection_set',
    ]


class OperationDefinition(Definition):
    __fields = [
        ('type', str, None),
        ('variables', list, list),
        ('directives', list, list),
    ]


class FragmentDefinition(Definition):
    __fields = [
        'on',
        ('directives', list, list),
    ]


class VariableDefinition(Base):
    __fields = ['name', 'type', 'value']


class VariableType(Base):
    __fields = [
        'name',
        ('nullable', bool, True),
        ('list', bool, False),
    ]


class SelectionSet(Base):
    __fields = [('selections', list, list)]


class Selection(Base):
    pass


class Field(Selection):
    __fields = [
        ('alias', str, None),
        'name',
        ('arguments', list, list),
        ('directives', list, list),
        'selection_set',
    ]


class FragmentSpread(Selection):
    __fields = [
        'name',
        ('directives', list, list),
    ]


class InlineFragment(Selection):
    __fields = [
        'on',
        ('directives', list, list),
        'selection_set',
    ]


class Directive(Base):
    __fields = [
        'name',
        ('arguments', list, list),
    ]


class Argument(Base):
    __fields = ['name', 'value']


class ObjectField(Base):
    __fields = ['name', 'value']<commit_msg>graphql: Convert AST to new type annotations syntax<commit_after>##
# Copyright (c) 2016 MagicStack Inc.
# All rights reserved.
#
# See LICENSE for details.
##


import re

from edgedb.lang.common import ast, parsing


class Base(ast.AST):
    ns = 'graphql'

    __ast_hidden__ = {'context'}
    context: parsing.ParserContext = None

    def _extra_repr(self):
        return ''

    def __repr__(self):
        ar = self._extra_repr()
        return '<{}.{} at {:#x}{}>'.format(self.__class__.ns,
                                           self.__class__.__name__,
                                           id(self),
                                           ar)


class LiteralNode(Base):
    value: object

    def topython(self):
        return self.value


class StringLiteral(LiteralNode):
    def tosource(self):
        value = self.value
        # generic substitutions for '\b' and '\f'
        #
        value = value.replace('\b', '\\b').replace('\f', '\\f')
        value = repr(value)
        # escape \b \f \u1234 and \/ correctly
        #
        value = re.sub(r'\\\\([fb])', r'\\\1', value)
        value = re.sub(r'\\\\(u[0-9a-fA-F]{4})', r'\\\1', value)
        value = value.replace('/', r'\/')

        if value[0] == "'":
            # need to change quotation style
            #
            value = value[1:-1].replace(R'\'', "'").replace('"', R'\"')
            value = '"' + value + '"'

        return value


class IntegerLiteral(LiteralNode):
    pass


class FloatLiteral(LiteralNode):
    pass


class BooleanLiteral(LiteralNode):
    pass


class EnumLiteral(LiteralNode):
    pass


class ListLiteral(LiteralNode):
    def topython(self):
        return [val.topython() for val in self.value]


class ObjectLiteral(LiteralNode):
    def topython(self):
        return {field.name: field.value.topython() for field in self.value}


class Variable(Base):
    value: object


class Document(Base):
    definitions: list


class Definition(Base):
    name: str = None
    selection_set: object


class OperationDefinition(Definition):
    type: str = None
    variables: list
    directives: list


class FragmentDefinition(Definition):
    on: object
    directives: list


class VariableDefinition(Base):
    name: object
    type: object
    value: object


class VariableType(Base):
    name: object
    nullable: bool = True
    list: bool = False


class SelectionSet(Base):
    selections: list


class Selection(Base):
    pass


class Field(Selection):
    alias: str = None
    name: object = None
    arguments: list
    directives: list
    selection_set: object


class FragmentSpread(Selection):
    name: object
    directives: list


class InlineFragment(Selection):
    on: object
    directives: list
    selection_set: object


class Directive(Base):
    name: object
    arguments: list


class Argument(Base):
    name: object
    value: object


class ObjectField(Base):
    name: object
    value: object
{'fraction_non_alphanumeric': 0.13909062203978528, 'fraction_numerical': 0.0050520997789706345, 'mean_word_length': 2.139246778989098, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5078698', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1849, 'n_words': 488}