forked from jaked/froc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
froc-syntax package for Lwt-style lbt x = y, lft x = y
- Loading branch information
Showing
6 changed files
with
94 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name = "froc-syntax" | ||
version = "0.2" | ||
description = "syntax extension for froc" | ||
archive(syntax,preprocessor) = "pa_froc.cmo" | ||
archive(syntax,toploop) = "pa_froc.cmo" |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-include ../../Makefile.conf | ||
|
||
FILES=\ | ||
pa_froc.cmo pa_froc.mli pa_froc.cmi \ | ||
|
||
BFILES=$(addprefix _build/,$(FILES)) | ||
|
||
all: myocamlbuild.ml | ||
ocamlbuild pa_froc.cmo | ||
|
||
doc: | ||
|
||
install: | ||
ocamlfind install froc-syntax META $(BFILES) | ||
|
||
uninstall: | ||
ocamlfind remove froc-syntax | ||
|
||
clean: | ||
ocamlbuild -clean | ||
rm -f myocamlbuild.ml | ||
|
||
myocamlbuild.ml: | ||
ln -s ../../tools/myocamlbuild.ml . |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<pa_froc.ml*> : syntax_camlp4o,pkg_camlp4.quotations.o,pkg_camlp4.extend |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
(* | ||
* This file is part of froc, a library for functional reactive programming | ||
* Copyright (C) 2009-2010 Jacob Donham | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public | ||
* License along with this library; if not, write to the Free | ||
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | ||
* MA 02111-1307, USA | ||
*) | ||
|
||
(* adapted from pa_lwt.ml in Lwt distribution, Copyright (C) 2009 Jérémie Dimino *) | ||
|
||
open Camlp4 | ||
open Camlp4.PreCast | ||
open Syntax | ||
|
||
let gen_bind id l e = | ||
let _loc = Loc.ghost in | ||
|
||
(* XXX handle > 7 args; if we generate nested binds, must eval args up front like pa_lwt *) | ||
let body = | ||
List.fold_right | ||
(fun (_loc, p, _) e -> <:expr< fun $p$ -> $e$ >>) | ||
l | ||
e in | ||
|
||
let id = | ||
match List.length l with | ||
| 1 -> id | ||
| n -> id ^ string_of_int n in | ||
|
||
let bind = | ||
List.fold_left | ||
(fun e (_loc, _, e') -> <:expr< $e$ $e'$ >>) | ||
<:expr< Froc.$lid:id$ >> | ||
l in | ||
|
||
<:expr< $bind$ $body$ >> | ||
|
||
EXTEND Gram | ||
GLOBAL: expr str_item; | ||
|
||
letb_binding: | ||
[ [ b1 = SELF; "and"; b2 = SELF -> b1 @ b2 | ||
| p = patt; "="; e = expr -> [(_loc, p, e)] | ||
] ]; | ||
|
||
expr: LEVEL "top" | ||
[ [ "lbt"; l = letb_binding; "in"; e = expr LEVEL ";" -> gen_bind "bind" l e | ||
| "lft"; l = letb_binding; "in"; e = expr LEVEL ";" -> gen_bind "blift" l e | ||
] ]; | ||
END |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
(** syntax extension for lbt x = y in, lft x = y in*) |