Skip to content

Commit

Permalink
Bootsrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitrii Dimandt committed Jul 23, 2014
1 parent 1eb7f4b commit a3ee389
Show file tree
Hide file tree
Showing 6 changed files with 1,674 additions and 598 deletions.
49 changes: 41 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ This is a rather straightforward port/implementation of the grammar defined for

## Current status

- This is a **beta** (at least, until bootstrapping is implemented)
- As far as I can tell, implements everything from the PEG.js grammar
- Generates complete useable parsers
- The project has not been bootstrapped yet (that is the parser is not yet
generated from the grammar by the parser itself)
- For now uses [Neotoma](https://github.com/seancribbs/neotoma) to generate the parser
- Is based on an earlier definition of the grammar (probably [this](https://github.com/dmajda/pegjs/blob/f0a6bc92cc24b623689c7811bebc1ce2921442f0/src/parser.pegjs))
- The project is bootstrapped (see `priv/pegjs_parse.pegjs`). Original grammar for
[Neotoma](https://github.com/seancribbs/neotoma) is also available in `priv/pegjs_parse.peg`
- It's based on an earlier definition of the grammar (probably [this](https://github.com/dmajda/pegjs/blob/f0a6bc92cc24b623689c7811bebc1ce2921442f0/src/parser.pegjs))
than the one that currently [exists](https://github.com/dmajda/pegjs/blob/master/src/parser.pegjs)
for PEG.js. Currenlty there's no timeframe or even a decision on when/whether to update the erlang version

## Further work

- Bootstrap
- Support @append (see, e.g. [core-pegjs](https://github.com/for-GET/core-pegjs)
in the for-GET project)
- Add more options:
Expand Down Expand Up @@ -59,7 +56,8 @@ There are several options you can pass along to `pegjs:file(File, Options::optio
-type option() :: {ignore_unused, boolean()} %% ignore unused rules. Default: true
| {ignore_duplicates, boolean()} %% ignore duplicate rules. Default: false
| {ignore_unparsed, boolean()} %% ignore incomplete parses. Default: false
| {ignore_missing_rules, boolean()}. %% Default: false
| {ignore_missing_rules, boolean()}, %% Default: false
| {parser, atom()}. %% use a different module to parse grammars. Default: pegjs_parse

```

Expand All @@ -75,10 +73,45 @@ branch of neotoma.

Non-generated parser combinators can be found in `priv/pegjs.template`.

To generate the `pegjs_parse` module, all you need is:
Safe working parser is always available at `src/pegjs_parse.erl.safe`.

### pegjs grammar

The current grammar from which the project is now bootstrapped lives in
`priv/pegjs_parser.pegjs`. When you've tweaked it and you want to try your changes,
generate a different module and tell `pegjs` to use your new module instead:

```erlang
> pegjs:file("priv/pegjs_parse.pegjs", [{output, "src"}, {module, modified_parser}]).
ok
> c(modified_parser).
{ok, modified_parser)
> pegjs:file("extra/json.pegjs", [{parser, modified_parser}]).
ok
... etc. ...
```

Once you're satisfied with your changes, overwrite pegjs_parser (which is used by default):
```erlang
> pegjs:file("priv/pegjs_parse.pegjs", [{output, "src"}]).
ok
> c(pegjs_parse).
{ok, pegjs_parse)
> pegjs:file("extra/json.pegjs").
ok
... etc. ...
```
### Original neotoma
The original parser for pegjs was derived from a grammar defined for [Neotoma](https://github.com/seancribbs/neotoma).
You can also start your work from there:
```erlang
> neotoma:file("priv/pegjs_parse.peg", [{output, "src/"}]).
ok
> pegjs:file(.... etc ... )
```
However, the original grammar will get increasingly outdated as time goes on, so it's there for reference only.
2 changes: 2 additions & 0 deletions priv/pegjs.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
%% -type index() :: {{line, pos_integer()}, {column, pos_integer()}}.
-type input() :: binary().
-ifndef(index).
-type index() :: {{line, integer()}, {column, integer()}}.
-endif.
-type parse_failure() :: {error, term()}.
-type parse_success() :: {term(), input(), index()}.
-type parse_result() :: parse_failure() | parse_success().
Expand Down
Loading

0 comments on commit a3ee389

Please sign in to comment.