+ | BrgEntity entity -> BrgU.type_check brg_err ok st.kst entity
+ | BagEntity entity -> BagU.type_check ok st.kst entity
+ | CrgEntity _
+ | MetaEntity _ -> st
+
+(* extended lexer ***********************************************************)
+
+type 'token lexer = {
+ parse : Lexing.lexbuf -> 'token;
+ mutable tokbuf: 'token option;
+ mutable unget : bool
+}
+
+let initial_lexer parse = {
+ parse = parse; tokbuf = None; unget = false
+}
+
+let token xl lexbuf = match xl.tokbuf with
+ | Some token when xl.unget ->
+ xl.unget <- false; token
+ | _ ->
+ let token = xl.parse lexbuf in
+ xl.tokbuf <- Some token; token
+
+(* input related ************************************************************)
+
+type input = Text | Automath
+
+type input_entity = TxtEntity of Txt.command
+ | AutEntity of Aut.command
+
+let type_of_input name =
+ if F.check_suffix name ".hln" then Text
+ else if F.check_suffix name ".aut" then
+ let _ = H.set_sorts 0 ["Set"; "Prop"] in
+ assert (H.set_graph "Z2");
+ Automath
+ else begin
+ L.warn (P.sprintf "Unknown file type: %s" name); exit 2
+ end
+
+let txt_xl = initial_lexer TxtLexer.token
+
+let aut_xl = initial_lexer AutLexer.token
+
+let parbuf = ref [] (* parser buffer *)
+
+let gen_text command =
+ parbuf := TxtEntity command :: !parbuf
+
+let entity_of_input lexbuf i = match i, !parbuf with
+ | Text, [] ->
+ begin match TxtParser.entry (token txt_xl) lexbuf with
+ | Some e, unget -> txt_xl.unget <- unget; Some (TxtEntity e)
+ | None, _ -> None
+ end
+ | Text, hd :: tl ->
+ parbuf := tl; Some hd
+ | Automath, _ ->
+ begin match AutParser.entry (token aut_xl) lexbuf with
+ | Some e, unget -> aut_xl.unget <- unget; Some (AutEntity e)
+ | None, _ -> None
+ end
+
+let process_input f st = function
+ | AutEntity e ->
+ let f ast e = f {st with ast = ast} (AutEntity e) in
+ AP.process_command f st.ast e
+ | xe -> f st xe
+
+let count_input st = function
+ | AutEntity e -> {st with ac = AO.count_command C.start st.ac e}
+ | xe -> st