aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-07 11:56:08 +0000
committerAleksey Kladov <[email protected]>2018-01-07 11:56:08 +0000
commit9e4052cc2ee12751ba94909ff479bd03df141ac4 (patch)
tree2e7c3a063369c5151fd851910c997e5d1020a164 /src/parser
parent18f9e50b2d1aaf91992be9fd2f2a7e1866a943d3 (diff)
Test utils
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/event_parser/grammar.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs
index 79ef8b31c..e1f717714 100644
--- a/src/parser/event_parser/grammar.rs
+++ b/src/parser/event_parser/grammar.rs
@@ -8,7 +8,12 @@ pub fn file(p: &mut Parser) {
8 node(p, FILE, |p| { 8 node(p, FILE, |p| {
9 shebang(p); 9 shebang(p);
10 inner_attributes(p); 10 inner_attributes(p);
11 many(p, |p| skip_to_first(p, item_first, item)); 11 many(p, |p| {
12 skip_to_first(
13 p, item_first, item,
14 "expected item",
15 )
16 });
12 }) 17 })
13} 18}
14 19
@@ -84,19 +89,34 @@ fn comma_list<F: Fn(&mut Parser) -> bool>(p: &mut Parser, f: F) {
84} 89}
85 90
86 91
87fn skip_to_first<C, F>(p: &mut Parser, cond: C, f: F) -> bool 92fn skip_to_first<C, F>(p: &mut Parser, cond: C, f: F, message: &str) -> bool
88where 93where
89 C: Fn(&Parser) -> bool, 94 C: Fn(&Parser) -> bool,
90 F: FnOnce(&mut Parser), 95 F: FnOnce(&mut Parser),
91{ 96{
97 let mut skipped = false;
92 loop { 98 loop {
93 if cond(p) { 99 if cond(p) {
100 if skipped {
101 p.finish();
102 }
94 f(p); 103 f(p);
95 return true; 104 return true;
96 } 105 }
97 if p.bump().is_none() { 106 if p.is_eof() {
107 if skipped {
108 p.finish();
109 }
98 return false; 110 return false;
99 } 111 }
112 if !skipped {
113 p.start(ERROR);
114 p.error()
115 .message(message)
116 .emit();
117 }
118 p.bump().unwrap();
119 skipped = true;
100 } 120 }
101} 121}
102 122