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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#![deny(missing_docs)]
extern crate read_token;
extern crate range;
pub use whitespace::Whitespace;
pub use parse_error_handler::{ ParseErrorHandler, ParseStdErr };
pub use parse_error::ParseError;
pub use token::Token;
pub use select::Select;
pub use node::{ Node, NodeRef, NodeVisit };
pub use optional::Optional;
pub use sequence::Sequence;
pub use separated_by::SeparatedBy;
pub use until_any::UntilAny;
pub use until_any_or_whitespace::UntilAnyOrWhitespace;
pub use text::Text;
pub use number::Number;
pub use lines::Lines;
pub use rule::Rule;
pub use tokenizer::{ Tokenizer, TokenizerState };
pub type DebugId = usize;
use std::rc::Rc;
use range::Range;
mod parse_error;
mod parse_error_handler;
mod token;
mod whitespace;
mod select;
mod node;
mod optional;
mod sequence;
mod separated_by;
mod until_any;
mod until_any_or_whitespace;
mod text;
mod number;
mod lines;
mod rule;
mod tokenizer;
pub type ParseResult<S> = Result<(Range, S, Option<(Range, ParseError)>),
(Range, ParseError)>;
#[derive(PartialEq, Clone, Debug)]
pub enum MetaData {
StartNode(Rc<String>),
EndNode(Rc<String>),
Bool(Rc<String>, bool),
F64(Rc<String>, f64),
String(Rc<String>, String),
}
#[inline(always)]
fn update<'a>(
range: range::Range,
err: Option<(Range, ParseError)>,
chars: &mut &'a [char],
offset: &mut usize,
opt_error: &mut Option<(Range, ParseError)>
) {
let next_offset = range.next_offset();
*chars = &chars[next_offset - *offset..];
*offset = next_offset;
err_update(err, opt_error);
}
#[inline(always)]
fn err_update(
err: Option<(Range, ParseError)>,
opt_error: &mut Option<(Range, ParseError)>
) {
if let &mut Some(ref mut opt_error) = opt_error {
if let Some(err) = err {
if opt_error.0.next_offset() <= err.0.next_offset() {
*opt_error = err;
}
}
} else {
*opt_error = err;
};
}
#[inline(always)]
fn ret_err(a: (Range, ParseError), b: Option<(Range, ParseError)>) ->
(Range, ParseError) {
if let Some(b) = b {
if b.0.next_offset() > a.0.next_offset() {
b
} else {
a
}
} else {
a
}
}