rivescript.parser.Parser

Here are the examples of the python api rivescript.parser.Parser taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

Example 1

Project: rivescript-python Source File: parse.py
Function: main
def main():
    # Get the command line argument.
    filename = "../brain/clients.rive"
    if len(sys.argv) > 1:
        filename = sys.argv[1]

    # Make sure it's really a file.
    if not os.path.isfile(filename):
        print("{}: Not a file.".format(filename))
        sys.exit(1)

    # Make sure it looks like a RiveScript file.
    if not filename.lower().endswith(".rive"):
        print("{}: Doesn't look like a RiveScript file (no .rive extension)")
        sys.exit(1)

    # Create a parser instance.
    if os.environ.get("PARSER_DEBUG"):
        parser = Parser(
            on_debug=on_debug,
            on_warn=on_warn,
        )
    else:
        parser = Parser()

    # Read the file's contents.
    with codecs.open(filename, "r", "utf-8") as fh:
        source = fh.readlines()

        # Create a parser and parse it.
        ast = parser.parse(filename, source)

        # Dump the "Abstract Syntax Tree" to the console as JSON.
        print(json.dumps(ast, indent=2, sort_keys=True))