diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-05 20:12:39 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-05 20:12:39 +0100 |
| commit | dd38069bc1f8b696e8f0c50f43e0e7954729acf7 (patch) | |
| tree | ae7b0262aa7a3a4aaf9abf72738f116fdc61487e | |
| parent | 57f02d45b7e6ec65c3f2055a2cc4b2c2737167d4 (diff) | |
| download | sylt-dd38069bc1f8b696e8f0c50f43e0e7954729acf7.tar.gz | |
better errors on invalid outer tokens
| -rw-r--r-- | progs/tests/faulty.sy | 2 | ||||
| -rw-r--r-- | src/compiler.rs | 12 | ||||
| -rw-r--r-- | src/sectionizer.rs | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/progs/tests/faulty.sy b/progs/tests/faulty.sy index 67605d2..ea1b40d 100644 --- a/progs/tests/faulty.sy +++ b/progs/tests/faulty.sy @@ -2,4 +2,4 @@ asdflökja;;;; 123 asd -// errors: [ErrorKind::SyntaxError(_, _), ErrorKind::SyntaxError(_, _), ErrorKind::SyntaxError(_, _)] +// errors: [ErrorKind::SyntaxError(_, _)] diff --git a/src/compiler.rs b/src/compiler.rs index 9f9d6ef..16887a0 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -1571,8 +1571,8 @@ impl Compiler { (Token::Newline, ..) => {} - _ => { - error!(self, "Invalid outer statement."); + (a, b, c, d) => { + error!(self, format!("Unknown outer token sequence: {:?} {:?} {:?} {:?}.", a, b, c, d)) } } } @@ -1686,7 +1686,7 @@ impl Compiler { pub(crate) fn compile(&mut self, name: &str, file: &Path, functions: &[(String, RustFunction)]) -> Result<Prog, Vec<Error>> { for section in 0..self.sections.len() { self.init_section(section); - let section = &self.sections[section]; + let section = &mut self.sections[section]; match (section.tokens.get(0), section.tokens.get(1), section.tokens.get(2)) { (Some((Token::Use, _)), Some((Token::Identifier(name), _)), ..) => { @@ -1737,7 +1737,8 @@ impl Compiler { (None, ..) => {} (a, b, c) => { - let msg = format!("Unknown outer token sequence: {:?} {:?} {:?}", a, b, c); + section.faulty = true; + let msg = format!("Unknown outer token sequence: {:?} {:?} {:?}. Expected 'use', function, blob or variable.", a, b, c); error!(self, msg); } } @@ -1755,6 +1756,9 @@ impl Compiler { let mut block = Block::new(name, file); for section in 0..self.sections.len() { self.init_section(section); + if self.sections[section].faulty { + continue; + } while !matches!(self.peek(), Token::EOF | Token::Use) { self.outer_statement(&mut block); expect!(self, Token::Newline | Token::EOF, diff --git a/src/sectionizer.rs b/src/sectionizer.rs index c9cfcd5..8c5e238 100644 --- a/src/sectionizer.rs +++ b/src/sectionizer.rs @@ -6,6 +6,7 @@ use std::path::{Path, PathBuf}; pub struct Section { pub tokens: Vec<PlacedToken>, pub path: PathBuf, + pub faulty: bool, } impl Section { @@ -13,6 +14,7 @@ impl Section { Self { tokens: Vec::from(tokens), path, + faulty: false, } } } |
