How to use the tatsu.util.asjson function in TatSu

To help you get started, we’ve selected a few TatSu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pierky / arouteserver / tests / static / test_rpsl_syntax.py View on Github external
def test_exp_result(self):

        def print_exp_res():
            res = "\n"
            res += " cat < {}".format(exp_res_file) + "\n"
            res += json.dumps(dic, indent=2) + "\n"
            res += "EOF" + "\n"
            res += "\n"
            return res

        self.maxDiff = None

        parser = RPSLViaParser()
        ast = parser.parse(line, rule_name="start")
        dic = asjson(ast)

        if exp_res:
            self.assertDictEqual(dic, exp_res, "\n\nTo fix it:\n{}".format(print_exp_res()))
            return

        print(print_exp_res())
github pierky / arouteserver / tests / static / test_rpsl_syntax.py View on Github external
def _test_syntax(self, line):
        parser = RPSLViaParser()
        ast = parser.parse(line, rule_name="start")

        # Build the reverse statement starting from the result of the parser
        # and check that it matches the input line.
        # Do this only when there are no actions in the original line, too
        # much effort to rebuild the action list.
        if "action" in line:
            return

        dic = asjson(ast)

        from_to = "from" if dic["action"] == "import-via:" else "to"
        accept_announce = "accept" if dic["action"] == "import-via:" else "announce"

        s = "{action} {afi} {rules} {filter}".format(
            action=dic["action"],
            afi="afi {afi_list}".format(
                afi_list=" ".join([afi for afi in dic["afi"]])
            ) if dic["afi"] else "",
            rules=" ".join([
                "{via} {from_to} {peers}".format(
                    from_to=from_to,
                    via="{intermediate_as} {router}".format(
                        intermediate_as=rule["via"]["intermediate_as"],
                        router="{peer} {at} {local}".format(
                            peer=rule["via"]["router"]["peer_router"]
github robbert-harms / MDT / mdt / models / parsers / CompositeModelExpression.py View on Github external
with open(filename) as f:
            text = f.read()
    parser = CompositeModelExpressionParser()
    return parser.parse(text, rule_name=start, filename=filename, **kwargs)


if __name__ == '__main__':
    import json
    from tatsu.util import asjson

    ast = generic_main(main, CompositeModelExpressionParser, name='CompositeModelExpression')
    print('AST:')
    print(ast)
    print()
    print('JSON:')
    print(json.dumps(asjson(ast), indent=2))
    print()
github neogeny / TatSu / examples / calc / v4 / calc_parser.py View on Github external
with open(filename) as f:
        text = f.read()
    parser = CalcParser()
    return parser.parse(text, startrule, filename=filename, **kwargs)


if __name__ == '__main__':
    import json
    from tatsu.util import asjson

    ast = generic_main(main, CalcParser, name='Calc')
    print('AST:')
    print(ast)
    print()
    print('JSON:')
    print(json.dumps(asjson(ast), indent=2))
    print()
github neogeny / TatSu / tatsu / objectmodel.py View on Github external
def asjson(self):
        return asjson(self)
github microsoft / TextWorld / textworld / logic / parser.py View on Github external
with open(filename) as f:
            text = f.read()
    parser = GameLogicParser()
    return parser.parse(text, rule_name=start, filename=filename, **kwargs)


if __name__ == '__main__':
    import json
    from tatsu.util import asjson

    ast = generic_main(main, GameLogicParser, name='GameLogic')
    print('AST:')
    print(ast)
    print()
    print('JSON:')
    print(json.dumps(asjson(ast), indent=2))
    print()
github neogeny / TatSu / examples / regex / parser_base.py View on Github external
with open(filename) as f:
        text = f.read()
    parser = RegexParser()
    return parser.parse(text, startrule, filename=filename, **kwargs)


if __name__ == '__main__':
    import json
    from tatsu.util import asjson

    ast = generic_main(main, RegexParser, name='Regex')
    print('AST:')
    print(ast)
    print()
    print('JSON:')
    print(json.dumps(asjson(ast), indent=2))
    print()
github robbert-harms / MOT / mot / parsers / cl / CLDataType.py View on Github external
with open(filename) as f:
            text = f.read()
    parser = CLDataTypeParser()
    return parser.parse(text, rule_name=start, filename=filename, **kwargs)


if __name__ == '__main__':
    import json
    from tatsu.util import asjson

    ast = generic_main(main, CLDataTypeParser, name='CLDataType')
    print('AST:')
    print(ast)
    print()
    print('JSON:')
    print(json.dumps(asjson(ast), indent=2))
    print()