[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Andre Nathan <andre@s...> |
| Subject: | Camlp4 help |
Hello
I'm just beginning with camlp4 here, and I'm stuck with what I think is
a precedence issue. I have the following syntax extension:
open Camlp4.PreCast
open Syntax
let sum = Gram.Entry.mk "sum"
EXTEND Gram
expr: LEVEL "top"
[ [ "sum"; "do"; seq = LIST1 sum; "done" ->
<:expr< do { $list:seq$ } >> ] ]
;
sum:
[ [ x = expr; "plus"; y = expr ->
<:expr< $x$ + $y$ >> ] ]
;
END
This works fine for something like this:
sum do
1 plus 2
done
which becomes (1 + 2).
However, it breaks on
sum do
let a = 1 in
let b = 2 in
a plus b
done
because it becomes ((let a = 1 in let b = 2 in a) + b).
How can fix that (allowing "b" to be in scope for the second argument of
"plus")?
Also, sequences of operations don't parse:
sum do
1 + 2;
3 + 4
done
gives "Parse error: [sum] or "done" expected (in [expr])"
What am I missing here?
Thanks in advance,
Andre