mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-26 19:00:28 -04:00
REFACTOR: Rename our error::Error type to BuildError.
This commit is contained in:
parent
39b6fea2fe
commit
15026423db
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -1,6 +1,6 @@
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "abortable_parser"
|
name = "abortable_parser"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -228,7 +228,7 @@ dependencies = [
|
|||||||
name = "ucg"
|
name = "ucg"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"abortable_parser 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"abortable_parser 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bencher 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bencher 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.26.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"cpuprofiler 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cpuprofiler 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -285,7 +285,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
"checksum abortable_parser 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09cdf5378b5e4a079fa886e621519fcb2502d9cb008d3f76b92f61f3890d5906"
|
"checksum abortable_parser 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "685d99bbca3566d6b7f34b09d68039089ce4a36226f6f99f61ed8495850e3213"
|
||||||
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
|
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
|
||||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||||
"checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f"
|
"checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f"
|
||||||
|
@ -10,7 +10,7 @@ keywords = ["compiler", "config"]
|
|||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
abortable_parser = "0.2.1"
|
abortable_parser = "~0.2.2"
|
||||||
clap = "~2.26.0"
|
clap = "~2.26.0"
|
||||||
serde_json = "~1.0.9"
|
serde_json = "~1.0.9"
|
||||||
simple-error = "0.1"
|
simple-error = "0.1"
|
||||||
|
@ -58,7 +58,7 @@ impl Val {
|
|||||||
target: &Self,
|
target: &Self,
|
||||||
file_name: &str,
|
file_name: &str,
|
||||||
pos: Position,
|
pos: Position,
|
||||||
) -> Result<bool, error::Error> {
|
) -> Result<bool, error::BuildError> {
|
||||||
// first we do a type equality comparison
|
// first we do a type equality comparison
|
||||||
match (self, target) {
|
match (self, target) {
|
||||||
// Empty values are always equal.
|
// Empty values are always equal.
|
||||||
@ -100,12 +100,12 @@ impl Val {
|
|||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(&Val::Macro(_), &Val::Macro(_)) => Err(error::Error::new(
|
(&Val::Macro(_), &Val::Macro(_)) => Err(error::BuildError::new(
|
||||||
format!("Macros are not comparable in file: {}", file_name),
|
format!("Macros are not comparable in file: {}", file_name),
|
||||||
error::ErrorType::TypeFail,
|
error::ErrorType::TypeFail,
|
||||||
pos,
|
pos,
|
||||||
)),
|
)),
|
||||||
(me, tgt) => Err(error::Error::new(
|
(me, tgt) => Err(error::BuildError::new(
|
||||||
format!("Types differ for {}, {} in file: {}", me, tgt, file_name),
|
format!("Types differ for {}, {} in file: {}", me, tgt, file_name),
|
||||||
error::ErrorType::TypeFail,
|
error::ErrorType::TypeFail,
|
||||||
pos,
|
pos,
|
||||||
|
@ -50,7 +50,7 @@ impl MacroDef {
|
|||||||
// Error conditions. If the args don't match the length and types of the argdefs then this is
|
// Error conditions. If the args don't match the length and types of the argdefs then this is
|
||||||
// macro call error.
|
// macro call error.
|
||||||
if args.len() > self.argdefs.len() {
|
if args.len() > self.argdefs.len() {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Macro called with too many args in file: {}",
|
"Macro called with too many args in file: {}",
|
||||||
root.to_string_lossy()
|
root.to_string_lossy()
|
||||||
@ -125,7 +125,7 @@ macro_rules! eval_binary_expr {
|
|||||||
return Ok(Rc::new($result));
|
return Ok(Rc::new($result));
|
||||||
}
|
}
|
||||||
val => {
|
val => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!("Expected {} but got {}", $msg, val),
|
format!("Expected {} but got {}", $msg, val),
|
||||||
error::ErrorType::TypeFail,
|
error::ErrorType::TypeFail,
|
||||||
$pos.clone(),
|
$pos.clone(),
|
||||||
@ -163,7 +163,7 @@ impl<'a> Builder<'a> {
|
|||||||
&Value::Str(ref s) => Ok(Rc::new(Val::Str(s.val.to_string()))),
|
&Value::Str(ref s) => Ok(Rc::new(Val::Str(s.val.to_string()))),
|
||||||
&Value::Symbol(ref s) => {
|
&Value::Symbol(ref s) => {
|
||||||
self.lookup_sym(&(s.into()))
|
self.lookup_sym(&(s.into()))
|
||||||
.ok_or(Box::new(error::Error::new(
|
.ok_or(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Unable to find {} in file: {}",
|
"Unable to find {} in file: {}",
|
||||||
s.val,
|
s.val,
|
||||||
@ -263,7 +263,7 @@ impl<'a> Builder<'a> {
|
|||||||
Some(val) => Ok(val),
|
Some(val) => Ok(val),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => Err(Box::new(error::Error::new(
|
Err(err) => Err(Box::new(error::BuildError::new(
|
||||||
format!("{}", err,),
|
format!("{}", err,),
|
||||||
error::ErrorType::ParseError,
|
error::ErrorType::ParseError,
|
||||||
(&input).into(),
|
(&input).into(),
|
||||||
@ -317,7 +317,7 @@ impl<'a> Builder<'a> {
|
|||||||
};
|
};
|
||||||
let key = sym.into();
|
let key = sym.into();
|
||||||
if self.build_output.contains_key(&key) {
|
if self.build_output.contains_key(&key) {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!("Binding for import name {} already exists", sym.fragment),
|
format!("Binding for import name {} already exists", sym.fragment),
|
||||||
error::ErrorType::DuplicateBinding,
|
error::ErrorType::DuplicateBinding,
|
||||||
def.path.pos.clone(),
|
def.path.pos.clone(),
|
||||||
@ -333,7 +333,7 @@ impl<'a> Builder<'a> {
|
|||||||
let name = &def.name;
|
let name = &def.name;
|
||||||
match self.build_output.entry(name.into()) {
|
match self.build_output.entry(name.into()) {
|
||||||
Entry::Occupied(e) => {
|
Entry::Occupied(e) => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Binding \
|
"Binding \
|
||||||
for {:?} already \
|
for {:?} already \
|
||||||
@ -366,7 +366,7 @@ impl<'a> Builder<'a> {
|
|||||||
self.out_lock = Some((typ.fragment.to_string(), val.clone()));
|
self.out_lock = Some((typ.fragment.to_string(), val.clone()));
|
||||||
Ok(val)
|
Ok(val)
|
||||||
} else {
|
} else {
|
||||||
Err(Box::new(error::Error::new(
|
Err(Box::new(error::BuildError::new(
|
||||||
format!("You can only have one output per file."),
|
format!("You can only have one output per file."),
|
||||||
error::ErrorType::DuplicateBinding,
|
error::ErrorType::DuplicateBinding,
|
||||||
typ.pos.clone(),
|
typ.pos.clone(),
|
||||||
@ -408,7 +408,7 @@ impl<'a> Builder<'a> {
|
|||||||
if let Some(vv) = Self::find_in_fieldlist(next.1, fs) {
|
if let Some(vv) = Self::find_in_fieldlist(next.1, fs) {
|
||||||
stack.push_back(vv.clone());
|
stack.push_back(vv.clone());
|
||||||
} else {
|
} else {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Unable to \
|
"Unable to \
|
||||||
match element {} in selector \
|
match element {} in selector \
|
||||||
@ -435,7 +435,7 @@ impl<'a> Builder<'a> {
|
|||||||
if idx < elems.len() {
|
if idx < elems.len() {
|
||||||
stack.push_back(elems[idx].clone());
|
stack.push_back(elems[idx].clone());
|
||||||
} else {
|
} else {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Unable to \
|
"Unable to \
|
||||||
match element {} in selector \
|
match element {} in selector \
|
||||||
@ -495,7 +495,7 @@ impl<'a> Builder<'a> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!("{} is not a Tuple or List", vref),
|
format!("{} is not a Tuple or List", vref),
|
||||||
error::ErrorType::TypeFail,
|
error::ErrorType::TypeFail,
|
||||||
next.pos.clone(),
|
next.pos.clone(),
|
||||||
@ -526,7 +526,7 @@ impl<'a> Builder<'a> {
|
|||||||
return Ok(Rc::new(Val::Str([s.to_string(), ss.clone()].concat())))
|
return Ok(Rc::new(Val::Str([s.to_string(), ss.clone()].concat())))
|
||||||
}
|
}
|
||||||
val => {
|
val => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Expected \
|
"Expected \
|
||||||
String \
|
String \
|
||||||
@ -547,7 +547,7 @@ impl<'a> Builder<'a> {
|
|||||||
return Ok(Rc::new(Val::List(new_vec)));
|
return Ok(Rc::new(Val::List(new_vec)));
|
||||||
}
|
}
|
||||||
val => {
|
val => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Expected \
|
"Expected \
|
||||||
List \
|
List \
|
||||||
@ -561,7 +561,7 @@ impl<'a> Builder<'a> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ref expr => {
|
ref expr => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!("{} does not support the '+' operation", expr.type_name()),
|
format!("{} does not support the '+' operation", expr.type_name()),
|
||||||
error::ErrorType::Unsupported,
|
error::ErrorType::Unsupported,
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
@ -584,7 +584,7 @@ impl<'a> Builder<'a> {
|
|||||||
eval_binary_expr!(&Val::Float(ff), pos, right, Val::Float(f - ff), "Float")
|
eval_binary_expr!(&Val::Float(ff), pos, right, Val::Float(f - ff), "Float")
|
||||||
}
|
}
|
||||||
ref expr => {
|
ref expr => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!("{} does not support the '-' operation", expr.type_name()),
|
format!("{} does not support the '-' operation", expr.type_name()),
|
||||||
error::ErrorType::Unsupported,
|
error::ErrorType::Unsupported,
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
@ -607,7 +607,7 @@ impl<'a> Builder<'a> {
|
|||||||
eval_binary_expr!(&Val::Float(ff), pos, right, Val::Float(f * ff), "Float")
|
eval_binary_expr!(&Val::Float(ff), pos, right, Val::Float(f * ff), "Float")
|
||||||
}
|
}
|
||||||
ref expr => {
|
ref expr => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!("{} does not support the '*' operation", expr.type_name()),
|
format!("{} does not support the '*' operation", expr.type_name()),
|
||||||
error::ErrorType::Unsupported,
|
error::ErrorType::Unsupported,
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
@ -630,7 +630,7 @@ impl<'a> Builder<'a> {
|
|||||||
eval_binary_expr!(&Val::Float(ff), pos, right, Val::Float(f / ff), "Float")
|
eval_binary_expr!(&Val::Float(ff), pos, right, Val::Float(f / ff), "Float")
|
||||||
}
|
}
|
||||||
ref expr => {
|
ref expr => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!("{} does not support the '*' operation", expr.type_name()),
|
format!("{} does not support the '*' operation", expr.type_name()),
|
||||||
error::ErrorType::Unsupported,
|
error::ErrorType::Unsupported,
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
@ -677,7 +677,7 @@ impl<'a> Builder<'a> {
|
|||||||
return Ok(Rc::new(Val::Boolean(l > r)));
|
return Ok(Rc::new(Val::Boolean(l > r)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Box::new(error::Error::new(
|
Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Incompatible types for numeric comparison {} with {}",
|
"Incompatible types for numeric comparison {} with {}",
|
||||||
left.type_name(),
|
left.type_name(),
|
||||||
@ -700,7 +700,7 @@ impl<'a> Builder<'a> {
|
|||||||
return Ok(Rc::new(Val::Boolean(l < r)));
|
return Ok(Rc::new(Val::Boolean(l < r)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Box::new(error::Error::new(
|
Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Incompatible types for numeric comparison {} with {}",
|
"Incompatible types for numeric comparison {} with {}",
|
||||||
left.type_name(),
|
left.type_name(),
|
||||||
@ -727,7 +727,7 @@ impl<'a> Builder<'a> {
|
|||||||
return Ok(Rc::new(Val::Boolean(l <= r)));
|
return Ok(Rc::new(Val::Boolean(l <= r)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Box::new(error::Error::new(
|
Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Incompatible types for numeric comparison {} with {}",
|
"Incompatible types for numeric comparison {} with {}",
|
||||||
left.type_name(),
|
left.type_name(),
|
||||||
@ -754,7 +754,7 @@ impl<'a> Builder<'a> {
|
|||||||
return Ok(Rc::new(Val::Boolean(l >= r)));
|
return Ok(Rc::new(Val::Boolean(l >= r)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(Box::new(error::Error::new(
|
Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Incompatible types for numeric comparison {} with {}",
|
"Incompatible types for numeric comparison {} with {}",
|
||||||
left.type_name(),
|
left.type_name(),
|
||||||
@ -802,7 +802,7 @@ impl<'a> Builder<'a> {
|
|||||||
v.insert((count, val.clone()));
|
v.insert((count, val.clone()));
|
||||||
count += 1;
|
count += 1;
|
||||||
} else {
|
} else {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Duplicate \
|
"Duplicate \
|
||||||
field: {} in \
|
field: {} in \
|
||||||
@ -829,7 +829,7 @@ impl<'a> Builder<'a> {
|
|||||||
if src_val.1.type_equal(&expr_result) {
|
if src_val.1.type_equal(&expr_result) {
|
||||||
v.insert((src_val.0, expr_result));
|
v.insert((src_val.0, expr_result));
|
||||||
} else {
|
} else {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Expected type {} for field {} but got {}",
|
"Expected type {} for field {} but got {}",
|
||||||
src_val.1.type_name(),
|
src_val.1.type_name(),
|
||||||
@ -861,7 +861,7 @@ impl<'a> Builder<'a> {
|
|||||||
}).collect(),
|
}).collect(),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
Err(Box::new(error::Error::new(
|
Err(Box::new(error::BuildError::new(
|
||||||
format!("Expected Tuple got {}", v),
|
format!("Expected Tuple got {}", v),
|
||||||
error::ErrorType::TypeFail,
|
error::ErrorType::TypeFail,
|
||||||
def.selector.pos.clone(),
|
def.selector.pos.clone(),
|
||||||
@ -898,7 +898,7 @@ impl<'a> Builder<'a> {
|
|||||||
));
|
));
|
||||||
return Ok(Rc::new(Val::Tuple(fields)));
|
return Ok(Rc::new(Val::Tuple(fields)));
|
||||||
}
|
}
|
||||||
Err(Box::new(error::Error::new(
|
Err(Box::new(error::BuildError::new(
|
||||||
// We should pretty print the selectors here.
|
// We should pretty print the selectors here.
|
||||||
format!("{} is not a Macro", v),
|
format!("{} is not a Macro", v),
|
||||||
error::ErrorType::TypeFail,
|
error::ErrorType::TypeFail,
|
||||||
@ -909,7 +909,7 @@ impl<'a> Builder<'a> {
|
|||||||
fn eval_macro_def(&self, def: &MacroDef) -> Result<Rc<Val>, Box<Error>> {
|
fn eval_macro_def(&self, def: &MacroDef) -> Result<Rc<Val>, Box<Error>> {
|
||||||
match def.validate_symbols() {
|
match def.validate_symbols() {
|
||||||
Ok(()) => Ok(Rc::new(Val::Macro(def.clone()))),
|
Ok(()) => Ok(Rc::new(Val::Macro(def.clone()))),
|
||||||
Err(set) => Err(Box::new(error::Error::new(
|
Err(set) => Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Macro has the following \
|
"Macro has the following \
|
||||||
undefined symbols: {:?}",
|
undefined symbols: {:?}",
|
||||||
@ -939,7 +939,7 @@ impl<'a> Builder<'a> {
|
|||||||
// Otherwise return the default.
|
// Otherwise return the default.
|
||||||
return self.eval_expr(def_expr);
|
return self.eval_expr(def_expr);
|
||||||
} else {
|
} else {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!(
|
format!(
|
||||||
"Expected String but got \
|
"Expected String but got \
|
||||||
{} in Select expression",
|
{} in Select expression",
|
||||||
@ -956,7 +956,7 @@ impl<'a> Builder<'a> {
|
|||||||
let l = match maybe_list.as_ref() {
|
let l = match maybe_list.as_ref() {
|
||||||
&Val::List(ref elems) => elems,
|
&Val::List(ref elems) => elems,
|
||||||
other => {
|
other => {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!("Expected List as target but got {:?}", other.type_name()),
|
format!("Expected List as target but got {:?}", other.type_name()),
|
||||||
error::ErrorType::TypeFail,
|
error::ErrorType::TypeFail,
|
||||||
def.target.pos().clone(),
|
def.target.pos().clone(),
|
||||||
@ -994,7 +994,7 @@ impl<'a> Builder<'a> {
|
|||||||
}
|
}
|
||||||
return Ok(Rc::new(Val::List(out)));
|
return Ok(Rc::new(Val::List(out)));
|
||||||
}
|
}
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
format!("Expected macro but got {:?}", mac),
|
format!("Expected macro but got {:?}", mac),
|
||||||
error::ErrorType::TypeFail,
|
error::ErrorType::TypeFail,
|
||||||
def.pos.clone(),
|
def.pos.clone(),
|
||||||
|
@ -22,7 +22,7 @@ use build::Val;
|
|||||||
use build::Val::Tuple;
|
use build::Val::Tuple;
|
||||||
use convert;
|
use convert;
|
||||||
use convert::traits::{Converter, Result};
|
use convert::traits::{Converter, Result};
|
||||||
use error::Error;
|
use error::BuildError;
|
||||||
use error::ErrorType;
|
use error::ErrorType;
|
||||||
|
|
||||||
pub struct ExecConverter {}
|
pub struct ExecConverter {}
|
||||||
@ -43,7 +43,7 @@ impl ExecConverter {
|
|||||||
if let &Tuple(ref fields) = v {
|
if let &Tuple(ref fields) = v {
|
||||||
// We expect no more than three fields in our exec tuple.
|
// We expect no more than three fields in our exec tuple.
|
||||||
if fields.len() > 3 {
|
if fields.len() > 3 {
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"Exec tuples must have no more than 3 fields",
|
"Exec tuples must have no more than 3 fields",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
Position::new(0, 0, 0),
|
Position::new(0, 0, 0),
|
||||||
@ -56,7 +56,7 @@ impl ExecConverter {
|
|||||||
// We require a command field in our exec tuple.
|
// We require a command field in our exec tuple.
|
||||||
if name.val == "command" {
|
if name.val == "command" {
|
||||||
if command.is_some() {
|
if command.is_some() {
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"There can only be one command field in an exec tuple",
|
"There can only be one command field in an exec tuple",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
name.pos.clone(),
|
name.pos.clone(),
|
||||||
@ -66,7 +66,7 @@ impl ExecConverter {
|
|||||||
command = Some(s);
|
command = Some(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"The command field of an exec tuple must be a string",
|
"The command field of an exec tuple must be a string",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
name.pos.clone(),
|
name.pos.clone(),
|
||||||
@ -76,7 +76,7 @@ impl ExecConverter {
|
|||||||
if name.val == "env" {
|
if name.val == "env" {
|
||||||
if let &Val::Tuple(ref l) = val.as_ref() {
|
if let &Val::Tuple(ref l) = val.as_ref() {
|
||||||
if env.is_some() {
|
if env.is_some() {
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"There can only be one env field in an exec tuple",
|
"There can only be one env field in an exec tuple",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
name.pos.clone(),
|
name.pos.clone(),
|
||||||
@ -85,7 +85,7 @@ impl ExecConverter {
|
|||||||
env = Some(l);
|
env = Some(l);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"The env field of an exec tuple must be a list",
|
"The env field of an exec tuple must be a list",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
name.pos.clone(),
|
name.pos.clone(),
|
||||||
@ -95,7 +95,7 @@ impl ExecConverter {
|
|||||||
if name.val == "args" {
|
if name.val == "args" {
|
||||||
if let &Val::List(ref l) = val.as_ref() {
|
if let &Val::List(ref l) = val.as_ref() {
|
||||||
if args.is_some() {
|
if args.is_some() {
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"There can only be one args field of an exec tuple",
|
"There can only be one args field of an exec tuple",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
name.pos.clone(),
|
name.pos.clone(),
|
||||||
@ -104,7 +104,7 @@ impl ExecConverter {
|
|||||||
args = Some(l);
|
args = Some(l);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"The args field of an exec tuple must be a list",
|
"The args field of an exec tuple must be a list",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
name.pos.clone(),
|
name.pos.clone(),
|
||||||
@ -112,7 +112,7 @@ impl ExecConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if command.is_none() {
|
if command.is_none() {
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"An exec tuple must have a command field",
|
"An exec tuple must have a command field",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
Position::new(0, 0, 0),
|
Position::new(0, 0, 0),
|
||||||
@ -133,7 +133,7 @@ impl ExecConverter {
|
|||||||
try!(write!(script, "{}=\"{}\"\n", name.val, s));
|
try!(write!(script, "{}=\"{}\"\n", name.val, s));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"The env fields of an exec tuple must contain only string values",
|
"The env fields of an exec tuple must contain only string values",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
name.pos.clone(),
|
name.pos.clone(),
|
||||||
@ -154,7 +154,7 @@ impl ExecConverter {
|
|||||||
}
|
}
|
||||||
&Val::Tuple(_) => try!(flag_converter.convert(v.clone(), &mut script)),
|
&Val::Tuple(_) => try!(flag_converter.convert(v.clone(), &mut script)),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Box::new(Error::new(
|
return Err(Box::new(BuildError::new(
|
||||||
"Exec args must be a list of strings or tuples of strings.",
|
"Exec args must be a list of strings or tuples of strings.",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
Position::new(0, 0, 0),
|
Position::new(0, 0, 0),
|
||||||
@ -170,7 +170,7 @@ impl ExecConverter {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(Box::new(Error::new(
|
Err(Box::new(BuildError::new(
|
||||||
"Exec outputs must be of type Tuple",
|
"Exec outputs must be of type Tuple",
|
||||||
ErrorType::TypeFail,
|
ErrorType::TypeFail,
|
||||||
Position::new(0, 0, 0),
|
Position::new(0, 0, 0),
|
||||||
|
18
src/error.rs
18
src/error.rs
@ -27,14 +27,11 @@ pub enum ErrorType {
|
|||||||
// Build Errors
|
// Build Errors
|
||||||
TypeFail,
|
TypeFail,
|
||||||
DuplicateBinding,
|
DuplicateBinding,
|
||||||
IncompleteParsing,
|
|
||||||
Unsupported,
|
Unsupported,
|
||||||
NoSuchSymbol,
|
NoSuchSymbol,
|
||||||
BadArgLen,
|
BadArgLen,
|
||||||
FormatError,
|
FormatError,
|
||||||
// Parsing Errors
|
// Parsing Errors
|
||||||
UnexpectedToken,
|
|
||||||
EmptyExpression,
|
|
||||||
ParseError,
|
ParseError,
|
||||||
AssertError,
|
AssertError,
|
||||||
}
|
}
|
||||||
@ -44,13 +41,10 @@ impl fmt::Display for ErrorType {
|
|||||||
let name = match self {
|
let name = match self {
|
||||||
&ErrorType::TypeFail => "TypeFail",
|
&ErrorType::TypeFail => "TypeFail",
|
||||||
&ErrorType::DuplicateBinding => "DuplicateBinding",
|
&ErrorType::DuplicateBinding => "DuplicateBinding",
|
||||||
&ErrorType::IncompleteParsing => "IncompleteParsing",
|
|
||||||
&ErrorType::Unsupported => "Unsupported",
|
&ErrorType::Unsupported => "Unsupported",
|
||||||
&ErrorType::NoSuchSymbol => "NoSuchSymbol",
|
&ErrorType::NoSuchSymbol => "NoSuchSymbol",
|
||||||
&ErrorType::BadArgLen => "BadArgLen",
|
&ErrorType::BadArgLen => "BadArgLen",
|
||||||
&ErrorType::FormatError => "FormatError",
|
&ErrorType::FormatError => "FormatError",
|
||||||
&ErrorType::UnexpectedToken => "UnexpectedToken",
|
|
||||||
&ErrorType::EmptyExpression => "EmptyExpression",
|
|
||||||
&ErrorType::ParseError => "ParseError",
|
&ErrorType::ParseError => "ParseError",
|
||||||
&ErrorType::AssertError => "AssertError",
|
&ErrorType::AssertError => "AssertError",
|
||||||
};
|
};
|
||||||
@ -59,16 +53,16 @@ impl fmt::Display for ErrorType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Error defines an Error type for parsing and building UCG code.
|
/// Error defines an Error type for parsing and building UCG code.
|
||||||
pub struct Error {
|
pub struct BuildError {
|
||||||
pub err_type: ErrorType,
|
pub err_type: ErrorType,
|
||||||
pub pos: Position,
|
pub pos: Position,
|
||||||
pub msg: String,
|
pub msg: String,
|
||||||
_pkgonly: (),
|
_pkgonly: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl BuildError {
|
||||||
pub fn new<S: Into<String>>(msg: S, t: ErrorType, pos: Position) -> Self {
|
pub fn new<S: Into<String>>(msg: S, t: ErrorType, pos: Position) -> Self {
|
||||||
Error {
|
BuildError {
|
||||||
err_type: t,
|
err_type: t,
|
||||||
pos: pos,
|
pos: pos,
|
||||||
msg: msg.into(),
|
msg: msg.into(),
|
||||||
@ -86,19 +80,19 @@ impl Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Error {
|
impl Debug for BuildError {
|
||||||
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
|
||||||
self.render(w)
|
self.render(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for BuildError {
|
||||||
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
|
||||||
self.render(w)
|
self.render(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for Error {
|
impl error::Error for BuildError {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
&self.msg
|
&self.msg
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ impl<V: Into<String> + Clone> Formatter<V> {
|
|||||||
for c in self.tmpl.chars() {
|
for c in self.tmpl.chars() {
|
||||||
if c == '@' && !should_escape {
|
if c == '@' && !should_escape {
|
||||||
if count == self.args.len() {
|
if count == self.args.len() {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
"Too few arguments to string \
|
"Too few arguments to string \
|
||||||
formatter.",
|
formatter.",
|
||||||
error::ErrorType::FormatError,
|
error::ErrorType::FormatError,
|
||||||
@ -63,7 +63,7 @@ impl<V: Into<String> + Clone> Formatter<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.args.len() != count {
|
if self.args.len() != count {
|
||||||
return Err(Box::new(error::Error::new(
|
return Err(Box::new(error::BuildError::new(
|
||||||
"Too many arguments to string \
|
"Too many arguments to string \
|
||||||
formatter.",
|
formatter.",
|
||||||
error::ErrorType::FormatError,
|
error::ErrorType::FormatError,
|
||||||
|
@ -846,7 +846,7 @@ make_fn!(
|
|||||||
name => wrap_err!(match_type!(BAREWORD), "Expected name for binding"),
|
name => wrap_err!(match_type!(BAREWORD), "Expected name for binding"),
|
||||||
_ => punct!("="),
|
_ => punct!("="),
|
||||||
// TODO(jwall): Wrap this error with an appropriate abortable_parser::Error
|
// TODO(jwall): Wrap this error with an appropriate abortable_parser::Error
|
||||||
val => wrap_err!(trace_nom!(expression), "Expected Expression"),
|
val => with_err!(trace_nom!(expression), "Expected Expression"),
|
||||||
_ => punct!(";"),
|
_ => punct!(";"),
|
||||||
(tuple_to_let(name, val))
|
(tuple_to_let(name, val))
|
||||||
)
|
)
|
||||||
@ -904,7 +904,7 @@ make_fn!(
|
|||||||
do_each!(
|
do_each!(
|
||||||
_ => word!("out"),
|
_ => word!("out"),
|
||||||
typ => wrap_err!(must!(match_type!(BAREWORD)), "Expected converter name"),
|
typ => wrap_err!(must!(match_type!(BAREWORD)), "Expected converter name"),
|
||||||
expr => wrap_err!(must!(expression), "Expected Expression to export"),
|
expr => with_err!(must!(expression), "Expected Expression to export"),
|
||||||
_ => must!(punct!(";")),
|
_ => must!(punct!(";")),
|
||||||
(Statement::Output(typ.clone(), expr.clone()))
|
(Statement::Output(typ.clone(), expr.clone()))
|
||||||
)
|
)
|
||||||
@ -937,21 +937,11 @@ pub fn parse<'a>(input: OffsetStrIter<'a>) -> std::result::Result<Vec<Statement>
|
|||||||
}
|
}
|
||||||
match statement(i.clone()) {
|
match statement(i.clone()) {
|
||||||
Result::Abort(e) => {
|
Result::Abort(e) => {
|
||||||
let err = abortable_parser::Error::caused_by(
|
let ctx_err = StackPrinter { err: e };
|
||||||
"Statement Parse Error",
|
|
||||||
Box::new(e),
|
|
||||||
Box::new(i.clone()),
|
|
||||||
);
|
|
||||||
let ctx_err = StackPrinter { err: err };
|
|
||||||
return Err(format!("{}", ctx_err));
|
return Err(format!("{}", ctx_err));
|
||||||
}
|
}
|
||||||
Result::Fail(e) => {
|
Result::Fail(e) => {
|
||||||
let err = abortable_parser::Error::caused_by(
|
let ctx_err = StackPrinter { err: e };
|
||||||
"Statement Parse Error",
|
|
||||||
Box::new(e),
|
|
||||||
Box::new(i.clone()),
|
|
||||||
);
|
|
||||||
let ctx_err = StackPrinter { err: err };
|
|
||||||
return Err(format!("{}", ctx_err));
|
return Err(format!("{}", ctx_err));
|
||||||
}
|
}
|
||||||
Result::Incomplete(_ei) => {
|
Result::Incomplete(_ei) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user