From 4efc1d21441c5e9ad7f24a3e473bbbd8025de124 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Thu, 28 Sep 2023 11:44:12 +0200 Subject: Allow the parsing for the whole compiled file --- bin/qsp_parser.ml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'bin') diff --git a/bin/qsp_parser.ml b/bin/qsp_parser.ml index f2b21f9..0459fe2 100644 --- a/bin/qsp_parser.ml +++ b/bin/qsp_parser.ml @@ -43,14 +43,22 @@ let () = let file_name = List.hd file_names in let ic = Stdlib.open_in file_name in + (*let lexer = Lexing.from_channel ~with_positions:true ic in*) - let lexer = Sedlexing.Utf8.from_channel ic in - let result = - Qparser.Analyzer.parse - (module Qsp_syntax.Type_of) - (module Sedlexing.Utf8) - lexer + let lexer, mod_ = + match Filename.extension file_name with + | ".qsrc" -> + ( Sedlexing.Utf8.from_channel ic, + (module Sedlexing.Utf8 : Qparser.Lexer.Encoding) ) + | ".txt" -> + ( Sedlexing.Utf16.from_channel ic (Some Little_endian), + (module struct + let lexeme lexbuf = Sedlexing.Utf16.lexeme lexbuf Little_endian true + end : Qparser.Lexer.Encoding) ) + | _ -> raise (Failure "unknown extension") in + + let result = Qparser.Analyzer.parse (module Qsp_syntax.Type_of) mod_ lexer in match result with | Ok f -> ( let report = List.fold_left (f []) ~init:[] ~f:(filter_report filters) in -- cgit v1.2.3