-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace earley by pacomb in examples.
- Loading branch information
Showing
4 changed files
with
27 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(test | ||
(name main) | ||
(preprocess (per_module ((action (run pa_ocaml %{input-file})) parser))) | ||
(libraries bindlib earley.core timed) | ||
(preprocess (per_module ((pps pacomb.ppx) parser))) | ||
(libraries bindlib unix pacomb timed) | ||
(action (with-stdin-from test.txt (run %{test})))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
open Earley_core | ||
open Pacomb | ||
open Ast | ||
|
||
let parser ident = id:{#[a-z0-9][_a-zA-Z0-9]*[']*#}[group.(0)] | ||
let%parser ident = (id::RE"[a-z0-9][_a-zA-Z0-9]*[']*") => id | ||
|
||
let parser term_atom = | ||
| id:ident -> PVar id | ||
| '(' t:term_full ')' -> t | ||
| '[' t:term_full ']' -> PNrm t | ||
let%parser rec term_atom = | ||
(id::ident) => PVar id | ||
; '(' (t::term_full) ')' => t | ||
; '[' (t::term_full) ']' => PNrm t | ||
|
||
and parser term_appl = | ||
| term_atom | ||
| t:term_appl u:term_atom -> PApp(t,u) | ||
and term_appl = | ||
(t::term_atom) => t | ||
; (t::term_appl) (u::term_atom) => PApp(t,u) | ||
|
||
and parser term_full = | ||
| term_appl | ||
| {"λ"|"%"} ids:ident* '.' t:term_full -> many_PLam ids t | ||
and term_full = | ||
(t::term_appl) => t | ||
; ("λ" => () ; "%" => ()) (ids:: ~* ident) '.' (t::term_full) | ||
=> many_PLam ids t | ||
|
||
let parser command = | ||
| "$u" -> Undo | ||
| "$g" -> Goal | ||
| "$s" x:ident "=" t:term_full -> Decl(x,t) | ||
| "$p" t:term_full -> Prnt(t) | ||
let%parser command = | ||
"$u" => Undo | ||
; "$g" => Goal | ||
; "$s" (x::ident) "=" (t::term_full) => Decl(x,t) | ||
; "$p" (t::term_full) => Prnt(t) | ||
|
||
let parser commands = {command ";"}* | ||
let%parser commands = cs :: ~* ((c::command) ";" => c) => cs | ||
|
||
let blank = Blank.line_comments "//" | ||
|
||
let parse_channel : in_channel -> cmd list = fun ic -> | ||
let blank = Blanks.line_comments "//" in | ||
let parse = Earley.parse_buffer commands blank in | ||
Earley.handle_exception parse (Input.from_channel ic) | ||
let parse = Grammar.parse_channel commands blank in | ||
Pos.handle_exception parse ic |