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
118
119
120
121
122
123
124
125
#![forbid(unsafe_code)]
#![forbid(clippy::all)]
#![allow(clippy::try_err)]
#![allow(clippy::too_many_arguments)]
#![deny(clippy::pedantic)]
#![allow(clippy::non_ascii_literal)]
#![deny(clippy::use_self)]
#![deny(unreachable_pub)]
#![doc(html_root_url = "https://docs.rs/fend-core/0.1.13")]
mod ast;
mod err;
mod eval;
mod interrupt;
mod lexer;
mod num;
mod parser;
mod scope;
mod units;
mod value;
pub use interrupt::Interrupt;
#[derive(PartialEq, Eq, Debug)]
pub struct FendResult {
main_result: String,
other_info: Vec<String>,
}
impl FendResult {
#[must_use]
pub fn get_main_result(&self) -> &str {
self.main_result.as_str()
}
pub fn get_other_info(&self) -> impl Iterator<Item = &str> {
self.other_info.iter().map(std::string::String::as_str)
}
}
#[derive(Clone)]
pub struct Context {}
impl Default for Context {
fn default() -> Self {
Self::new()
}
}
impl Context {
#[must_use]
pub fn new() -> Self {
Self {}
}
}
pub fn evaluate(input: &str, context: &mut Context) -> Result<FendResult, String> {
evaluate_with_interrupt(input, context, &interrupt::Never::default())
}
pub fn evaluate_with_interrupt(
input: &str,
_context: &mut Context,
int: &impl Interrupt,
) -> Result<FendResult, String> {
if input.is_empty() {
return Ok(FendResult {
main_result: "".to_string(),
other_info: vec![],
});
}
let result = match eval::evaluate_to_string(input, None, int) {
Ok(value) => value,
Err(err::IntErr::Interrupt(_)) => return Err("Interrupted".to_string()),
Err(err::IntErr::Error(e)) => return Err(e),
};
Ok(FendResult {
main_result: result,
other_info: vec![],
})
}
fn get_version_as_str() -> &'static str {
"0.1.13"
}
#[must_use]
pub fn get_version() -> String {
get_version_as_str().to_string()
}
#[must_use]
#[deprecated = "Use `get_version()` instead"]
pub fn get_extended_version() -> String {
get_version()
}