diff options
Diffstat (limited to 'lib/qparser/lexbuf.ml')
-rw-r--r-- | lib/qparser/lexbuf.ml | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/qparser/lexbuf.ml b/lib/qparser/lexbuf.ml index cd0add3..61f86cd 100644 --- a/lib/qparser/lexbuf.ml +++ b/lib/qparser/lexbuf.ml @@ -1,7 +1,10 @@ +type state = Token | String | DString | MString of int | EndString + type t = { buffer : Sedlexing.lexbuf; mutable start_p : Lexing.position option; mutable expression_level : int; + state : state Stack.t; reset_line : bool; } @@ -27,7 +30,13 @@ 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 } + { + buffer = t; + start_p = None; + expression_level = 0; + reset_line; + state = Stack.create (); + } let set_start_position : t -> Lexing.position -> unit = fun t position -> @@ -53,6 +62,11 @@ let tokenize : (t -> 'a) -> t -> unit -> 'a * Lexing.position * Lexing.position in 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 : - starting a comment - inequality operation @@ -68,4 +82,3 @@ let decr_level : t -> unit = let reset_level : t -> unit = fun t -> t.expression_level <- 0 let level : t -> int = fun t -> t.expression_level -let rollback : t -> unit = fun t -> Sedlexing.rollback t.buffer |