<commit_before>""" Parsing utilities for Polly's ScheduleTree representation. """
import logging
import textwrap as t
import pyparsing as p


LOG = logging.getLogger(__name__)


class Node(object):
    def __init__(self, tok):
        self.name = tok[0]
        self.value = tok[2]
    
    def indent(self, level=0, idt=' '):
        val = self.value
        if not isinstance(self.value, str):
            val = self.value.indent(level)
        return t.indent('"{:s}": "{:s}"'.format(self.name, val), level*idt)


class CoincidenceNode(object):
    def __init__(self, tok):
        self.name = tok[0]
        self.children = tok[3]

    def indent(self, level=0, idt=' '):
        ret = [str(child) for child in self.children]
        ret = ",".join(ret)

        return t.indent('"{:s}": [{:s}]'.format(self.name, ret), level*idt)

class RootNode(object):
    def __init__(self, tok):
        self.name = tok[0]
        self.children = tok[1]

    def indent(self, level=0, idt=' '):
        ret = []
        for r in self.children:
            ret += r.indent(level+2)
        ret = [child.indent(level+2) for child in self.children]
        ret = ",\n".join(ret)

        return t.indent('{{\n{:s}\n}}'.format(ret), level*idt)

    def __str__(self):
        return self.indent(0)


class ChildNode(RootNode):
    def __init__(self, tok):
        self.elem = tok[0]

    def indent(self, level=0, idt=' '):
        ret = self.elem.indent(level)
        return t.indent(ret, level*idt)

class SequenceNode(object):
    def __init__(self, tok):
        self.name = tok[0]
        self.children = tok[3]

    def indent(self, level=0, idt=' '):
        ret = '"{:s}": [\n'.format(self.name)
        for child in self.children:
            ret += child.indent(level+2) + ',\n'
        ret += '\n]'
        return t.indent(ret, level * idt)


_NUM = p.Word(p.nums, max=1)
_NUM_LIST = p.Group(p.delimitedList(_NUM))

_STR = p.QuotedString('"')

_KW_CHILD = p.Keyword("child")
_KW_COINCIDENT = p.Keyword("coincident")
_KW_DOMAIN = p.Keyword("domain")<commit_msg>schedule_tree: fix indentation errors<commit_after>""" Parsing utilities for Polly's ScheduleTree representation. """
import logging
import textwrap as t
import pyparsing as p


LOG = logging.getLogger(__name__)


class Node(object):
    def __init__(self, tok):
        self.name = tok[0]
        self.value = tok[2]
    
    def indent(self, level=0, idt=' '):
        val = self.value
        if not isinstance(self.value, str):
            val = self.value.indent(1)
        return t.indent('"{:s}": "{:s}"'.format(self.name, val), level*idt)


class CoincidenceNode(object):
    def __init__(self, tok):
        self.name = tok[0]
        self.children = tok[3]

    def indent(self, level=0, idt=' '):
        ret = [str(child) for child in self.children]
        ret = ",".join(ret)

        return t.indent('"{:s}": [{:s}]'.format(self.name, ret), level*idt)

class RootNode(object):
    def __init__(self, tok):
        self.name = tok[0]
        self.children = tok[1]

    def indent(self, level=0, idt=' '):
        ret = []
        for r in self.children:
            ret += r.indent(level+2)
        ret = [child.indent(level+2) for child in self.children]
        ret = ",\n".join(ret)

        return t.indent('{{\n{:s}\n}}'.format(ret), level*idt)

    def __str__(self):
        return self.indent(0)


class ChildNode(RootNode):
    def __init__(self, tok):
        self.elem = tok[0]

    def indent(self, level=0, idt=' '):
        ret = self.elem.indent(level)
        return ret

class SequenceNode(object):
    def __init__(self, tok):
        self.name = tok[0]
        self.children = tok[3]

    def indent(self, level=0, idt=' '):
        ret = '"{:s}": [\n'.format(self.name)
        for child in self.children:
            ret += child.indent(0) + ',\n'
        ret += '\n]'
        return t.indent(ret, level * idt)


_NUM = p.Word(p.nums, max=1)
_NUM_LIST = p.Group(p.delimitedList(_NUM))

_STR = p.QuotedString('"')

_KW_CHILD = p.Keyword("child")
_KW_COINCIDENT = p.Keyword("coincident")
_KW_DOMAIN = p.Keyword("domain")
{'fraction_non_alphanumeric': 0.16500607533414338, 'fraction_numerical': 0.009477521263669502, 'mean_word_length': 2.5729166666666665, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '951508', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1439, 'n_words': 329}