summaryrefslogtreecommitdiff
path: root/src/parser.ml
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2022-04-02 00:13:13 +0300
committerDaniil Baturin <daniil@vyos.io>2022-04-21 18:41:51 +0300
commit3f86b8278389ae9978cbce1d45be6f03ed29035a (patch)
tree1907c5e02b635c426a43904f85358c56406a8546 /src/parser.ml
parent6725043051d20f0211da184dd0aab77472873fcf (diff)
downloadvyos1x-config-3f86b8278389ae9978cbce1d45be6f03ed29035a.tar.gz
vyos1x-config-3f86b8278389ae9978cbce1d45be6f03ed29035a.zip
T4334: make the lexer reentrant by passing state around
instead of using a shared mutable reference
Diffstat (limited to 'src/parser.ml')
-rw-r--r--src/parser.ml11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/parser.ml b/src/parser.ml
index b334a20..f659b34 100644
--- a/src/parser.ml
+++ b/src/parser.ml
@@ -3,18 +3,18 @@ open Lexing
module I = Vyos1x_parser.MenhirInterpreter
-let rec parse lexbuf (checkpoint : Config_tree.t I.checkpoint) =
+let rec parse vy_inside_node lexbuf (checkpoint : Config_tree.t I.checkpoint) =
match checkpoint with
| I.InputNeeded _env ->
- let token = Vyos1x_lexer.token lexbuf in
+ let vy_inside_node, token = Vyos1x_lexer.token vy_inside_node lexbuf in
let startp = lexbuf.lex_start_p
and endp = lexbuf.lex_curr_p in
let checkpoint = I.offer checkpoint (token, startp, endp) in
- parse lexbuf checkpoint
+ parse vy_inside_node lexbuf checkpoint
| I.Shifting _
| I.AboutToReduce _ ->
let checkpoint = I.resume checkpoint in
- parse lexbuf checkpoint
+ parse vy_inside_node lexbuf checkpoint
| I.HandlingError _env ->
let line, pos = Util.get_lexing_position lexbuf in
raise (Syntax_error (Some (line, pos), "Invalid syntax."))
@@ -23,5 +23,6 @@ let rec parse lexbuf (checkpoint : Config_tree.t I.checkpoint) =
raise (Syntax_error (None, "invalid syntax (parser rejected the input)"))
let from_string s =
+ let vy_inside_node = false in
let lexbuf = Lexing.from_string s in
- parse lexbuf (Vyos1x_parser.Incremental.config lexbuf.lex_curr_p)
+ parse vy_inside_node lexbuf (Vyos1x_parser.Incremental.config lexbuf.lex_curr_p)