ppparse / README

****************************************
  ppparse -- a simple parser generator
****************************************

The ``ppparse`` package generates a lexical scanner and a syntax parser for the
given grammar.  Use it as in the following example::

    from ppparse import make_scan, make_parse

    scan = make_scan("""
        SPACE   : [\s]+
                !skip
        NUMBER  : [\d]+
        SYMBOL  : [()*/+-]
                !symbol
    """)

    parse = make_parse("""
        expr    : term
                | expr `+` term
                | expr `-` term
        term    : factor
                | term `*` factor
                | term `/` factor
        factor  : atom
                | `+` factor
                | `-` factor
        atom    : NUMBER
                | `(` expr `)`
    """)

    text = "(-4+15)*4 - 2"
    tokens = scan(text)
    syntax = parse(tokens)

The function ``scan()`` generated by ``make_scan()`` takes a string or an open
file as input and produces a list of ``Token`` objects.  The function
``parse()`` generated by ``make_parse()`` takes a list of ``Token`` objects and
produces a syntax tree composed of ``Syntax`` and ``Token`` objects.

A ``Token`` instance has the following attributes:

``code``: ``unicode``
    The token type; usually coincides with the name of the production rule
    which matched the token.
``text``: ``unicode``
    The token value.

Each ``Syntax`` instance has the following attributes:

``code``: ``unicode``
    The type of the syntax node; coincides with the name of the rule which
    produced the node.
``arms``: list of ``Syntax`` and ``Token`` objects
    Nodes which matched the production rule.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.