UCSD-PL/nano-js — pull request #23 by panagosg7 (2013-12-29 02:54:38+00:00)
Title: Heapless parser

CHANGELOG
---------------------
- Valid specifications at the moment are:
- Measure: as before
- Bindings: for defined functions
- Extern: for imported functions (no body, no checks). This distinguishes imported specs from the signatures of the defined functions.
- Type definitions: as before
- Type aliases: as added by Ranjit
- Predicate aliases: as added by Ranjit
- Qualifiers
- Invariants

These will be parsed only within top-level comments -- not anywhere within the code.

There is no notion of spec file vs code file. Specs can be in any file and within liquid-style comments (`/*@ ... */`).

- Variable declarations can be annotated with a type in the following way:
```
var x /*@ { v: B | p } */ = e;
```
These annotations are checked at initialization and used later on for assignment checks. I.e.:
```
x = e;
```
Will look up `x` for an annotation and use that for the subtyping constraint.

Mutability is treated in a similar fashion as before.

Global variables are not treated as global function, because scoping differs (though not modeled correctly yet), so they are stored separately.

- As for the implementation: parsers are passed over to language ecmascript to be used in the usual places for each annotation token. Tricky bits: moving back and forth between the two parser states.

- `prelude.js` and all (?) tests has been changed to reflect these changes.

Issues
----------
- There is a parsing **bug** in code of the form:
```
var x = { ... }
/*@ foo :: () => void */
...
```
In particular the closing bracket of the object literal (`{`) when combined with the slash (`/`) from the upcoming annotation is partially parsed as a division expression, without the possibility of fallback because of the use of expression tables. The parser that parses the annotation is passed from nano-js, while the rest of the parsing is done withing language-ecmascript.