pull.ml 1.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
(* To test PXP pull parsers *)

open Pxp_yacc
open Pxp_lexer_types
open Pxp_types
open Printf


(* dump_event: dumps a single parsing event *)

11 12 13
let dump_event e = ()

(*
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
let dump_event =
  function
      E_start_doc(v,sa,dtd) ->
	printf "E_start_doc version=%s standalone=%b\n" v sa
    | E_end_doc ->
	printf "E_end_doc\n"
    | E_start_tag(name,attlist,_) ->
	printf "E_start_tag %s %s\n" name 
	  (String.concat " " (List.map (fun (n,v) -> n ^ "=" ^ v) attlist))
    | E_end_tag(name,_) ->
	printf "E_end_tag %s\n" name
    | E_char_data data ->
	printf "E_char_data %s\n" data
    | E_pinstr(target,data) ->
	printf "E_pinstr %s %s\n" target data
    | E_comment data ->
	printf "E_comment %s\n" data
    | E_position(ent,line,col) ->
	printf "E_position %s line=%d col=%d\n" ent line col
    | E_error e ->
	printf "E_error %s\n" (Pxp_types.string_of_exn e)
    | E_end_of_stream ->
	printf "E_end_of_stream\n"
37
*)
38 39 40 41


(* parse: prints the events while parsing the passed string *)

42
let pull s =
43 44 45 46 47 48 49 50 51
  let config = default_config in
  let mgr = create_entity_manager config (from_file s) in
  let next_event = 
    create_pull_parser config (`Entry_document [`Extend_dtd_fully]) mgr in
  let event = ref (Some E_end_of_stream) in
  while !event <> None do
    event := next_event();
    match !event with
	Some e -> dump_event e
52
      | None -> () 
53 54 55
  done


56 57 58
let push s =
  process_entity
    default_config
59
    (`Entry_document[(* `Extend_dtd_fully *)])
60 61 62 63
    (create_entity_manager default_config (from_file s))
    dump_event

let () = push Sys.argv.(1)