zkas/analyzer: Add error functions.

This commit is contained in:
parazyd
2022-01-02 12:22:20 +01:00
parent 3b1b0de2e9
commit bbecf641de
2 changed files with 36 additions and 6 deletions

View File

@@ -1,4 +1,6 @@
use std::str::Chars;
use std::{io, io::Write, process, str::Chars};
use termion::{color, style};
use crate::ast::{Constants, Statements, Witnesses};
@@ -24,5 +26,32 @@ impl Analyzer {
Analyzer { file: filename.to_string(), lines, constants, witnesses, statements }
}
pub fn analyze(self) {}
pub fn analyze(self) {
self.error("Semantic analyzer not implemented".to_string(), 1, 0);
}
fn error(&self, msg: String, ln: usize, col: usize) {
let err_msg = format!("{} (line {}, column {})", msg, ln, col);
let dbg_msg = format!("{}:{}:{}: {}", self.file, ln, col, self.lines[ln - 1]);
let pad = dbg_msg.split(": ").next().unwrap().len() + col + 2;
let caret = format!("{:width$}^", "", width = pad);
let msg = format!("{}\n{}\n{}\n", err_msg, dbg_msg, caret);
Analyzer::abort(&msg);
}
fn abort(msg: &str) {
let stderr = io::stderr();
let mut handle = stderr.lock();
write!(
handle,
"{}{}Semantic error:{} {}",
style::Bold,
color::Fg(color::Red),
style::Reset,
msg,
)
.unwrap();
handle.flush().unwrap();
process::exit(1);
}
}

View File

@@ -1,8 +1,9 @@
/// Types supported by the VM
#[derive(Clone, Debug)]
pub enum Type {
EcFixedPoint = 0x00,
Base = 0x01,
Scalar = 0x02,
MerklePath = 0x03,
EcPoint = 0x00,
EcFixedPoint = 0x01,
Base = 0x10,
Scalar = 0x11,
MerklePath = 0x20,
}