camlspotter avatar camlspotter committed 415c266 Merge

merge

Comments (0)

Files changed (4)

xml-light/xmlParser.ml

 open Dtd
 open Xml
 
+let robust = ref false
+
 type t = {
 	mutable prove : bool;
 	mutable check_eof : bool;
 	Stack.push t s.stack
 
 let rec read_node s =
-	match pop s with
-	| Xml_lexer.PCData s -> PCData s
-	| Xml_lexer.Tag (tag, attr, true) -> Element (tag, attr, [])
-	| Xml_lexer.Tag (tag, attr, false) -> Element (tag, attr, read_elems ~tag s)
-	| t ->
-		push t s;
-		raise NoMoreData
-and
-	read_elems ?tag s =
-		let elems = ref [] in
-		(try
-			while true do
-				match s.xparser.concat_pcdata , read_node s , !elems with
-				| true , PCData c , (PCData c2) :: q ->
-					elems := PCData (sprintf "%s\n%s" c2 c) :: q
-				| _ , x , l ->
-					elems := x :: l
-			done
-		with
-			NoMoreData -> ());
-		match pop s with
-		| Xml_lexer.Endtag s when Some s = tag -> List.rev !elems
-		| Xml_lexer.Eof when tag = None -> List.rev !elems
-		| t ->
-			match tag with
-			| None -> raise (Internal_error EOFExpected)
-			| Some s -> raise (Internal_error (EndOfTagExpected s))
-
+  match pop s with
+  | Xml_lexer.PCData s -> PCData s
+  | Xml_lexer.Tag (tag, attr, true) -> Element (tag, attr, [])
+  | Xml_lexer.Tag (tag, attr, false) -> Element (tag, attr, read_elems ~tag s)
+  | t ->
+      push t s;
+      raise NoMoreData
+and read_elems ?tag s =
+  let elems = ref [] in
+  (try
+     while true do
+       match s.xparser.concat_pcdata , read_node s , !elems with
+       | true , PCData c , (PCData c2) :: q ->
+	   elems := PCData (sprintf "%s\n%s" c2 c) :: q
+       | _ , x , l ->
+	   elems := x :: l
+     done
+   with
+     NoMoreData -> ());
+  match pop s with
+  | Xml_lexer.Endtag s when Some s = tag -> List.rev !elems
+  | Xml_lexer.Eof when tag = None -> List.rev !elems
+  | t ->
+      match tag with
+      | None -> 
+          if not !robust then raise (Internal_error EOFExpected)
+          else begin
+            (* ignore the stacks *)
+            List.rev !elems
+          end
+      | Some str -> 
+          if not !robust then 
+            raise (Internal_error (EndOfTagExpected str))
+          else begin 
+            (* fake a close *)
+            push t s; List.rev !elems
+          end
+                        
 let read_xml s =
 	match s.xparser.prove, pop s with
 	| true, Xml_lexer.DocType (root, Xml_lexer.DTDFile file) ->

xml-light/xmlParser.mli

 
 *)
 
+val robust : bool ref
+
 (** Abstract type for an Xml parser. *)
 type t
 
 (**/**)
 
 (* internal usage only... *)
-val _raises : (Xml.error_msg -> Lexing.lexbuf -> exn) -> (string -> exn) -> (Dtd.parse_error_msg -> Lexing.lexbuf -> exn) -> unit
+val _raises : (Xml.error_msg -> Lexing.lexbuf -> exn) -> (string -> exn) -> (Dtd.parse_error_msg -> Lexing.lexbuf -> exn) -> unit

xml-light/xml_lexer.mli

  * MA 02110-1301 USA
  *)
 
+val robust : bool ref
+
 type error =
 	| EUnterminatedComment
 	| EUnterminatedString
 val token : Lexing.lexbuf -> token
 val dtd : Lexing.lexbuf -> Dtd.dtd
 val pos : Lexing.lexbuf -> pos
-val restore : pos -> unit
+val restore : pos -> unit

xml-light/xml_lexer.mll

 open Xml_parser
 open Dtd
 
+let robust = ref false
+
 type error =
 	| EUnterminatedComment
 	| EUnterminatedString
 			with
 				Not_found -> "&" ^ ident
 		}
-	| _ | eof
-		{ raise (Error EUnterminatedEntity) }
+	| (entitychar* as s)
+		{ 
+                  if !robust then s
+                  else raise (Error EUnterminatedEntity) }
+        | eof
+		{ 
+                  if !robust then "&"
+                  else raise (Error EUnterminatedEntity) }
 
 and ident_name = parse
 	| identchar+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.