diff options
Diffstat (limited to 'lib/qparser/analyzer.ml')
-rw-r--r-- | lib/qparser/analyzer.ml | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/lib/qparser/analyzer.ml b/lib/qparser/analyzer.ml index ca2b54f..b4eeba0 100644 --- a/lib/qparser/analyzer.ml +++ b/lib/qparser/analyzer.ml @@ -1,15 +1,23 @@ type 'a result = { content : 'a; report : Qsp_syntax.Report.t list } +type lexer = Location | Dynamic -(** - Run the QSP parser and apply the analyzer over it. +let get_lexer : + Lexbuf.t -> + lexer -> + unit -> + Tokens.token * Lexing.position * Lexing.position = + fun l -> function + | Location -> Lexbuf.tokenize Lexer.main l + | Dynamic -> Lexbuf.tokenize Lexer.dynamics l + +(** Run the QSP parser and apply the analyzer over it. - See [syntax/S] - *) -let rec parse : - type a context. + See [syntax/S] *) +let rec parse : type a context. (module Qsp_syntax.S.Analyzer with type Location.t = a and type context = context) -> + lexer -> Lexbuf.t -> context -> (a result, Qsp_syntax.Report.t) Result.t = @@ -19,10 +27,18 @@ let rec parse : let module Parser = Parser.Make (S) in let module IncrementalParser = Interpreter.Interpreter (Parser.MenhirInterpreter) in - fun l context -> - let lexer = Lexbuf.tokenize Lexer.main l in + fun lexer_type l context -> + let get_parser : + lexer -> + Lexing.position -> + (context -> a) Parser.MenhirInterpreter.checkpoint = function + | Location -> Parser.Incremental.main + | Dynamic -> Parser.Incremental.dynamics + in + + let lexer = get_lexer l lexer_type in - let init = Parser.Incremental.main (fst (Lexbuf.positions l)) in + let init = (get_parser lexer_type) (fst (Lexbuf.positions l)) in (* Firslty, check if we are able to read the whole syntax from the source *) let evaluation = @@ -59,7 +75,7 @@ let rec parse : application attempt to start from a clean state in the next location, but may fail to detect the correct position. If so, we just start again until we hook the next location *) - parse (module S) l context + parse (module S) lexer_type l context | Error e, _ -> let message = match e.IncrementalParser.code with |