summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>1995-07-11 08:54:13 +0000
committerXavier Leroy <xavier.leroy@inria.fr>1995-07-11 08:54:13 +0000
commit7068ced58387fc070ffb46db3959f25804c9dea9 (patch)
tree8153a84cf114a8e6dad1942278821bb58cb32766
parentc56071ab567f49d7eaefffd5f6ddbcfbae897ac0 (diff)
Lexing.get_next_char est maintenant en ML.
Utilisation des primitives %floatofint et %intoffloat. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@77 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--stdlib/lexing.ml20
-rw-r--r--stdlib/lexing.mli3
-rw-r--r--stdlib/pervasives.ml4
-rw-r--r--stdlib/pervasives.mli4
4 files changed, 24 insertions, 7 deletions
diff --git a/stdlib/lexing.ml b/stdlib/lexing.ml
index 07bb7b5df..17b0c753f 100644
--- a/stdlib/lexing.ml
+++ b/stdlib/lexing.ml
@@ -3,6 +3,7 @@
type lexbuf =
{ refill_buff : lexbuf -> unit;
lex_buffer : string;
+ lex_buffer_len : int;
mutable lex_abs_pos : int;
mutable lex_start_pos : int;
mutable lex_curr_pos : int;
@@ -31,6 +32,7 @@ let dummy_action x = failwith "lexing: empty token"
let from_function f =
{ refill_buff = lex_refill f;
lex_buffer = String.create 2048;
+ lex_buffer_len = 2048;
lex_abs_pos = - 2048;
lex_start_pos = 2048;
lex_curr_pos = 2048;
@@ -44,18 +46,32 @@ let from_string s =
{ refill_buff =
(fun lexbuf -> lexbuf.lex_curr_pos <- lexbuf.lex_curr_pos - 1);
lex_buffer = s ^ "\000";
+ lex_buffer_len = String.length s + 1;
lex_abs_pos = 0;
lex_start_pos = 0;
lex_curr_pos = 0;
lex_last_pos = 0;
lex_last_action = dummy_action }
-external get_next_char : lexbuf -> char = "get_next_char"
+let get_next_char lexbuf =
+ let p = lexbuf.lex_curr_pos in
+ if p < lexbuf.lex_buffer_len then begin
+ let c = String.unsafe_get lexbuf.lex_buffer p in
+ lexbuf.lex_curr_pos <- p + 1;
+ c
+ end else begin
+ lexbuf.refill_buff lexbuf;
+ let p = lexbuf.lex_curr_pos in
+ let c = String.unsafe_get lexbuf.lex_buffer p in
+ lexbuf.lex_curr_pos <- p + 1;
+ c
+ end
let lexeme lexbuf =
let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos in
let s = String.create len in
- String.unsafe_blit lexbuf.lex_buffer lexbuf.lex_start_pos s 0 len; s
+ String.unsafe_blit lexbuf.lex_buffer lexbuf.lex_start_pos s 0 len;
+ s
let lexeme_char lexbuf i =
String.get lexbuf.lex_buffer (lexbuf.lex_start_pos + i)
diff --git a/stdlib/lexing.mli b/stdlib/lexing.mli
index 1585da1f1..58041e923 100644
--- a/stdlib/lexing.mli
+++ b/stdlib/lexing.mli
@@ -5,6 +5,7 @@
type lexbuf =
{ refill_buff : lexbuf -> unit;
lex_buffer : string;
+ lex_buffer_len : int;
mutable lex_abs_pos : int;
mutable lex_start_pos : int;
mutable lex_curr_pos : int;
@@ -64,5 +65,5 @@ val lexeme_end : lexbuf -> int
They are not intended to be used by user programs. *)
val start_lexing : lexbuf -> unit
-external get_next_char : lexbuf -> char = "get_next_char"
+val get_next_char : lexbuf -> char
val backtrack : lexbuf -> 'a
diff --git a/stdlib/pervasives.ml b/stdlib/pervasives.ml
index 556190c8f..4bdd94c5f 100644
--- a/stdlib/pervasives.ml
+++ b/stdlib/pervasives.ml
@@ -73,8 +73,8 @@ external atan2 : float -> float -> float = "atan2_float"
let abs_float f = if f >= 0.0 then f else -. f
-external float : int -> float = "float_of_int"
-external truncate : float -> int = "int_of_float"
+external float : int -> float = "%floatofint"
+external truncate : float -> int = "%intoffloat"
(* String operations -- more in module String *)
diff --git a/stdlib/pervasives.mli b/stdlib/pervasives.mli
index eee570502..176ed2ec3 100644
--- a/stdlib/pervasives.mli
+++ b/stdlib/pervasives.mli
@@ -88,8 +88,8 @@ external acos : float -> float = "acos_float"
external atan : float -> float = "atan_float"
external atan2 : float -> float -> float = "atan2_float"
val abs_float : float -> float
-external float : int -> float = "float_of_int"
-external truncate : float -> int = "int_of_float"
+external float : int -> float = "%floatofint"
+external truncate : float -> int = "%intoffloat"
(* String operations -- more in module String *)