1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use pkl_parser::{parse, Rule};
use std::{fs, time::Instant};
fn main() {
let src = fs::read_to_string("a.pkl").unwrap();
let src = src.repeat(1);
let time = Instant::now();
let mut result = parse(&src).unwrap();
let file = result.next().unwrap().into_inner();
let mut doc_comment: Option<String> = None;
for record in file {
match record.as_rule() {
Rule::stmt => {
for stmt in record.into_inner() {
match stmt.as_rule() {
_ => {
// when managing the statement
// take the value inside the doc
// comment to attach it to attach
// it to the stmt if necessary
for stmt in stmt.into_inner() {
match stmt.as_rule() {
Rule::COMMENT => {
// println!("comment: {:?}", stmt.as_rule())
}
_ => {
// println!("any stmt: {:?}", stmt.as_rule());
}
}
}
}
}
}
}
Rule::EOI => (),
Rule::COMMENT => {
for com in record.into_inner() {
match com.as_rule() {
Rule::doc_comment => {
doc_comment = Some(
doc_comment
.map(|mut x| {
x.push_str(com.as_str());
x
})
.unwrap_or(String::from(com.as_str())),
);
}
Rule::annotation => {
// take care of them here
}
Rule::line_comment | Rule::multiline_comment => (),
_ => unreachable!(),
}
}
}
_ => unreachable!(),
}
}
println!(
"{}ms to parse {} chars",
time.elapsed().as_millis(),
src.len()
);
}