@@ -33,29 +33,46 @@ pub fn string_to_parser(source_str: @str) -> Parser {
33
33
p
34
34
}
35
35
36
+ fn with_error_checking_parse < T > ( s : @str , f : & fn ( & mut Parser ) -> T ) -> T {
37
+ let mut p = string_to_parser ( s) ;
38
+ let x = f ( & mut p) ;
39
+ p. abort_if_errors ( ) ;
40
+ x
41
+ }
42
+
36
43
pub fn string_to_crate ( source_str : @str ) -> @ast:: Crate {
37
- string_to_parser ( source_str) . parse_crate_mod ( )
44
+ do with_error_checking_parse ( source_str) |p| {
45
+ p. parse_crate_mod ( )
46
+ }
38
47
}
39
48
40
49
// parse a string, return an expr
41
50
pub fn string_to_expr ( source_str : @str ) -> @ast:: expr {
42
- string_to_parser ( source_str) . parse_expr ( )
51
+ do with_error_checking_parse ( source_str) |p| {
52
+ p. parse_expr ( )
53
+ }
43
54
}
44
55
45
56
// parse a string, return an item
46
57
pub fn string_to_item ( source_str : @str ) -> Option < @ast:: item > {
47
- string_to_parser ( source_str) . parse_item ( ~[ ] )
58
+ do with_error_checking_parse ( source_str) |p| {
59
+ p. parse_item ( ~[ ] )
60
+ }
48
61
}
49
62
50
63
// parse a string, return an item and the ParseSess
51
64
pub fn string_to_item_and_sess ( source_str : @str ) -> ( Option < @ast:: item > , @mut ParseSess ) {
52
65
let ( p, ps) = string_to_parser_and_sess ( source_str) ;
53
- ( p. parse_item ( ~[ ] ) , ps)
66
+ let io = p. parse_item ( ~[ ] ) ;
67
+ p. abort_if_errors ( ) ;
68
+ ( io, ps)
54
69
}
55
70
56
71
// parse a string, return a stmt
57
72
pub fn string_to_stmt ( source_str : @str ) -> @ast:: stmt {
58
- string_to_parser ( source_str) . parse_stmt ( ~[ ] )
73
+ do with_error_checking_parse ( source_str) |p| {
74
+ p. parse_stmt ( ~[ ] )
75
+ }
59
76
}
60
77
61
78
// parse a string, return a pat. Uses "irrefutable"... which doesn't
0 commit comments