Turn Oil's expression grammar into an AST #387

Related: Tips on Using pgen2

Demo:

bin/osh -n -c 'var x = 1 + 2 * 3;'

This already works. (Right now semicolon or newline are accepted, we should also add EOF.)

Code

Related Code

Things We Want to Add

Implementation Details (vs. Python)

Testing Strategy

Generally I test things very quickly with osh -n -c, or an interactive shell, but we should somehow record those tests. The simplest thing to do is to write some Python unit tests that take strings and print out the AST. Maybe they don't even need to make assertions?

Update: I added a test driver, which you can run like this:

test/unit.sh unit oil_lang/expr_parse_test.py

It takes lines of code and prints out an AST.

If you want to print out the parse tree, turn on print_parse_tree in frontend/parse_lib.py ParseOilAssign.

NOTE: The way I hacked everything together was with pgen2/pgen2-test.sh all. (You can run less with a particular function in that file, like parse-exprs or oil-productions.) This worked pretty nicely, but I won't be surprised if others don't like this style or get confused by it :-/

Typing

The whole front end is statically typed with MyPy now. The types/osh-parse.sh script checks it in Travis.

I usually the code working, and then add types. However filling in types first is conceivable. ASDL types map to MyPy types in a straightforward way.

Building

See Contributing, but

build/dev.sh minimal

should be enough (on an Ubuntu/Debian machine).

Important: make sure to re-run this when changing frontend/syntax.asdl. The file _devbuild/gen/syntax_asdl.py needs to be regenerated.