aboutsummaryrefslogtreecommitdiff
path: root/lib/qparser/lexbuf.ml
diff options
context:
space:
mode:
authorChimrod <>2023-10-26 17:16:36 +0200
committerChimrod <>2023-11-02 11:06:12 +0100
commit4f5e33ef7b96d6daee29ff1088ea381b9302f846 (patch)
treedadb90693a78866bbc63725a4eb5ee29c6459b0c /lib/qparser/lexbuf.ml
parentdc1ae31617bc4c3cfaefc518971bbb153149ca86 (diff)
Used the same state for the expression levels
Diffstat (limited to 'lib/qparser/lexbuf.ml')
-rw-r--r--lib/qparser/lexbuf.ml36
1 files changed, 13 insertions, 23 deletions
diff --git a/lib/qparser/lexbuf.ml b/lib/qparser/lexbuf.ml
index 61f86cd..af8c48a 100644
--- a/lib/qparser/lexbuf.ml
+++ b/lib/qparser/lexbuf.ml
@@ -1,9 +1,14 @@
-type state = Token | String | DString | MString of int | EndString
+type state =
+ | Token
+ | String
+ | DString
+ | MString of int
+ | EndString
+ | Expression
type t = {
buffer : Sedlexing.lexbuf;
mutable start_p : Lexing.position option;
- mutable expression_level : int;
state : state Stack.t;
reset_line : bool;
}
@@ -17,8 +22,7 @@ let start : t -> unit =
if not t.reset_line then
Sedlexing.set_position t.buffer { end_pos with Lexing.pos_lnum = 1 }
in
- t.start_p <- None;
- t.expression_level <- 0
+ t.start_p <- None
let positions : t -> Lexing.position * Lexing.position =
fun t ->
@@ -30,13 +34,7 @@ let content : t -> string = fun t -> Sedlexing.Utf8.lexeme t.buffer
let from_lexbuf : ?reset_line:bool -> Sedlexing.lexbuf -> t =
fun ?(reset_line = true) t ->
- {
- buffer = t;
- start_p = None;
- expression_level = 0;
- reset_line;
- state = Stack.create ();
- }
+ { buffer = t; start_p = None; reset_line; state = Stack.create () }
let set_start_position : t -> Lexing.position -> unit =
fun t position ->
@@ -63,22 +61,14 @@ let tokenize : (t -> 'a) -> t -> unit -> 'a * Lexing.position * Lexing.position
lexer
let rollback : t -> unit = fun t -> Sedlexing.rollback t.buffer
-let state : t -> state option = fun t -> Stack.top_opt t.state
-let enter_state : t -> state -> unit = fun t state -> Stack.push state t.state
-let leave_state : t -> unit = fun t -> ignore (Stack.pop_opt t.state)
-(* The comment system is terrible. The same symbol can be used for :
+(** The comment system is terrible. The same symbol can be used for :
- starting a comment
- inequality operation
In order to manage this, I try to identify the context in a very basic way,
using a counter for determining the token to send.
*)
+let state : t -> state option = fun t -> Stack.top_opt t.state
-let incr_level : t -> unit =
- fun t -> t.expression_level <- t.expression_level + 1
-
-let decr_level : t -> unit =
- fun t -> t.expression_level <- t.expression_level - 1
-
-let reset_level : t -> unit = fun t -> t.expression_level <- 0
-let level : t -> int = fun t -> t.expression_level
+let enter_state : t -> state -> unit = fun t state -> Stack.push state t.state
+let leave_state : t -> unit = fun t -> ignore (Stack.pop_opt t.state)