* camlp4 3.10 and ints
@ 2007-06-13 11:40 Richard Jones
2007-06-13 12:17 ` [Caml-list] " Jeremy Yallop
2007-06-13 12:31 ` Nicolas Pouillard
0 siblings, 2 replies; 3+ messages in thread
From: Richard Jones @ 2007-06-13 11:40 UTC (permalink / raw)
To: caml-list
I'm getting some odd errors with camlp4 (3.10) and integers.
Firstly, INT returns a string, rather than an int, and similarly
$int:...$ expects a string instead of an int. I can live with this,
but it seems a bit strange, and unless I'm mistaken is different from
what camlp4 <= 3.09 did.
Secondly, I get the error 'Failure: "Integer literal exceeds the range
of representable integers of type int"' if I try to pass a string
containing any int32 or int64 literal, eg. $int:"0x3ffL"$, even ones
which obviously do not exceed the range of representable integers.
To demonstrate this second one, save the following to files:
-------------------------------------------------- pa_test.ml ---
open Camlp4.PreCast
open Syntax
let expand_test _loc () =
<:str_item< value test = $int:"0x3ffL"$ >>
EXTEND Gram
GLOBAL: str_item;
str_item: LEVEL "top" [
[ "TEST" -> expand_test _loc () ]
];
END;;
--------------------------------------------------
-------------------------------------------------- test.ml ---
TEST
--------------------------------------------------
And then compile with:
$ ocamlc -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I +camlp4 -c pa_test.ml
$ ocamlc -pp "camlp4o ./pa_test.cmo" test.ml
File "test.ml", line 1, characters 0-4:
Failure: "Integer literal exceeds the range of representable integers of type int"
Preprocessor error
Are these bugs or am I missing something?
Rich.
--
Richard Jones
Red Hat
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] camlp4 3.10 and ints
2007-06-13 11:40 camlp4 3.10 and ints Richard Jones
@ 2007-06-13 12:17 ` Jeremy Yallop
2007-06-13 12:31 ` Nicolas Pouillard
1 sibling, 0 replies; 3+ messages in thread
From: Jeremy Yallop @ 2007-06-13 12:17 UTC (permalink / raw)
To: caml-list
Richard Jones wrote:
> $int:...$ expects a string instead of an int. I can live with this,
> but it seems a bit strange, and unless I'm mistaken is different from
> what camlp4 <= 3.09 did.
The old camlp4 did this as well. The new one has an extra feature,
though: there's an antiquotation
$`int:...$
which expects an int.
> Secondly, I get the error 'Failure: "Integer literal exceeds the range
> of representable integers of type int"' if I try to pass a string
> containing any int32 or int64 literal, eg. $int:"0x3ffL"$, even ones
> which obviously do not exceed the range of representable integers.
For int32 and int64 there are antiquotations $int32:...$, $`int3:...$, etc.
Jeremy.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] camlp4 3.10 and ints
2007-06-13 11:40 camlp4 3.10 and ints Richard Jones
2007-06-13 12:17 ` [Caml-list] " Jeremy Yallop
@ 2007-06-13 12:31 ` Nicolas Pouillard
1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Pouillard @ 2007-06-13 12:31 UTC (permalink / raw)
To: Richard Jones; +Cc: caml-list
On 6/13/07, Richard Jones <rich@annexia.org> wrote:
> I'm getting some odd errors with camlp4 (3.10) and integers.
Thanks to Jeremy Yallop for responding to this. I then just add a few bits...
>
> Firstly, INT returns a string, rather than an int, and similarly
> $int:...$ expects a string instead of an int. I can live with this,
> but it seems a bit strange, and unless I'm mistaken is different from
> what camlp4 <= 3.09 did.
Not it's not different and the reason is simple. Camlp4 wants to keep
the representation of your integer and turning it to int will
normalize it ("42", "4_2", "0000042", "0b0101010"...).
With 3.10 you also have active antiquotations $`int:...$ $`int32:...$ for that.
Conversely on the parser side you can also get integers instead of
string by using real patterns in your production rule.
old_prod:
[[ s = INT -> (* s is a string *) ... ]];
new_prod:
[[ `INT(i, s) -> (* i is an integer and s its representation *) ... ]];
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-06-13 12:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-13 11:40 camlp4 3.10 and ints Richard Jones
2007-06-13 12:17 ` [Caml-list] " Jeremy Yallop
2007-06-13 12:31 ` Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox