Beispiel #1
0
    def setUp(self):
        super().setUp()

        g = GrammarBuilder()
        g.number_literal = Regexp(r'-?(?:[1-9]\d*|0)(?:\.\d*)?(?:[eE][+-]?\d+)?')
        g.string_literal = Regexp(r'"(?:[^"]|\\(?:["\\nbfrt]|u[0-9a-fA-F]{4}))*"')
        g.array = '[' + flatten(repeat(g.expr, separator=drop(','))) + ']'
        g.object_ = '{' + flatten(repeat(flatten(g.string_literal + ':' + g.expr), separator=',')) + '}'
        g.expr = flatten(g.number_literal | g.string_literal | g.array | g.object_)
        g.whitespace = Regexp('\\s+')

        self.grammar = g(start=g.expr, tokenize=[ignore(g.whitespace)], drop_terminals=True)
Beispiel #2
0
    def setUp(self):
        super().setUp()

        g = GrammarBuilder()
        g.number_literal = Regexp(r'-?(?:[1-9]\d*|0)(?:\.\d*)?(?:[eE][+-]?\d+)?') >= float
        g.string_literal = Regexp(r'"(?:[^"]|\\(?:["\\nbfrt]|u[0-9a-fA-F]{4}))*"') >= (lambda s: s[1:-1])
        g.array = '[' + flatten(repeat(g.expr, separator=',')) + ']' >= list
        g.object_item = g.string_literal + ':' + g.expr >= tuple
        g.object_ = '{' + flatten(repeat(g.object_item, separator=',')) + '}' >= dict
        g.boolean = keep('true') | keep('false') >= (lambda s: s == 'true')
        g.null = keep('null') >= const(None)
        g.expr = flatten(g.number_literal | g.string_literal | g.array | g.object_ | g.boolean | g.null)
        g.whitespace = Regexp('\\s+')
        self.grammar = g(start=g.expr, tokenize=[ignore(g.whitespace)], drop_terminals=True)
Beispiel #3
0
    def setUp(self):
        super().setUp()

        g = GrammarBuilder()
        g.number_literal = Regexp(
            r'-?(?:[1-9]\d*|0)(?:\.\d*)?(?:[eE][+-]?\d+)?')
        g.string_literal = Regexp(
            r'"(?:[^"]|\\(?:["\\nbfrt]|u[0-9a-fA-F]{4}))*"')
        g.array = '[' + flatten(repeat(g.expr, separator=drop(','))) + ']'
        g.object_ = '{' + flatten(
            repeat(flatten(g.string_literal + ':' + g.expr),
                   separator=',')) + '}'
        g.expr = flatten(g.number_literal | g.string_literal | g.array
                         | g.object_)
        g.whitespace = Regexp('\\s+')

        self.grammar = g(start=g.expr,
                         tokenize=[ignore(g.whitespace)],
                         drop_terminals=True)
Beispiel #4
0
    def setUp(self):
        super().setUp()

        g = GrammarBuilder()
        g.number_literal = Regexp(
            r'-?(?:[1-9]\d*|0)(?:\.\d*)?(?:[eE][+-]?\d+)?') >= float
        g.string_literal = Regexp(
            r'"(?:[^"]|\\(?:["\\nbfrt]|u[0-9a-fA-F]{4}))*"') >= (
                lambda s: s[1:-1])
        g.array = '[' + flatten(repeat(g.expr, separator=',')) + ']' >= list
        g.object_item = g.string_literal + ':' + g.expr >= tuple
        g.object_ = '{' + flatten(repeat(g.object_item,
                                         separator=',')) + '}' >= dict
        g.boolean = keep('true') | keep('false') >= (lambda s: s == 'true')
        g.null = keep('null') >= const(None)
        g.expr = flatten(g.number_literal | g.string_literal | g.array
                         | g.object_ | g.boolean | g.null)
        g.whitespace = Regexp('\\s+')
        self.grammar = g(start=g.expr,
                         tokenize=[ignore(g.whitespace)],
                         drop_terminals=True)