mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
zkas/analyzer: Add error functions.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user