Skip to content

Commit

Permalink
froc-syntax package for Lwt-style lbt x = y, lft x = y
Browse files Browse the repository at this point in the history
  • Loading branch information
duckpilot committed Jul 13, 2010
1 parent e3671ae commit 0f444d0
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 1 deletion.
2 changes: 1 addition & 1 deletion configure
Expand Up @@ -214,7 +214,7 @@ echo "Effective options:"
print_options
echo

pkglist="froc"
pkglist="froc froc-syntax"

if [ $enable_ocamljs -gt 0 ]; then
pkglist="$pkglist froc-dom"
Expand Down
5 changes: 5 additions & 0 deletions src/froc-syntax/META
@@ -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"
24 changes: 24 additions & 0 deletions src/froc-syntax/Makefile
@@ -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 .
1 change: 1 addition & 0 deletions src/froc-syntax/_tags
@@ -0,0 +1 @@
<pa_froc.ml*> : syntax_camlp4o,pkg_camlp4.quotations.o,pkg_camlp4.extend
62 changes: 62 additions & 0 deletions src/froc-syntax/pa_froc.ml
@@ -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
1 change: 1 addition & 0 deletions src/froc-syntax/pa_froc.mli
@@ -0,0 +1 @@
(** syntax extension for lbt x = y in, lft x = y in*)

0 comments on commit 0f444d0

Please sign in to comment.