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
use arret_syntax::span::ByteIndex;
use super::command::TYPE_ONLY_PREFIX;
pub const MAXIMUM_PARSED_LINE_LEN: usize = 512;
pub fn error_for_line(mut line: &str) -> Option<arret_syntax::error::Error> {
use arret_syntax::parser::datum_from_str_with_span_offset;
let span_offset = if line.starts_with(TYPE_ONLY_PREFIX) {
line = &line[TYPE_ONLY_PREFIX.len()..];
TYPE_ONLY_PREFIX.len()
} else {
0
};
if line.starts_with('/') ||
line.chars().all(char::is_whitespace) ||
line.len() > MAXIMUM_PARSED_LINE_LEN
{
return None;
}
datum_from_str_with_span_offset(None, line, span_offset as ByteIndex).err()
}
pub fn error_context_for_eol(line: &str) -> Option<arret_syntax::error::WithinContext> {
error_for_line(line).and_then(|error| {
if let arret_syntax::error::ErrorKind::Eof(within_context) = error.kind() {
Some(*within_context)
} else {
None
}
})
}