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
use structure::xflow::XFlowValue;
use xfstate::XFState;
#[allow(dead_code)]
mod flox_grammar {
include!(concat!(env!("OUT_DIR"), "/flox_grammar.rs"));
}
#[derive(Serialize, Deserialize, Debug)]
pub enum Error {
ParseError(String),
}
pub fn parse_context(input: &str, state: &XFState) -> Result<XFlowValue, Error> {
match flox_grammar::expression(input, state) {
Ok(res) => Ok(res),
Err(err) => {
Err(Error::ParseError(format!("Bad expression {:?} - Error : {:?}", input, err)))
}
}
}
pub fn parse(input: &str) -> Result<XFlowValue, Error> {
let state = XFState::default();
match flox_grammar::expression(input, &state) {
Ok(res) => Ok(res),
Err(err) => {
Err(Error::ParseError(format!("Bad expression {:?} - Error : {:?}", input, err)))
}
}
}
pub fn parse_arithmetic(input: &str) -> Result<XFlowValue, Error> {
let state = XFState::default();
match flox_grammar::arithmetic_expression(input, &state) {
Ok(res) => Ok(res),
Err(err) => {
Err(Error::ParseError(format!("Bad expression {:?} - Error : {:?}", input, err)))
}
}
}
pub fn parse_boolean(input: &str) -> Result<XFlowValue, Error> {
let state = XFState::default();
match flox_grammar::boolean_expression(input, &state) {
Ok(res) => Ok(res),
Err(err) => {
Err(Error::ParseError(format!("Bad expression {:?} - Error : {:?}", input, err)))
}
}
}
pub fn extract_variable_names(input: &str) -> Result<Vec<&str>, Error> {
let state = XFState::default();
match flox_grammar::variable_names(input, &state) {
Ok(res) => Ok(res),
Err(_ ) => {
Ok(Vec::<&str>::default())
}
}
}