aboutsummaryrefslogtreecommitdiff
path: root/bin/qsp_parser.ml
diff options
context:
space:
mode:
authorChimrod <>2023-09-28 11:44:12 +0200
committerChimrod <>2023-09-29 10:00:21 +0200
commit4efc1d21441c5e9ad7f24a3e473bbbd8025de124 (patch)
tree6aecbef816a6380138248bd93621d8c69aefa514 /bin/qsp_parser.ml
parent7fc4021d888b4f16f8fa87c0ea1df68d3806df64 (diff)
Allow the parsing for the whole compiled file
Diffstat (limited to 'bin/qsp_parser.ml')
-rw-r--r--bin/qsp_parser.ml20
1 files changed, 14 insertions, 6 deletions
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