@@ -3,6 +3,28 @@ use std::path::Path;
33use crate :: language:: * ;
44use crate :: regex:: * ;
55
6+ #[ derive( Debug , PartialEq , Eq ) ]
7+ pub struct ParseResult < ' i > {
8+ pub document : Document < ' i > ,
9+ pub errors : Vec < ParsingError < ' i > > ,
10+ }
11+
12+ impl < ' i > ParseResult < ' i > {
13+ pub fn has_errors ( & self ) -> bool {
14+ !self
15+ . errors
16+ . is_empty ( )
17+ }
18+ }
19+
20+ pub fn parse_with_recovery < ' i > ( path : & ' i Path , content : & ' i str ) -> ParseResult < ' i > {
21+ let mut input = Parser :: new ( ) ;
22+ input. filename ( path) ;
23+ input. initialize ( content) ;
24+
25+ input. parse_collecting_errors ( )
26+ }
27+
628pub fn parse_via_taking < ' i > (
729 path : & ' i Path ,
830 content : & ' i str ,
@@ -87,6 +109,7 @@ pub struct Parser<'i> {
87109 original : & ' i str ,
88110 source : & ' i str ,
89111 offset : usize ,
112+ problems : Vec < ParsingError < ' i > > ,
90113}
91114
92115impl < ' i > Parser < ' i > {
@@ -96,6 +119,7 @@ impl<'i> Parser<'i> {
96119 original : "" ,
97120 source : "" ,
98121 offset : 0 ,
122+ problems : Vec :: new ( ) ,
99123 }
100124 }
101125
@@ -106,6 +130,8 @@ impl<'i> Parser<'i> {
106130 self . original = content;
107131 self . source = content;
108132 self . offset = 0 ;
133+ self . problems
134+ . clear ( ) ;
109135 }
110136
111137 fn advance ( & mut self , width : usize ) {
@@ -499,6 +525,7 @@ impl<'i> Parser<'i> {
499525 original : self . original ,
500526 source : content,
501527 offset : indent + self . offset ,
528+ problems : Vec :: new ( ) ,
502529 } ;
503530
504531 // and return
0 commit comments