MAINT: Opt in to 2018 edition of Rust.

This commit is contained in:
Jeremy Wall 2018-12-06 12:23:52 -06:00
parent 10d13de5a0
commit e9a0bde631
23 changed files with 183 additions and 182 deletions

View File

@ -1,4 +1,5 @@
[package] [package]
edition = "2018"
name = "ucg" name = "ucg"
version = "0.2.6" version = "0.2.6"
authors = ["Jeremy Wall <jeremy@marzhillstudios.com>"] authors = ["Jeremy Wall <jeremy@marzhillstudios.com>"]

View File

@ -29,7 +29,7 @@ use std::rc::Rc;
use abortable_parser; use abortable_parser;
use build::Val; use crate::build::Val;
macro_rules! enum_type_equality { macro_rules! enum_type_equality {
( $slf:ident, $r:expr, $( $l:pat ),* ) => { ( $slf:ident, $r:expr, $( $l:pat ),* ) => {
@ -304,10 +304,10 @@ impl fmt::Debug for SelectorList {
impl fmt::Display for SelectorList { impl fmt::Display for SelectorList {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
try!(write!(w, "{}", self.head)); r#try!(write!(w, "{}", self.head));
if let Some(ref tok_vec) = self.tail { if let Some(ref tok_vec) = self.tail {
for t in tok_vec.iter() { for t in tok_vec.iter() {
try!(write!(w, ".{}", t.fragment)); r#try!(write!(w, ".{}", t.fragment));
} }
} }
return Ok(()); return Ok(());
@ -736,7 +736,7 @@ impl ModuleDef {
pub fn imports_to_absolute(&mut self, base: PathBuf) { pub fn imports_to_absolute(&mut self, base: PathBuf) {
for stmt in self.statements.iter_mut() { for stmt in self.statements.iter_mut() {
if let &mut Statement::Import(ref mut def) = stmt { if let &mut Statement::Import(ref mut def) = stmt {
let mut path = PathBuf::from(&def.path.fragment); let path = PathBuf::from(&def.path.fragment);
if path.is_relative() { if path.is_relative() {
def.path.fragment = base def.path.fragment = base
.join(path) .join(path)
@ -795,37 +795,37 @@ impl fmt::Display for Expression {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
&Expression::Simple(ref v) => { &Expression::Simple(ref v) => {
try!(write!(w, "{}", v.to_string())); r#try!(write!(w, "{}", v.to_string()));
} }
&Expression::Binary(_) => { &Expression::Binary(_) => {
try!(write!(w, "<Expr>")); r#try!(write!(w, "<Expr>"));
} }
&Expression::Compare(_) => { &Expression::Compare(_) => {
try!(write!(w, "<Expr>")); r#try!(write!(w, "<Expr>"));
} }
&Expression::ListOp(_) => { &Expression::ListOp(_) => {
try!(write!(w, "<Expr>")); r#try!(write!(w, "<Expr>"));
} }
&Expression::Copy(_) => { &Expression::Copy(_) => {
try!(write!(w, "<Copy>")); r#try!(write!(w, "<Copy>"));
} }
&Expression::Grouped(_) => { &Expression::Grouped(_) => {
try!(write!(w, "(<Expr>)")); r#try!(write!(w, "(<Expr>)"));
} }
&Expression::Format(_) => { &Expression::Format(_) => {
try!(write!(w, "<Format Expr>")); r#try!(write!(w, "<Format Expr>"));
} }
&Expression::Call(_) => { &Expression::Call(_) => {
try!(write!(w, "<MacroCall>")); r#try!(write!(w, "<MacroCall>"));
} }
&Expression::Macro(_) => { &Expression::Macro(_) => {
try!(write!(w, "<Macro>")); r#try!(write!(w, "<Macro>"));
} }
&Expression::Module(_) => { &Expression::Module(_) => {
try!(write!(w, "<Module>")); r#try!(write!(w, "<Module>"));
} }
&Expression::Select(_) => { &Expression::Select(_) => {
try!(write!(w, "<Select>")); r#try!(write!(w, "<Select>"));
} }
} }
Ok(()) Ok(())

View File

@ -51,17 +51,17 @@ impl MemoryCache {
impl Cache for MemoryCache { impl Cache for MemoryCache {
fn has_path(&self, path: &PathBuf) -> Result<bool> { fn has_path(&self, path: &PathBuf) -> Result<bool> {
let new_path = try!(path.canonicalize()); let new_path = r#try!(path.canonicalize());
Ok(self.map.contains_key(&new_path)) Ok(self.map.contains_key(&new_path))
} }
fn get(&self, path: &PathBuf) -> Result<Option<Rc<Val>>> { fn get(&self, path: &PathBuf) -> Result<Option<Rc<Val>>> {
let new_path = try!(path.canonicalize()); let new_path = r#try!(path.canonicalize());
Ok(self.map.get(&new_path).map(|v| v.clone())) Ok(self.map.get(&new_path).map(|v| v.clone()))
} }
fn stash(&mut self, path: PathBuf, asset: Rc<Val>) -> Result<()> { fn stash(&mut self, path: PathBuf, asset: Rc<Val>) -> Result<()> {
let new_path = try!(path.canonicalize()); let new_path = r#try!(path.canonicalize());
self.map.insert(new_path, asset); self.map.insert(new_path, asset);
Ok(()) Ok(())
} }

View File

@ -6,8 +6,8 @@ use std::fmt::{Display, Formatter};
use std::rc::Rc; use std::rc::Rc;
use std::string::ToString; use std::string::ToString;
use ast::*; use crate::ast::*;
use error; use crate::error;
/// The Intermediate representation of a compiled UCG AST. /// The Intermediate representation of a compiled UCG AST.
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Debug, Clone)]
@ -73,7 +73,7 @@ impl Val {
Ok(false) Ok(false)
} else { } else {
for (i, lv) in ldef.iter().enumerate() { for (i, lv) in ldef.iter().enumerate() {
try!(lv.equal(rdef[i].as_ref(), pos.clone())); r#try!(lv.equal(rdef[i].as_ref(), pos.clone()));
} }
Ok(true) Ok(true)
} }
@ -89,7 +89,7 @@ impl Val {
return Ok(false); return Ok(false);
} else { } else {
// field value equality. // field value equality.
if !try!(lv.1.equal(field_target.1.as_ref(), lv.0.pos.clone())) { if !r#try!(lv.1.equal(field_target.1.as_ref(), lv.0.pos.clone())) {
return Ok(false); return Ok(false);
} }
} }
@ -190,25 +190,25 @@ impl Display for Val {
&Val::Int(ref i) => write!(f, "Int({})", i), &Val::Int(ref i) => write!(f, "Int({})", i),
&Val::Str(ref s) => write!(f, "String({})", s), &Val::Str(ref s) => write!(f, "String({})", s),
&Val::List(ref def) => { &Val::List(ref def) => {
try!(write!(f, "[\n")); r#try!(write!(f, "[\n"));
for v in def.iter() { for v in def.iter() {
try!(write!(f, "\t{},\n", v)); r#try!(write!(f, "\t{},\n", v));
} }
write!(f, "]") write!(f, "]")
} }
&Val::Macro(_) => write!(f, "Macro(..)"), &Val::Macro(_) => write!(f, "Macro(..)"),
&Val::Module(_) => write!(f, "Module{{..}}"), &Val::Module(_) => write!(f, "Module{{..}}"),
&Val::Tuple(ref def) => { &Val::Tuple(ref def) => {
try!(write!(f, "Tuple(\n")); r#try!(write!(f, "Tuple(\n"));
for v in def.iter() { for v in def.iter() {
try!(write!(f, "\t{} = {},\n", v.0.val, v.1)); r#try!(write!(f, "\t{} = {},\n", v.0.val, v.1));
} }
write!(f, ")") write!(f, ")")
} }
&Val::Env(ref def) => { &Val::Env(ref def) => {
try!(write!(f, "Env(\n")); r#try!(write!(f, "Env(\n"));
for v in def.iter() { for v in def.iter() {
try!(write!(f, "\t{}=\"{}\"\n", v.0, v.1)); r#try!(write!(f, "\t{}=\"{}\"\n", v.0, v.1));
} }
write!(f, ")") write!(f, ")")
} }

View File

@ -27,11 +27,11 @@ use std::string::ToString;
use simple_error; use simple_error;
use ast::*; use crate::ast::*;
use error; use crate::error;
use format; use crate::format;
use iter::OffsetStrIter; use crate::iter::OffsetStrIter;
use parse::parse; use crate::parse::parse;
pub mod assets; pub mod assets;
pub mod ir; pub mod ir;
@ -72,7 +72,7 @@ impl MacroDef {
for &(ref key, ref expr) in self.fields.iter() { for &(ref key, ref expr) in self.fields.iter() {
// We clone the expressions here because this macro may be consumed // We clone the expressions here because this macro may be consumed
// multiple times in the future. // multiple times in the future.
let val = try!(b.eval_expr(expr)); let val = r#try!(b.eval_expr(expr));
result.push((key.into(), val.clone())); result.push((key.into(), val.clone()));
} }
Ok(result) Ok(result)
@ -197,7 +197,7 @@ impl Builder {
fn tuple_to_val(&mut self, fields: &Vec<(Token, Expression)>) -> Result<Rc<Val>, Box<Error>> { fn tuple_to_val(&mut self, fields: &Vec<(Token, Expression)>) -> Result<Rc<Val>, Box<Error>> {
let mut new_fields = Vec::<(PositionedItem<String>, Rc<Val>)>::new(); let mut new_fields = Vec::<(PositionedItem<String>, Rc<Val>)>::new();
for &(ref name, ref expr) in fields.iter() { for &(ref name, ref expr) in fields.iter() {
let val = try!(self.eval_expr(expr)); let val = r#try!(self.eval_expr(expr));
new_fields.push((name.into(), val)); new_fields.push((name.into(), val));
} }
Ok(Rc::new(Val::Tuple(new_fields))) Ok(Rc::new(Val::Tuple(new_fields)))
@ -206,7 +206,7 @@ impl Builder {
fn list_to_val(&mut self, def: &ListDef) -> Result<Rc<Val>, Box<Error>> { fn list_to_val(&mut self, def: &ListDef) -> Result<Rc<Val>, Box<Error>> {
let mut vals = Vec::new(); let mut vals = Vec::new();
for expr in def.elems.iter() { for expr in def.elems.iter() {
vals.push(try!(self.eval_expr(expr))); vals.push(r#try!(self.eval_expr(expr)));
} }
Ok(Rc::new(Val::List(vals))) Ok(Rc::new(Val::List(vals)))
} }
@ -254,7 +254,7 @@ impl Builder {
/// Builds a list of parsed UCG Statements. /// Builds a list of parsed UCG Statements.
pub fn eval_stmts(&mut self, ast: &Vec<Statement>) -> BuildResult { pub fn eval_stmts(&mut self, ast: &Vec<Statement>) -> BuildResult {
for stmt in ast.iter() { for stmt in ast.iter() {
try!(self.eval_stmt(stmt)); r#try!(self.eval_stmt(stmt));
} }
Ok(()) Ok(())
} }
@ -265,7 +265,7 @@ impl Builder {
//panic!("Successfully parsed {}", input); //panic!("Successfully parsed {}", input);
let mut out: Option<Rc<Val>> = None; let mut out: Option<Rc<Val>> = None;
for stmt in stmts.iter() { for stmt in stmts.iter() {
out = Some(try!(self.eval_stmt(stmt))); out = Some(r#try!(self.eval_stmt(stmt)));
} }
match out { match out {
None => return Ok(Rc::new(Val::Empty)), None => return Ok(Rc::new(Val::Empty)),
@ -287,9 +287,9 @@ impl Builder {
/// Builds a ucg file at the named path. /// Builds a ucg file at the named path.
pub fn build(&mut self) -> BuildResult { pub fn build(&mut self) -> BuildResult {
let mut f = try!(File::open(&self.file)); let mut f = r#try!(File::open(&self.file));
let mut s = String::new(); let mut s = String::new();
try!(f.read_to_string(&mut s)); r#try!(f.read_to_string(&mut s));
let eval_result = self.eval_string(&s); let eval_result = self.eval_string(&s);
match eval_result { match eval_result {
Ok(v) => { Ok(v) => {
@ -340,7 +340,7 @@ impl Builder {
} else { } else {
normalized = import_path; normalized = import_path;
} }
normalized = try!(normalized.canonicalize()); normalized = r#try!(normalized.canonicalize());
if self.detect_import_cycle(normalized.to_string_lossy().as_ref()) { if self.detect_import_cycle(normalized.to_string_lossy().as_ref()) {
return Err(Box::new(error::BuildError::new( return Err(Box::new(error::BuildError::new(
format!( format!(
@ -356,13 +356,13 @@ impl Builder {
// Introduce a scope so the above borrow is dropped before we modify // Introduce a scope so the above borrow is dropped before we modify
// the cache below. // the cache below.
// Only parse the file once on import. // Only parse the file once on import.
let maybe_asset = try!(self.assets.borrow().get(&normalized)); let maybe_asset = r#try!(self.assets.borrow().get(&normalized));
let result = match maybe_asset { let result = match maybe_asset {
Some(v) => v.clone(), Some(v) => v.clone(),
None => { None => {
let mut b = Self::new(normalized.clone(), self.assets.clone()); let mut b = Self::new(normalized.clone(), self.assets.clone());
b.prepend_import_stack(&self.import_stack); b.prepend_import_stack(&self.import_stack);
try!(b.build()); r#try!(b.build());
b.get_outputs_as_val() b.get_outputs_as_val()
} }
}; };
@ -376,12 +376,12 @@ impl Builder {
} }
self.build_output.insert(key, result.clone()); self.build_output.insert(key, result.clone());
let mut mut_assets_cache = self.assets.borrow_mut(); let mut mut_assets_cache = self.assets.borrow_mut();
try!(mut_assets_cache.stash(normalized.clone(), result.clone())); r#try!(mut_assets_cache.stash(normalized.clone(), result.clone()));
return Ok(result); return Ok(result);
} }
fn eval_let(&mut self, def: &LetDef) -> Result<Rc<Val>, Box<Error>> { fn eval_let(&mut self, def: &LetDef) -> Result<Rc<Val>, Box<Error>> {
let val = try!(self.eval_expr(&def.value)); let val = r#try!(self.eval_expr(&def.value));
let name = &def.name; let name = &def.name;
// TODO(jwall): Enforce the reserved words list here. // TODO(jwall): Enforce the reserved words list here.
if Self::check_reserved_word(&name.fragment) { if Self::check_reserved_word(&name.fragment) {
@ -421,7 +421,7 @@ impl Builder {
// having a single builder per file. // having a single builder per file.
&Statement::Output(ref typ, ref expr) => { &Statement::Output(ref typ, ref expr) => {
if let None = self.out_lock { if let None = self.out_lock {
let val = try!(self.eval_expr(expr)); let val = r#try!(self.eval_expr(expr));
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 {
@ -518,7 +518,7 @@ impl Builder {
next: (&Position, &str), next: (&Position, &str),
elems: &Vec<Rc<Val>>, elems: &Vec<Rc<Val>>,
) -> Result<(), Box<Error>> { ) -> Result<(), Box<Error>> {
let idx = try!(next.1.parse::<usize>()); let idx = r#try!(next.1.parse::<usize>());
if idx < elems.len() { if idx < elems.len() {
stack.push_back(elems[idx].clone()); stack.push_back(elems[idx].clone());
} else { } else {
@ -537,7 +537,7 @@ impl Builder {
} }
fn lookup_selector(&mut self, sl: &SelectorList) -> Result<Rc<Val>, Box<Error>> { fn lookup_selector(&mut self, sl: &SelectorList) -> Result<Rc<Val>, Box<Error>> {
let first = try!(self.eval_expr(&sl.head)); let first = r#try!(self.eval_expr(&sl.head));
// First we ensure that the result is a tuple or a list. // First we ensure that the result is a tuple or a list.
let mut stack = VecDeque::new(); let mut stack = VecDeque::new();
match first.as_ref() { match first.as_ref() {
@ -570,15 +570,15 @@ impl Builder {
let next = it.next().unwrap(); let next = it.next().unwrap();
match vref.as_ref() { match vref.as_ref() {
&Val::Tuple(ref fs) => { &Val::Tuple(ref fs) => {
try!(self.lookup_in_tuple(&mut stack, sl, (&next.pos, &next.fragment), fs)); r#try!(self.lookup_in_tuple(&mut stack, sl, (&next.pos, &next.fragment), fs));
continue; continue;
} }
&Val::Env(ref fs) => { &Val::Env(ref fs) => {
try!(self.lookup_in_env(&next, &mut stack, fs)); r#try!(self.lookup_in_env(&next, &mut stack, fs));
continue; continue;
} }
&Val::List(ref elems) => { &Val::List(ref elems) => {
try!(self.lookup_in_list( r#try!(self.lookup_in_list(
&mut stack, &mut stack,
sl, sl,
(&next.pos, &next.fragment), (&next.pos, &next.fragment),
@ -737,7 +737,7 @@ impl Builder {
left: Rc<Val>, left: Rc<Val>,
right: Rc<Val>, right: Rc<Val>,
) -> Result<Rc<Val>, Box<Error>> { ) -> Result<Rc<Val>, Box<Error>> {
Ok(Rc::new(Val::Boolean(try!( Ok(Rc::new(Val::Boolean(r#try!(
left.equal(right.as_ref(), pos.clone()) left.equal(right.as_ref(), pos.clone())
)))) ))))
} }
@ -748,7 +748,7 @@ impl Builder {
left: Rc<Val>, left: Rc<Val>,
right: Rc<Val>, right: Rc<Val>,
) -> Result<Rc<Val>, Box<Error>> { ) -> Result<Rc<Val>, Box<Error>> {
Ok(Rc::new(Val::Boolean(!try!( Ok(Rc::new(Val::Boolean(!r#try!(
left.equal(right.as_ref(), pos.clone()) left.equal(right.as_ref(), pos.clone())
)))) ))))
} }
@ -855,8 +855,8 @@ impl Builder {
fn eval_binary(&mut self, def: &BinaryOpDef) -> Result<Rc<Val>, Box<Error>> { fn eval_binary(&mut self, def: &BinaryOpDef) -> Result<Rc<Val>, Box<Error>> {
let kind = &def.kind; let kind = &def.kind;
let left = try!(self.eval_expr(&def.left)); let left = r#try!(self.eval_expr(&def.left));
let right = try!(self.eval_expr(&def.right)); let right = r#try!(self.eval_expr(&def.right));
match kind { match kind {
&BinaryExprType::Add => self.add_vals(&def.pos, left, right), &BinaryExprType::Add => self.add_vals(&def.pos, left, right),
&BinaryExprType::Sub => self.subtract_vals(&def.pos, left, right), &BinaryExprType::Sub => self.subtract_vals(&def.pos, left, right),
@ -867,8 +867,8 @@ impl Builder {
fn eval_compare(&mut self, def: &ComparisonDef) -> Result<Rc<Val>, Box<Error>> { fn eval_compare(&mut self, def: &ComparisonDef) -> Result<Rc<Val>, Box<Error>> {
let kind = &def.kind; let kind = &def.kind;
let left = try!(self.eval_expr(&def.left)); let left = r#try!(self.eval_expr(&def.left));
let right = try!(self.eval_expr(&def.right)); let right = r#try!(self.eval_expr(&def.right));
match kind { match kind {
&CompareType::Equal => self.do_deep_equal(&def.pos, left, right), &CompareType::Equal => self.do_deep_equal(&def.pos, left, right),
&CompareType::GT => self.do_gt(&def.pos, left, right), &CompareType::GT => self.do_gt(&def.pos, left, right),
@ -937,7 +937,7 @@ impl Builder {
} }
} }
for &(ref key, ref val) in overrides.iter() { for &(ref key, ref val) in overrides.iter() {
let expr_result = try!(self.eval_expr(val)); let expr_result = r#try!(self.eval_expr(val));
match m.entry(key.into()) { match m.entry(key.into()) {
// brand new field here. // brand new field here.
Entry::Vacant(v) => { Entry::Vacant(v) => {
@ -990,7 +990,7 @@ impl Builder {
} }
fn eval_copy(&mut self, def: &CopyDef) -> Result<Rc<Val>, Box<Error>> { fn eval_copy(&mut self, def: &CopyDef) -> Result<Rc<Val>, Box<Error>> {
let v = try!(self.lookup_selector(&def.selector.sel)); let v = r#try!(self.lookup_selector(&def.selector.sel));
if let &Val::Tuple(ref src_fields) = v.as_ref() { if let &Val::Tuple(ref src_fields) = v.as_ref() {
self.push_val(v.clone()); self.push_val(v.clone());
return self.copy_from_base(&src_fields, &def.fields); return self.copy_from_base(&src_fields, &def.fields);
@ -1006,7 +1006,7 @@ impl Builder {
// Push our base tuple on the stack so the copy can use // Push our base tuple on the stack so the copy can use
// self to reference it. // self to reference it.
b.push_val(maybe_tpl.clone()); b.push_val(maybe_tpl.clone());
let mod_args = try!(self.copy_from_base(src_fields, &def.fields)); let mod_args = r#try!(self.copy_from_base(src_fields, &def.fields));
// put our copied parameters tuple in our builder under the mod key. // put our copied parameters tuple in our builder under the mod key.
let mod_key = let mod_key =
PositionedItem::new_with_pos(String::from("mod"), Position::new(0, 0, 0)); PositionedItem::new_with_pos(String::from("mod"), Position::new(0, 0, 0));
@ -1028,7 +1028,7 @@ impl Builder {
} }
} }
// 4. Evaluate all the statements using the builder. // 4. Evaluate all the statements using the builder.
try!(b.eval_stmts(&mod_def.statements)); r#try!(b.eval_stmts(&mod_def.statements));
// 5. Take all of the bindings in the module and construct a new // 5. Take all of the bindings in the module and construct a new
// tuple using them. // tuple using them.
return Ok(b.get_outputs_as_val()); return Ok(b.get_outputs_as_val());
@ -1055,25 +1055,25 @@ impl Builder {
let args = &def.args; let args = &def.args;
let mut vals = Vec::new(); let mut vals = Vec::new();
for v in args.iter() { for v in args.iter() {
let rcv = try!(self.eval_expr(v)); let rcv = r#try!(self.eval_expr(v));
vals.push(rcv.deref().clone()); vals.push(rcv.deref().clone());
} }
let formatter = format::Formatter::new(tmpl.clone(), vals); let formatter = format::Formatter::new(tmpl.clone(), vals);
Ok(Rc::new(Val::Str(try!(formatter.render(&def.pos))))) Ok(Rc::new(Val::Str(r#try!(formatter.render(&def.pos)))))
} }
// FIXME(jwall): Handle module calls as well? // FIXME(jwall): Handle module calls as well?
fn eval_call(&mut self, def: &CallDef) -> Result<Rc<Val>, Box<Error>> { fn eval_call(&mut self, def: &CallDef) -> Result<Rc<Val>, Box<Error>> {
let sel = &def.macroref; let sel = &def.macroref;
let args = &def.arglist; let args = &def.arglist;
let v = try!(self.lookup_selector(&sel.sel)); let v = r#try!(self.lookup_selector(&sel.sel));
if let &Val::Macro(ref m) = v.deref() { if let &Val::Macro(ref m) = v.deref() {
// Congratulations this is actually a macro. // Congratulations this is actually a macro.
let mut argvals: Vec<Rc<Val>> = Vec::new(); let mut argvals: Vec<Rc<Val>> = Vec::new();
for arg in args.iter() { for arg in args.iter() {
argvals.push(try!(self.eval_expr(arg))); argvals.push(r#try!(self.eval_expr(arg)));
} }
let fields = try!(m.eval( let fields = r#try!(m.eval(
self.file.clone(), self.file.clone(),
self.assets.clone(), self.assets.clone(),
self.env.clone(), self.env.clone(),
@ -1121,7 +1121,7 @@ impl Builder {
// First we rewrite the imports to be absolute paths. // First we rewrite the imports to be absolute paths.
def.imports_to_absolute(root); def.imports_to_absolute(root);
// Then we create our tuple default. // Then we create our tuple default.
def.arg_tuple = Some(try!(self.tuple_to_val(&def.arg_set))); def.arg_tuple = Some(r#try!(self.tuple_to_val(&def.arg_set)));
// Then we construct a new Val::Module // Then we construct a new Val::Module
Ok(Rc::new(Val::Module(def))) Ok(Rc::new(Val::Module(def)))
} }
@ -1131,7 +1131,7 @@ impl Builder {
let def_expr = &def.default; let def_expr = &def.default;
let fields = &def.tuple; let fields = &def.tuple;
// First resolve the target expression. // First resolve the target expression.
let v = try!(self.eval_expr(target)); let v = r#try!(self.eval_expr(target));
// Second ensure that the expression resolves to a string. // Second ensure that the expression resolves to a string.
if let &Val::Str(ref name) = v.deref() { if let &Val::Str(ref name) = v.deref() {
// Third find the field with that name in the tuple. // Third find the field with that name in the tuple.
@ -1168,7 +1168,7 @@ impl Builder {
} }
fn eval_list_op(&mut self, def: &ListOpDef) -> Result<Rc<Val>, Box<Error>> { fn eval_list_op(&mut self, def: &ListOpDef) -> Result<Rc<Val>, Box<Error>> {
let maybe_list = try!(self.eval_expr(&def.target)); let maybe_list = r#try!(self.eval_expr(&def.target));
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 => {
@ -1180,11 +1180,11 @@ impl Builder {
} }
}; };
let mac = &def.mac; let mac = &def.mac;
if let &Val::Macro(ref macdef) = try!(self.lookup_selector(&mac.sel)).as_ref() { if let &Val::Macro(ref macdef) = r#try!(self.lookup_selector(&mac.sel)).as_ref() {
let mut out = Vec::new(); let mut out = Vec::new();
for item in l.iter() { for item in l.iter() {
let argvals = vec![item.clone()]; let argvals = vec![item.clone()];
let fields = try!(macdef.eval( let fields = r#try!(macdef.eval(
self.file.clone(), self.file.clone(),
self.assets.clone(), self.assets.clone(),
self.env.clone(), self.env.clone(),

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
use super::assets::MemoryCache; use super::assets::MemoryCache;
use super::{Builder, CallDef, MacroDef, SelectDef, Val}; use super::{Builder, CallDef, MacroDef, SelectDef, Val};
use ast::*; use crate::ast::*;
use std; use std;
use std::cell::RefCell; use std::cell::RefCell;

View File

@ -16,9 +16,9 @@
use std::io::Write; use std::io::Write;
use std::rc::Rc; use std::rc::Rc;
use ast::PositionedItem; use crate::ast::PositionedItem;
use build::Val; use crate::build::Val;
use convert::traits::{Converter, Result}; use crate::convert::traits::{Converter, Result};
/// EnvConverter implements the conversion logic for converting a Val into a /// EnvConverter implements the conversion logic for converting a Val into a
/// set of environment variables. /// set of environment variables.
@ -43,8 +43,8 @@ impl EnvConverter {
eprintln!("Skipping empty variable: {}", name); eprintln!("Skipping empty variable: {}", name);
return Ok(()); return Ok(());
} }
try!(write!(w, "{}=", name.val)); r#try!(write!(w, "{}=", name.val));
try!(self.write(&val, w)); r#try!(self.write(&val, w));
} }
Ok(()) Ok(())
} }
@ -61,22 +61,22 @@ impl EnvConverter {
return Ok(()); return Ok(());
} }
&Val::Boolean(b) => { &Val::Boolean(b) => {
try!(write!(w, "{}\n", if b { "true" } else { "false" })); r#try!(write!(w, "{}\n", if b { "true" } else { "false" }));
} }
&Val::Float(ref f) => { &Val::Float(ref f) => {
try!(write!(w, "{}\n", f)); r#try!(write!(w, "{}\n", f));
} }
&Val::Int(ref i) => { &Val::Int(ref i) => {
try!(write!(w, "{}\n", i)); r#try!(write!(w, "{}\n", i));
} }
&Val::Str(ref s) => { &Val::Str(ref s) => {
try!(write!(w, "'{}'\n", s)); r#try!(write!(w, "'{}'\n", s));
} }
&Val::List(ref items) => { &Val::List(ref items) => {
try!(self.convert_list(items, w)); r#try!(self.convert_list(items, w));
} }
&Val::Tuple(ref flds) => { &Val::Tuple(ref flds) => {
try!(self.convert_tuple(flds, w)); r#try!(self.convert_tuple(flds, w));
} }
&Val::Macro(ref _def) => { &Val::Macro(ref _def) => {
// This is ignored // This is ignored

View File

@ -17,13 +17,13 @@ use std;
use std::io::{Cursor, Write}; use std::io::{Cursor, Write};
use std::rc::Rc; use std::rc::Rc;
use ast::{Position, PositionedItem}; use crate::ast::{Position, PositionedItem};
use build::Val; use crate::build::Val;
use build::Val::Tuple; use crate::build::Val::Tuple;
use convert; use crate::convert;
use convert::traits::{Converter, Result}; use crate::convert::traits::{Converter, Result};
use error::BuildError; use crate::error::BuildError;
use error::ErrorType; use crate::error::ErrorType;
pub struct ExecConverter {} pub struct ExecConverter {}
@ -121,16 +121,16 @@ impl ExecConverter {
// Okay if we have made it this far then we are ready to start creating our script. // Okay if we have made it this far then we are ready to start creating our script.
let mut script = Cursor::new(vec![]); let mut script = Cursor::new(vec![]);
// 1. First the script prefix line. // 1. First the script prefix line.
try!(write!(script, "#!/usr/bin/env bash\n")); r#try!(write!(script, "#!/usr/bin/env bash\n"));
// 2. then some initial setup. for bash hygiene. // 2. then some initial setup. for bash hygiene.
try!(write!(script, "# Turn on unofficial Bash-Strict-Mode\n")); r#try!(write!(script, "# Turn on unofficial Bash-Strict-Mode\n"));
try!(write!(script, "set -euo pipefail\n")); r#try!(write!(script, "set -euo pipefail\n"));
// 3. Then assign our environment variables // 3. Then assign our environment variables
if let Some(env_list) = env { if let Some(env_list) = env {
for &(ref name, ref v) in env_list.iter() { for &(ref name, ref v) in env_list.iter() {
// We only allow string fields in our env tuple. // We only allow string fields in our env tuple.
if let &Val::Str(ref s) = v.as_ref() { if let &Val::Str(ref s) = v.as_ref() {
try!(write!(script, "{}=\"{}\"\n", name.val, s)); r#try!(write!(script, "{}=\"{}\"\n", name.val, s));
continue; continue;
} }
return Err(Box::new(BuildError::new( return Err(Box::new(BuildError::new(
@ -140,19 +140,19 @@ impl ExecConverter {
))); )));
} }
} }
try!(write!(script, "\n")); r#try!(write!(script, "\n"));
// TODO(jwall): Should Flag converter have a strict mode? // TODO(jwall): Should Flag converter have a strict mode?
let flag_converter = convert::flags::FlagConverter::new(); let flag_converter = convert::flags::FlagConverter::new();
// 4. Then construct our command line. (be sure to use exec) // 4. Then construct our command line. (be sure to use exec)
try!(write!(script, "exec {} ", command.unwrap())); r#try!(write!(script, "exec {} ", command.unwrap()));
if let Some(arg_list) = args { if let Some(arg_list) = args {
for v in arg_list.iter() { for v in arg_list.iter() {
// We only allow tuples or strings in our args list. // We only allow tuples or strings in our args list.
match v.as_ref() { match v.as_ref() {
&Val::Str(ref s) => { &Val::Str(ref s) => {
try!(write!(script, "{} ", s)); r#try!(write!(script, "{} ", s));
} }
&Val::Tuple(_) => try!(flag_converter.convert(v.clone(), &mut script)), &Val::Tuple(_) => r#try!(flag_converter.convert(v.clone(), &mut script)),
_ => { _ => {
return Err(Box::new(BuildError::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.",
@ -166,7 +166,7 @@ impl ExecConverter {
// Put cursor to the beginning of our script so when we copy // Put cursor to the beginning of our script so when we copy
// we copy the whole thing. // we copy the whole thing.
script.set_position(0); script.set_position(0);
try!(std::io::copy(&mut script, w)); r#try!(std::io::copy(&mut script, w));
return Ok(()); return Ok(());
} }
@ -195,9 +195,9 @@ impl Converter for ExecConverter {
#[cfg(test)] #[cfg(test)]
mod exec_test { mod exec_test {
use super::*; use super::*;
use build::assets::MemoryCache; use crate::build::assets::MemoryCache;
use build::Builder; use crate::build::Builder;
use convert::traits::Converter; use crate::convert::traits::Converter;
use std; use std;
use std::cell::RefCell; use std::cell::RefCell;

View File

@ -16,8 +16,8 @@
use std::io::Write; use std::io::Write;
use std::rc::Rc; use std::rc::Rc;
use build::Val; use crate::build::Val;
use convert::traits::{Converter, Result}; use crate::convert::traits::{Converter, Result};
/// FlagConverter implements the conversion logic for converting a Val into a set /// FlagConverter implements the conversion logic for converting a Val into a set
/// of command line flags. /// of command line flags.
@ -30,9 +30,9 @@ impl FlagConverter {
fn write_flag_name(&self, pfx: &str, name: &str, w: &mut Write) -> Result { fn write_flag_name(&self, pfx: &str, name: &str, w: &mut Write) -> Result {
if name.chars().count() > 1 || pfx.chars().count() > 0 { if name.chars().count() > 1 || pfx.chars().count() > 0 {
try!(write!(w, "--{}{} ", pfx, name)); r#try!(write!(w, "--{}{} ", pfx, name));
} else { } else {
try!(write!(w, "-{} ", name)); r#try!(write!(w, "-{} ", name));
} }
return Ok(()); return Ok(());
} }
@ -47,8 +47,8 @@ impl FlagConverter {
pfx, name pfx, name
); );
} else { } else {
try!(self.write_flag_name(pfx, name, w)); r#try!(self.write_flag_name(pfx, name, w));
try!(self.write(pfx, vref, w)); r#try!(self.write(pfx, vref, w));
} }
} }
return Ok(()); return Ok(());
@ -61,36 +61,36 @@ impl FlagConverter {
return Ok(()); return Ok(());
} }
&Val::Boolean(b) => { &Val::Boolean(b) => {
try!(write!(w, "{} ", if b { "true" } else { "false" })); r#try!(write!(w, "{} ", if b { "true" } else { "false" }));
} }
&Val::Float(ref f) => { &Val::Float(ref f) => {
try!(write!(w, "{} ", f)); r#try!(write!(w, "{} ", f));
} }
&Val::Int(ref i) => { &Val::Int(ref i) => {
try!(write!(w, "{} ", i)); r#try!(write!(w, "{} ", i));
} }
&Val::Str(ref s) => { &Val::Str(ref s) => {
try!(write!(w, "'{}' ", s)); r#try!(write!(w, "'{}' ", s));
} }
&Val::List(ref _def) => { &Val::List(ref _def) => {
eprintln!("Skipping List..."); eprintln!("Skipping List...");
} }
&Val::Tuple(ref flds) => for &(ref name, ref val) in flds.iter() { &Val::Tuple(ref flds) => for &(ref name, ref val) in flds.iter() {
if let &Val::Empty = val.as_ref() { if let &Val::Empty = val.as_ref() {
try!(self.write_flag_name(pfx, &name.val, w)); r#try!(self.write_flag_name(pfx, &name.val, w));
continue; continue;
} }
match val.as_ref() { match val.as_ref() {
&Val::Tuple(_) => { &Val::Tuple(_) => {
let new_pfx = format!("{}{}.", pfx, name); let new_pfx = format!("{}{}.", pfx, name);
try!(self.write(&new_pfx, val, w)); r#try!(self.write(&new_pfx, val, w));
} }
&Val::List(ref def) => { &Val::List(ref def) => {
try!(self.write_list_flag(pfx, &name.val, def, w)); r#try!(self.write_list_flag(pfx, &name.val, def, w));
} }
_ => { _ => {
try!(self.write_flag_name(pfx, &name.val, w)); r#try!(self.write_flag_name(pfx, &name.val, w));
try!(self.write(pfx, &val, w)); r#try!(self.write(pfx, &val, w));
} }
} }
}, },

View File

@ -14,9 +14,9 @@ use std::rc::Rc;
use serde_json; use serde_json;
use ast; use crate::ast;
use build::Val; use crate::build::Val;
use convert::traits::{Converter, Result}; use crate::convert::traits::{Converter, Result};
/// JsonConverter implements the logic for converting a Val into the json output format. /// JsonConverter implements the logic for converting a Val into the json output format.
pub struct JsonConverter {} pub struct JsonConverter {}
@ -29,7 +29,7 @@ impl JsonConverter {
fn convert_list(&self, items: &Vec<Rc<Val>>) -> std::io::Result<serde_json::Value> { fn convert_list(&self, items: &Vec<Rc<Val>>) -> std::io::Result<serde_json::Value> {
let mut v = Vec::new(); let mut v = Vec::new();
for val in items.iter() { for val in items.iter() {
v.push(try!(self.convert_value(val))); v.push(r#try!(self.convert_value(val)));
} }
Ok(serde_json::Value::Array(v)) Ok(serde_json::Value::Array(v))
} }
@ -41,7 +41,7 @@ impl JsonConverter {
let mut mp = serde_json::Map::new(); let mut mp = serde_json::Map::new();
for &(ref k, ref v) in items.iter() { for &(ref k, ref v) in items.iter() {
mp.entry(k.val.clone()) mp.entry(k.val.clone())
.or_insert(try!(self.convert_value(v))); .or_insert(r#try!(self.convert_value(v)));
} }
Ok(serde_json::Value::Object(mp)) Ok(serde_json::Value::Object(mp))
} }
@ -84,16 +84,16 @@ impl JsonConverter {
eprintln!("Skipping module encoding as null..."); eprintln!("Skipping module encoding as null...");
serde_json::Value::Null serde_json::Value::Null
} }
&Val::Env(ref fs) => try!(self.convert_env(fs)), &Val::Env(ref fs) => r#try!(self.convert_env(fs)),
&Val::List(ref l) => try!(self.convert_list(l)), &Val::List(ref l) => r#try!(self.convert_list(l)),
&Val::Tuple(ref t) => try!(self.convert_tuple(t)), &Val::Tuple(ref t) => r#try!(self.convert_tuple(t)),
}; };
Ok(jsn_val) Ok(jsn_val)
} }
fn write(&self, v: &Val, w: &mut Write) -> Result { fn write(&self, v: &Val, w: &mut Write) -> Result {
let jsn_val = try!(self.convert_value(v)); let jsn_val = r#try!(self.convert_value(v));
try!(serde_json::to_writer_pretty(w, &jsn_val)); r#try!(serde_json::to_writer_pretty(w, &jsn_val));
Ok(()) Ok(())
} }
} }

View File

@ -20,9 +20,9 @@ use std::rc::Rc;
use simple_error::SimpleError; use simple_error::SimpleError;
use toml; use toml;
use ast; use crate::ast;
use build::Val; use crate::build::Val;
use convert::traits::{Converter, Result}; use crate::convert::traits::{Converter, Result};
pub struct TomlConverter {} pub struct TomlConverter {}
@ -36,7 +36,7 @@ impl TomlConverter {
fn convert_list(&self, items: &Vec<Rc<Val>>) -> ConvertResult { fn convert_list(&self, items: &Vec<Rc<Val>>) -> ConvertResult {
let mut v = Vec::new(); let mut v = Vec::new();
for val in items.iter() { for val in items.iter() {
v.push(try!(self.convert_value(val))); v.push(r#try!(self.convert_value(val)));
} }
Ok(toml::Value::Array(v)) Ok(toml::Value::Array(v))
} }
@ -45,7 +45,7 @@ impl TomlConverter {
let mut mp = toml::value::Table::new(); let mut mp = toml::value::Table::new();
for &(ref k, ref v) in items.iter() { for &(ref k, ref v) in items.iter() {
mp.entry(k.val.clone()) mp.entry(k.val.clone())
.or_insert(try!(self.convert_value(v))); .or_insert(r#try!(self.convert_value(v)));
} }
Ok(toml::Value::Table(mp)) Ok(toml::Value::Table(mp))
} }
@ -78,17 +78,17 @@ impl TomlConverter {
let err = SimpleError::new("Modules are not allowed in Toml Conversions!"); let err = SimpleError::new("Modules are not allowed in Toml Conversions!");
return Err(Box::new(err)); return Err(Box::new(err));
} }
&Val::Env(ref fs) => try!(self.convert_env(fs)), &Val::Env(ref fs) => r#try!(self.convert_env(fs)),
&Val::List(ref l) => try!(self.convert_list(l)), &Val::List(ref l) => r#try!(self.convert_list(l)),
&Val::Tuple(ref t) => try!(self.convert_tuple(t)), &Val::Tuple(ref t) => r#try!(self.convert_tuple(t)),
}; };
Ok(toml_val) Ok(toml_val)
} }
fn write(&self, v: &Val, w: &mut Write) -> Result { fn write(&self, v: &Val, w: &mut Write) -> Result {
let toml_val = try!(self.convert_value(v)); let toml_val = r#try!(self.convert_value(v));
let toml_bytes = try!(toml::ser::to_string_pretty(&toml_val)); let toml_bytes = r#try!(toml::ser::to_string_pretty(&toml_val));
try!(write!(w, "{}", toml_bytes)); r#try!(write!(w, "{}", toml_bytes));
Ok(()) Ok(())
} }
} }

View File

@ -18,7 +18,7 @@ use std::io::Write;
use std::rc::Rc; use std::rc::Rc;
use std::result; use std::result;
use build::Val; use crate::build::Val;
pub type Result = result::Result<(), Box<Error>>; pub type Result = result::Result<(), Box<Error>>;

View File

@ -5,8 +5,8 @@ use std::rc::Rc;
use serde_yaml; use serde_yaml;
use super::traits::{Converter, Result}; use super::traits::{Converter, Result};
use ast; use crate::ast;
use build::Val; use crate::build::Val;
pub struct YamlConverter {} pub struct YamlConverter {}
@ -18,7 +18,7 @@ impl YamlConverter {
fn convert_list(&self, items: &Vec<Rc<Val>>) -> std::io::Result<serde_yaml::Value> { fn convert_list(&self, items: &Vec<Rc<Val>>) -> std::io::Result<serde_yaml::Value> {
let mut v = Vec::new(); let mut v = Vec::new();
for val in items.iter() { for val in items.iter() {
v.push(try!(self.convert_value(val))); v.push(r#try!(self.convert_value(val)));
} }
Ok(serde_yaml::Value::Sequence(v)) Ok(serde_yaml::Value::Sequence(v))
} }
@ -42,7 +42,7 @@ impl YamlConverter {
for &(ref k, ref v) in items.iter() { for &(ref k, ref v) in items.iter() {
mapping.insert( mapping.insert(
serde_yaml::Value::String(k.val.clone()), serde_yaml::Value::String(k.val.clone()),
try!(self.convert_value(v)), r#try!(self.convert_value(v)),
); );
} }
Ok(serde_yaml::Value::Mapping(mapping)) Ok(serde_yaml::Value::Mapping(mapping))
@ -69,16 +69,16 @@ impl YamlConverter {
eprintln!("Skipping module encoding as null..."); eprintln!("Skipping module encoding as null...");
serde_yaml::Value::Null serde_yaml::Value::Null
} }
&Val::Env(ref fs) => try!(self.convert_env(fs)), &Val::Env(ref fs) => r#try!(self.convert_env(fs)),
&Val::List(ref l) => try!(self.convert_list(l)), &Val::List(ref l) => r#try!(self.convert_list(l)),
&Val::Tuple(ref t) => try!(self.convert_tuple(t)), &Val::Tuple(ref t) => r#try!(self.convert_tuple(t)),
}; };
Ok(yaml_val) Ok(yaml_val)
} }
fn write(&self, v: &Val, w: &mut Write) -> Result { fn write(&self, v: &Val, w: &mut Write) -> Result {
let jsn_val = try!(self.convert_value(v)); let jsn_val = r#try!(self.convert_value(v));
try!(serde_yaml::to_writer(w, &jsn_val)); r#try!(serde_yaml::to_writer(w, &jsn_val));
Ok(()) Ok(())
} }
} }

View File

@ -19,7 +19,7 @@ use std::fmt::Debug;
use abortable_parser::Positioned; use abortable_parser::Positioned;
use ast::*; use crate::ast::*;
/// ErrorType defines the various types of errors that can result from compiling UCG into an /// ErrorType defines the various types of errors that can result from compiling UCG into an
/// output format. /// output format.
@ -73,7 +73,7 @@ impl BuildError {
} }
fn render(&self, w: &mut fmt::Formatter) -> fmt::Result { fn render(&self, w: &mut fmt::Formatter) -> fmt::Result {
try!(write!( r#try!(write!(
w, w,
"{} at line: {} column: {}\nCaused By:\n\t{} ", "{} at line: {} column: {}\nCaused By:\n\t{} ",
self.err_type, self.pos.line, self.pos.column, self.msg self.err_type, self.pos.line, self.pos.column, self.msg
@ -118,7 +118,7 @@ where
None => break, None => break,
Some(err) => { Some(err) => {
let context = err.get_context(); let context = err.get_context();
try!(write!( r#try!(write!(
w, w,
"{}{}: line: {}, column: {}\n", "{}{}: line: {}, column: {}\n",
tabstop, tabstop,
@ -129,7 +129,7 @@ where
tabstop = "\t"; tabstop = "\t";
curr_err = err.get_cause(); curr_err = err.get_cause();
if curr_err.is_some() { if curr_err.is_some() {
try!(write!(w, "Caused by: \n")); r#try!(write!(w, "Caused by: \n"));
} }
} }
} }

View File

@ -16,8 +16,8 @@
use std::clone::Clone; use std::clone::Clone;
use std::error::Error; use std::error::Error;
use ast::*; use crate::ast::*;
use error; use crate::error;
/// Implements the logic for format strings in UCG format expressions. /// Implements the logic for format strings in UCG format expressions.
pub struct Formatter<V: Into<String> + Clone> { pub struct Formatter<V: Into<String> + Clone> {
@ -77,7 +77,7 @@ impl<V: Into<String> + Clone> Formatter<V> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::Formatter; use super::Formatter;
use ast::Position; use crate::ast::Position;
#[test] #[test]
fn test_format_happy_path() { fn test_format_happy_path() {

View File

@ -4,7 +4,7 @@ use std::iter::Iterator;
use abortable_parser::iter::{SliceIter, StrIter}; use abortable_parser::iter::{SliceIter, StrIter};
use abortable_parser::{InputIter, Offsetable, Peekable, Positioned, Seekable, Span, SpanRange}; use abortable_parser::{InputIter, Offsetable, Peekable, Positioned, Seekable, Span, SpanRange};
use ast::{Position, Token}; use crate::ast::{Position, Token};
#[derive(Debug)] #[derive(Debug)]
pub struct OffsetStrIter<'a> { pub struct OffsetStrIter<'a> {

View File

@ -39,10 +39,10 @@ pub mod parse;
mod format; mod format;
pub use ast::Expression; pub use crate::ast::Expression;
pub use ast::Statement; pub use crate::ast::Statement;
pub use ast::Value; pub use crate::ast::Value;
pub use build::Builder; pub use crate::build::Builder;
pub use build::Val; pub use crate::build::Val;
pub use parse::parse; pub use crate::parse::parse;

View File

@ -65,7 +65,7 @@ fn run_converter(c: &traits::Converter, v: Rc<Val>, f: Option<&str>) -> traits::
let mut path_buf = PathBuf::from(f); let mut path_buf = PathBuf::from(f);
path_buf.set_extension(c.file_ext()); path_buf.set_extension(c.file_ext());
let new_path = path_buf.to_str().unwrap(); let new_path = path_buf.to_str().unwrap();
Box::new(try!(File::create(&new_path))) Box::new(r#try!(File::create(&new_path)))
} }
None => Box::new(io::stdout()), None => Box::new(io::stdout()),
}; };
@ -87,7 +87,7 @@ fn build_file(
if validate { if validate {
builder.enable_validate_mode(); builder.enable_validate_mode();
} }
try!(builder.build()); r#try!(builder.build());
if validate { if validate {
println!("{}", builder.assert_collector.summary); println!("{}", builder.assert_collector.summary);
} }
@ -160,7 +160,7 @@ fn visit_ucg_files(
// TODO(jwall): Report the failing files at the bottom. // TODO(jwall): Report the failing files at the bottom.
let mut summary = String::new(); let mut summary = String::new();
if path.is_dir() { if path.is_dir() {
let mut dir_iter = try!(std::fs::read_dir(path)).peekable(); let mut dir_iter = r#try!(std::fs::read_dir(path)).peekable();
loop { loop {
let entry = match dir_iter.next() { let entry = match dir_iter.next() {
Some(e) => e, Some(e) => e,
@ -168,7 +168,7 @@ fn visit_ucg_files(
break; break;
} }
}; };
let next_item = try!(entry); let next_item = r#try!(entry);
let next_path = next_item.path(); let next_path = next_item.path();
let path_as_string = String::from(next_path.to_string_lossy()); let path_as_string = String::from(next_path.to_string_lossy());
if next_path.is_dir() && recurse { if next_path.is_dir() && recurse {

View File

@ -23,10 +23,10 @@ use abortable_parser::iter::SliceIter;
use abortable_parser::{Error, Peekable, Result}; use abortable_parser::{Error, Peekable, Result};
use self::precedence::op_expression; use self::precedence::op_expression;
use ast::*; use crate::ast::*;
use error::StackPrinter; use crate::error::StackPrinter;
use iter::OffsetStrIter; use crate::iter::OffsetStrIter;
use tokenizer::*; use crate::tokenizer::*;
// TODO(jwall): Rename this to something better. // TODO(jwall): Rename this to something better.
type NomResult<'a, O> = Result<SliceIter<'a, Token>, O>; type NomResult<'a, O> = Result<SliceIter<'a, Token>, O>;
@ -41,7 +41,7 @@ type ParseResult<'a, O> = std::result::Result<O, abortable_parser::Error<SliceIt
macro_rules! trace_nom { macro_rules! trace_nom {
($i:expr, $rule:ident!( $($args:tt)* )) => { ($i:expr, $rule:ident!( $($args:tt)* )) => {
{ {
use parse::ENABLE_TRACE; use crate::parse::ENABLE_TRACE;
if ENABLE_TRACE { if ENABLE_TRACE {
eprintln!("Entering Rule: {:?} {:?}", stringify!($rule), $i); eprintln!("Entering Rule: {:?} {:?}", stringify!($rule), $i);
} }
@ -55,7 +55,7 @@ macro_rules! trace_nom {
($i:expr, $rule:ident) => { ($i:expr, $rule:ident) => {
{ {
use parse::ENABLE_TRACE; use crate::parse::ENABLE_TRACE;
if ENABLE_TRACE { if ENABLE_TRACE {
eprintln!("Entering Rule: {:?} {:?}", stringify!($rule), $i); eprintln!("Entering Rule: {:?} {:?}", stringify!($rule), $i);
} }

View File

@ -18,7 +18,7 @@ use abortable_parser::combinators::eoi;
use abortable_parser::{Error, Result, SliceIter}; use abortable_parser::{Error, Result, SliceIter};
use super::{non_op_expression, NomResult}; use super::{non_op_expression, NomResult};
use ast::*; use crate::ast::*;
/// Defines the intermediate stages of our bottom up parser for precedence parsing. /// Defines the intermediate stages of our bottom up parser for precedence parsing.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
@ -333,7 +333,7 @@ pub fn op_expression<'a>(i: SliceIter<'a, Token>) -> Result<SliceIter<Token>, Ex
} }
Result::Incomplete(i) => Result::Incomplete(i), Result::Incomplete(i) => Result::Incomplete(i),
Result::Complete(rest, oplist) => { Result::Complete(rest, oplist) => {
let mut i_ = SliceIter::new(&oplist); let i_ = SliceIter::new(&oplist);
let parse_result = either!( let parse_result = either!(
i_.clone(), i_.clone(),
trace_nom!(compare_expression), trace_nom!(compare_expression),

View File

@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use super::*; use super::*;
use tokenizer::tokenize; use crate::tokenizer::tokenize;
use abortable_parser::{Result, SliceIter}; use abortable_parser::{Result, SliceIter};
use iter::OffsetStrIter; use crate::iter::OffsetStrIter;
macro_rules! assert_parse { macro_rules! assert_parse {
($parsemac:ident($i:expr), $out:expr) => { ($parsemac:ident($i:expr), $out:expr) => {

View File

@ -19,9 +19,9 @@ use abortable_parser::combinators::*;
use abortable_parser::iter::SliceIter; use abortable_parser::iter::SliceIter;
use abortable_parser::{Error, Offsetable, Result}; use abortable_parser::{Error, Offsetable, Result};
use ast::*; use crate::ast::*;
use error::StackPrinter; use crate::error::StackPrinter;
use iter::OffsetStrIter; use crate::iter::OffsetStrIter;
fn is_symbol_char<'a>(i: OffsetStrIter<'a>) -> Result<OffsetStrIter<'a>, u8> { fn is_symbol_char<'a>(i: OffsetStrIter<'a>) -> Result<OffsetStrIter<'a>, u8> {
let mut _i = i.clone(); let mut _i = i.clone();
@ -559,7 +559,7 @@ macro_rules! match_type {
/// conversion handlers for the matched Token. /// conversion handlers for the matched Token.
macro_rules! match_token { macro_rules! match_token {
($i:expr,PUNCT => $f:expr) => {{ ($i:expr,PUNCT => $f:expr) => {{
use tokenizer::token_clone; use crate::tokenizer::token_clone;
match_token!($i, PUNCT => $f, token_clone) match_token!($i, PUNCT => $f, token_clone)
}}; }};
@ -568,7 +568,7 @@ macro_rules! match_token {
}; };
($i:expr,BAREWORD => $f:expr) => {{ ($i:expr,BAREWORD => $f:expr) => {{
use tokenizer::token_clone; use crate::tokenizer::token_clone;
match_token!($i, BAREWORD => $f, token_clone) match_token!($i, BAREWORD => $f, token_clone)
}}; }};

View File

@ -2,7 +2,7 @@ use super::*;
use abortable_parser::{Result, SliceIter}; use abortable_parser::{Result, SliceIter};
use iter::OffsetStrIter; use crate::iter::OffsetStrIter;
#[test] #[test]
fn test_empty_token() { fn test_empty_token() {