aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-03-05 20:12:39 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-03-05 20:12:39 +0100
commitdd38069bc1f8b696e8f0c50f43e0e7954729acf7 (patch)
treeae7b0262aa7a3a4aaf9abf72738f116fdc61487e /src/compiler.rs
parent57f02d45b7e6ec65c3f2055a2cc4b2c2737167d4 (diff)
downloadsylt-dd38069bc1f8b696e8f0c50f43e0e7954729acf7.tar.gz
better errors on invalid outer tokens
Diffstat (limited to 'src/compiler.rs')
-rw-r--r--src/compiler.rs12
1 files changed, 8 insertions, 4 deletions
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,