Skip to main content

mtots_core/base/gl/
parse.rs

1use super::*;
2
3impl Globals {
4    pub fn parse(&self, source: Rc<Source>) -> Result<ModuleDisplay> {
5        let (tokens, posinfo) = match self.lexer.lex(source.data()) {
6            Ok(r) => r,
7            Err(error) => {
8                let pos = error.offset();
9                let lineno = error.lineno();
10                return Err(Error::rt(
11                    format!("{:?}", error).into(),
12                    vec![Mark::new(source, pos, lineno)],
13                ));
14            }
15        };
16        self.parser.parse_tokens(source.clone(), tokens, posinfo)
17    }
18    pub fn repl_ready(&self, line: &str) -> bool {
19        match self.lexer.lex(line) {
20            Ok(_) => true,
21            Err(error) => match error.kind() {
22                LexErrorKind::UnmatchedOpeningSymbol | LexErrorKind::UnterminatedStringLiteral => {
23                    false
24                }
25
26                // input is invalid, but the problem is not insufficient input
27                _ => true,
28            },
29        }
30    }
31}