diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 81d2b06..5d6f883 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -330,7 +330,7 @@ pub enum Value { Boolean(Positioned), Int(Positioned), Float(Positioned), - String(Positioned), + Str(Positioned), Symbol(Positioned), // Complex Values Tuple(Positioned), @@ -346,7 +346,7 @@ impl Value { &Value::Boolean(_) => "Boolean".to_string(), &Value::Int(_) => "Integer".to_string(), &Value::Float(_) => "Float".to_string(), - &Value::String(_) => "String".to_string(), + &Value::Str(_) => "String".to_string(), &Value::Symbol(_) => "Symbol".to_string(), &Value::Tuple(_) => "Tuple".to_string(), &Value::List(_) => "List".to_string(), @@ -377,7 +377,7 @@ impl Value { &Value::Boolean(ref b) => format!("{}", b.val), &Value::Int(ref i) => format!("{}", i.val), &Value::Float(ref f) => format!("{}", f.val), - &Value::String(ref s) => format!("{}", s.val), + &Value::Str(ref s) => format!("{}", s.val), &Value::Symbol(ref s) => format!("{}", s.val), &Value::Tuple(ref fs) => format!("{}", Self::fields_to_string(&fs.val)), &Value::List(ref def) => format!("[{}]", Self::elems_to_string(&def.elems)), @@ -392,7 +392,7 @@ impl Value { &Value::Boolean(ref b) => &b.pos, &Value::Int(ref i) => &i.pos, &Value::Float(ref f) => &f.pos, - &Value::String(ref s) => &s.pos, + &Value::Str(ref s) => &s.pos, &Value::Symbol(ref s) => &s.pos, &Value::Tuple(ref fs) => &fs.pos, &Value::List(ref def) => &def.pos, @@ -409,7 +409,7 @@ impl Value { &Value::Boolean(_), &Value::Int(_), &Value::Float(_), - &Value::String(_), + &Value::Str(_), &Value::Symbol(_), &Value::Tuple(_), &Value::List(_), diff --git a/src/build/mod.rs b/src/build/mod.rs index 4c7ec85..9772b43 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -83,7 +83,7 @@ pub enum Val { Boolean(bool), Int(i64), Float(f64), - String(String), + Str(String), List(Vec>), Tuple(Vec<(Positioned, Rc)>), Macro(MacroDef), @@ -97,7 +97,7 @@ impl Val { &Val::Boolean(_) => "Boolean".to_string(), &Val::Int(_) => "Integer".to_string(), &Val::Float(_) => "Float".to_string(), - &Val::String(_) => "String".to_string(), + &Val::Str(_) => "String".to_string(), &Val::List(_) => "List".to_string(), &Val::Tuple(_) => "Tuple".to_string(), &Val::Macro(_) => "Macro".to_string(), @@ -113,7 +113,7 @@ impl Val { &Val::Boolean(_), &Val::Int(_), &Val::Float(_), - &Val::String(_), + &Val::Str(_), &Val::List(_), &Val::Tuple(_), &Val::Macro(_) @@ -133,7 +133,7 @@ impl Val { (&Val::Int(ref i), &Val::Int(ref ii)) => Ok(i == ii), (&Val::Float(ref f), &Val::Float(ref ff)) => Ok(f == ff), (&Val::Boolean(ref b), &Val::Boolean(ref bb)) => Ok(b == bb), - (&Val::String(ref s), &Val::String(ref ss)) => Ok(s == ss), + (&Val::Str(ref s), &Val::Str(ref ss)) => Ok(s == ss), (&Val::List(ref ldef), &Val::List(ref rdef)) => { if ldef.len() != rdef.len() { Ok(false) @@ -211,7 +211,7 @@ impl Val { } pub fn is_string(&self) -> bool { - if let &Val::String(_) = self { + if let &Val::Str(_) = self { return true; } return false; @@ -246,7 +246,7 @@ impl Display for Val { &Val::Empty => write!(f, "EmptyValue"), &Val::Float(ref ff) => write!(f, "Float({})", ff), &Val::Int(ref i) => write!(f, "Int({})", i), - &Val::String(ref s) => write!(f, "String({})", s), + &Val::Str(ref s) => write!(f, "String({})", s), &Val::List(ref def) => { try!(write!(f, "[\n")); for v in def.iter() { @@ -271,7 +271,7 @@ impl From for String { match v { Val::Int(ref i) => format!("{}", i), Val::Float(ref f) => format!("{}", f), - Val::String(ref s) => s.to_string(), + Val::Str(ref s) => s.to_string(), val => format!("<{}>", val), } } @@ -279,7 +279,7 @@ impl From for String { impl From for Val { fn from(s: String) -> Val { - Val::String(s) + Val::Str(s) } } @@ -353,7 +353,7 @@ impl Builder { &Value::Boolean(ref b) => Ok(Rc::new(Val::Boolean(b.val))), &Value::Int(ref i) => Ok(Rc::new(Val::Int(i.val))), &Value::Float(ref f) => Ok(Rc::new(Val::Float(f.val))), - &Value::String(ref s) => Ok(Rc::new(Val::String(s.val.to_string()))), + &Value::Str(ref s) => Ok(Rc::new(Val::Str(s.val.to_string()))), &Value::Symbol(ref s) => self.lookup_sym(&(s.into())).ok_or(Box::new( error::Error::new( format!( @@ -682,9 +682,9 @@ impl Builder { Val::Float(f) => { eval_binary_expr!(&Val::Float(ff), pos, right, Val::Float(f + ff), "Float") } - Val::String(ref s) => match right.as_ref() { - &Val::String(ref ss) => { - return Ok(Rc::new(Val::String([s.to_string(), ss.clone()].concat()))) + Val::Str(ref s) => match right.as_ref() { + &Val::Str(ref ss) => { + return Ok(Rc::new(Val::Str([s.to_string(), ss.clone()].concat()))) } val => { return Err(Box::new(error::Error::new( @@ -1035,7 +1035,7 @@ impl Builder { vals.push(rcv.deref().clone()); } let formatter = format::Formatter::new(tmpl.clone(), vals); - Ok(Rc::new(Val::String(try!(formatter.render(&def.pos))))) + Ok(Rc::new(Val::Str(try!(formatter.render(&def.pos))))) } fn eval_call(&self, def: &CallDef) -> Result, Box> { @@ -1081,7 +1081,7 @@ impl Builder { // First resolve the target expression. let v = try!(self.eval_expr(target)); // Second ensure that the expression resolves to a string. - if let &Val::String(ref name) = v.deref() { + if let &Val::Str(ref name) = v.deref() { // Third find the field with that name in the tuple. for &(ref fname, ref val_expr) in fields.iter() { if &fname.fragment == name { diff --git a/src/build/test.rs b/src/build/test.rs index ce034b0..e955d9b 100644 --- a/src/build/test.rs +++ b/src/build/test.rs @@ -174,25 +174,25 @@ fn test_eval_add_expr() { ( Expression::Binary(BinaryOpDef { kind: BinaryExprType::Add, - left: Box::new(Expression::Simple(Value::String(value_node!( + left: Box::new(Expression::Simple(Value::Str(value_node!( "foo".to_string(), 1, 1 )))), - right: Box::new(Expression::Simple(Value::String(value_node!( + right: Box::new(Expression::Simple(Value::Str(value_node!( "bar".to_string(), 1, 1 )))), pos: Position::new(1, 0), }), - Val::String("foobar".to_string()), + Val::Str("foobar".to_string()), ), ( Expression::Binary(BinaryOpDef { kind: BinaryExprType::Add, left: Box::new(Expression::Simple(Value::List(ListDef { - elems: vec![Expression::Simple(Value::String(value_node!( + elems: vec![Expression::Simple(Value::Str(value_node!( "foo".to_string(), 1, 1 @@ -200,7 +200,7 @@ fn test_eval_add_expr() { pos: Position::new(1, 1), }))), right: Box::new(Expression::Simple(Value::List(ListDef { - elems: vec![Expression::Simple(Value::String(value_node!( + elems: vec![Expression::Simple(Value::Str(value_node!( "bar".to_string(), 1, 1 @@ -210,8 +210,8 @@ fn test_eval_add_expr() { pos: Position::new(1, 0), }), Val::List(vec![ - Rc::new(Val::String("foo".to_string())), - Rc::new(Val::String("bar".to_string())), + Rc::new(Val::Str("foo".to_string())), + Rc::new(Val::Str("bar".to_string())), ]), ), ], @@ -331,8 +331,8 @@ fn test_eval_simple_expr() { Val::Float(2.0), ), ( - Expression::Simple(Value::String(value_node!("foo".to_string(), 1, 1))), - Val::String("foo".to_string()), + Expression::Simple(Value::Str(value_node!("foo".to_string(), 1, 1))), + Val::Str("foo".to_string()), ), ( Expression::Simple(Value::Tuple(value_node!( @@ -448,7 +448,7 @@ fn test_eval_selector_list_expr() { b.out .entry(value_node!("var1".to_string(), 1, 1)) .or_insert(Rc::new(Val::List(vec![ - Rc::new(Val::String("val1".to_string())), + Rc::new(Val::Str("val1".to_string())), Rc::new(Val::Tuple(vec![( value_node!("var2".to_string(), 1, 1), Rc::new(Val::Int(1)), @@ -460,7 +460,7 @@ fn test_eval_selector_list_expr() { Expression::Simple(Value::Selector( make_selector!(make_expr!("var1") => "0" => 1, 1), )), - Val::String("val1".to_string()), + Val::Str("val1".to_string()), )], b, ); @@ -521,13 +521,13 @@ fn test_expr_copy_field_type_error() { selector: make_selector!(make_expr!("tpl1")), fields: vec![( make_tok!("fld1", 1, 1), - Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))), + Expression::Simple(Value::Str(value_node!("2".to_string(), 1, 1))), )], pos: Position::new(1, 0), }), Val::Tuple(vec![( value_node!("fld1".to_string(), 1, 1), - Rc::new(Val::String("2".to_string())), + Rc::new(Val::Str("2".to_string())), )]), )], b, @@ -550,7 +550,7 @@ fn test_expr_copy() { selector: make_selector!(make_expr!("tpl1")), fields: vec![( make_tok!("fld2", 1, 1), - Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))), + Expression::Simple(Value::Str(value_node!("2".to_string(), 1, 1))), )], pos: Position::new(1, 0), }), @@ -563,7 +563,7 @@ fn test_expr_copy() { (value_node!("fld1".to_string(), 1, 0), Rc::new(Val::Int(1))), ( value_node!("fld2".to_string(), 1, 1), - Rc::new(Val::String("2".to_string())), + Rc::new(Val::Str("2".to_string())), ), ], ), @@ -579,7 +579,7 @@ fn test_expr_copy() { ), ( make_tok!("fld2", 1, 1), - Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))), + Expression::Simple(Value::Str(value_node!("2".to_string(), 1, 1))), ), ], pos: Position::new(1, 0), @@ -588,7 +588,7 @@ fn test_expr_copy() { (value_node!("fld1".to_string(), 1, 0), Rc::new(Val::Int(3))), ( value_node!("fld2".to_string(), 1, 0), - Rc::new(Val::String("2".to_string())), + Rc::new(Val::Str("2".to_string())), ), ]), ), @@ -622,7 +622,7 @@ fn test_macro_call() { vec![( Expression::Call(CallDef { macroref: make_selector!(make_expr!("tstmac")), - arglist: vec![Expression::Simple(Value::String(value_node!( + arglist: vec![Expression::Simple(Value::Str(value_node!( "bar".to_string(), 1, 1 @@ -631,7 +631,7 @@ fn test_macro_call() { }), Val::Tuple(vec![( value_node!("foo".to_string(), 1, 1), - Rc::new(Val::String("bar".to_string())), + Rc::new(Val::Str("bar".to_string())), )]), )], b, @@ -644,7 +644,7 @@ fn test_macro_hermetic() { let mut b = Builder::new(std::env::current_dir().unwrap()); b.out .entry(value_node!("arg1".to_string(), 1, 0)) - .or_insert(Rc::new(Val::String("bar".to_string()))); + .or_insert(Rc::new(Val::Str("bar".to_string()))); b.out .entry(value_node!("tstmac".to_string(), 1, 0)) .or_insert(Rc::new(Val::Macro(MacroDef { @@ -659,7 +659,7 @@ fn test_macro_hermetic() { vec![( Expression::Call(CallDef { macroref: make_selector!(make_expr!("tstmac")), - arglist: vec![Expression::Simple(Value::String(value_node!( + arglist: vec![Expression::Simple(Value::Str(value_node!( "bar".to_string(), 1, 1 @@ -668,7 +668,7 @@ fn test_macro_hermetic() { }), Val::Tuple(vec![( value_node!("foo".to_string(), 1, 0), - Rc::new(Val::String("bar".to_string())), + Rc::new(Val::Str("bar".to_string())), )]), )], b, @@ -680,10 +680,10 @@ fn test_select_expr() { let mut b = Builder::new(std::env::current_dir().unwrap()); b.out .entry(value_node!("foo".to_string(), 1, 0)) - .or_insert(Rc::new(Val::String("bar".to_string()))); + .or_insert(Rc::new(Val::Str("bar".to_string()))); b.out .entry(value_node!("baz".to_string(), 1, 0)) - .or_insert(Rc::new(Val::String("boo".to_string()))); + .or_insert(Rc::new(Val::Str("boo".to_string()))); test_expr_to_val( vec![ ( @@ -697,7 +697,7 @@ fn test_select_expr() { tuple: vec![ ( make_tok!("foo", 1, 1), - Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))), + Expression::Simple(Value::Str(value_node!("2".to_string(), 1, 1))), ), ( make_tok!("bar", 1, 1), @@ -723,7 +723,7 @@ fn test_select_expr() { ), ( make_tok!("quux", 1, 1), - Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))), + Expression::Simple(Value::Str(value_node!("2".to_string(), 1, 1))), ), ], pos: Position::new(1, 0), @@ -759,7 +759,7 @@ fn test_select_expr_not_a_string() { ), ( make_tok!("quux", 1, 1), - Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))), + Expression::Simple(Value::Str(value_node!("2".to_string(), 1, 1))), ), ], pos: Position::new(1, 0), @@ -775,13 +775,13 @@ fn test_let_statement() { let mut b = Builder::new(std::env::current_dir().unwrap()); let stmt = Statement::Let(LetDef { name: make_tok!("foo", 1, 1), - value: Expression::Simple(Value::String(value_node!("bar".to_string(), 1, 1))), + value: Expression::Simple(Value::Str(value_node!("bar".to_string(), 1, 1))), }); b.build_stmt(&stmt).unwrap(); test_expr_to_val( vec![( Expression::Simple(Value::Symbol(value_node!("foo".to_string(), 1, 1))), - Val::String("bar".to_string()), + Val::Str("bar".to_string()), )], b, ); diff --git a/src/convert/env.rs b/src/convert/env.rs index 197506a..53ea087 100644 --- a/src/convert/env.rs +++ b/src/convert/env.rs @@ -69,7 +69,7 @@ impl EnvConverter { &Val::Int(ref i) => { try!(write!(w, "{} ", i)); } - &Val::String(ref s) => { + &Val::Str(ref s) => { try!(write!(w, "'{}' ", s)); } &Val::List(ref items) => { diff --git a/src/convert/flags.rs b/src/convert/flags.rs index 4ebf500..d587163 100644 --- a/src/convert/flags.rs +++ b/src/convert/flags.rs @@ -75,7 +75,7 @@ impl FlagConverter { &Val::Int(ref i) => { try!(write!(w, "{} ", i)); } - &Val::String(ref s) => { + &Val::Str(ref s) => { try!(write!(w, "'{}' ", s)); } &Val::List(ref _def) => { diff --git a/src/convert/json.rs b/src/convert/json.rs index 89178d5..b80ed73 100644 --- a/src/convert/json.rs +++ b/src/convert/json.rs @@ -66,7 +66,7 @@ impl JsonConverter { }; serde_json::Value::Number(n) } - &Val::String(ref s) => serde_json::Value::String(s.clone()), + &Val::Str(ref s) => serde_json::Value::String(s.clone()), &Val::Macro(_) => { eprintln!("Skipping macro encoding as null..."); serde_json::Value::Null diff --git a/src/parse/mod.rs b/src/parse/mod.rs index c1dfb94..10880f5 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -42,7 +42,7 @@ named!(symbol, ); fn str_to_value(s: &Token) -> ParseResult { - Ok(Value::String(value_node!( + Ok(Value::Str(value_node!( s.fragment.to_string(), s.pos.clone() ))) diff --git a/src/parse/test.rs b/src/parse/test.rs index 5a6f6ac..97bc678 100644 --- a/src/parse/test.rs +++ b/src/parse/test.rs @@ -319,7 +319,7 @@ fn test_expression_statement_parse() { ); assert_parse!( expression_statement("\"foo\";"), - Statement::Expression(Expression::Simple(Value::String(value_node!( + Statement::Expression(Expression::Simple(Value::Str(value_node!( "foo".to_string(), 1, 1 @@ -327,7 +327,7 @@ fn test_expression_statement_parse() { ); assert_parse!( expression_statement("\"foo\" ;"), - Statement::Expression(Expression::Simple(Value::String(value_node!( + Statement::Expression(Expression::Simple(Value::Str(value_node!( "foo".to_string(), 1, 1 @@ -335,7 +335,7 @@ fn test_expression_statement_parse() { ); assert_parse!( expression_statement(" \"foo\";"), - Statement::Expression(Expression::Simple(Value::String(value_node!( + Statement::Expression(Expression::Simple(Value::Str(value_node!( "foo".to_string(), 1, 2 @@ -351,7 +351,7 @@ fn test_expression_parse() { ); assert_parse!( expression("\"foo\""), - Expression::Simple(Value::String(value_node!("foo".to_string(), 1, 1))) + Expression::Simple(Value::Str(value_node!("foo".to_string(), 1, 1))) ); assert_parse!( expression("1"), @@ -591,7 +591,7 @@ fn test_expression_parse() { 1, 1), arglist: vec![ Expression::Simple(Value::Int(value_node!(1, 1, 10))), - Expression::Simple(Value::String(value_node!("foo".to_string(), 1, 13))), + Expression::Simple(Value::Str(value_node!("foo".to_string(), 1, 13))), ], pos: Position::new(1, 1), }) @@ -663,7 +663,7 @@ fn test_call_parse() { macroref: make_selector!(make_expr!("foo", 1, 1), 1, 1), arglist: vec![ Expression::Simple(Value::Int(value_node!(1, 1, 6))), - Expression::Simple(Value::String(value_node!("foo".to_string(), 1, 9))), + Expression::Simple(Value::Str(value_node!("foo".to_string(), 1, 9))), ], pos: Position::new(1, 1), }) @@ -675,7 +675,7 @@ fn test_call_parse() { macroref: make_selector!(make_expr!("foo") => [ make_tok!("bar", 1, 5) ] => 1, 1), arglist: vec![ Expression::Simple(Value::Int(value_node!(1, 1, 10))), - Expression::Simple(Value::String(value_node!("foo".to_string(), 1, 13))), + Expression::Simple(Value::Str(value_node!("foo".to_string(), 1, 13))), ], pos: Position::new(1, 1), }) @@ -958,7 +958,7 @@ fn test_tuple_parse() { ), ( make_tok!("bar", 1, 12), - Expression::Simple(Value::String(value_node!( + Expression::Simple(Value::Str(value_node!( "1".to_string(), Position::new(1, 18) ))), @@ -978,7 +978,7 @@ fn test_tuple_parse() { ), ( make_tok!("bar", 2, 1), - Expression::Simple(Value::String(value_node!( + Expression::Simple(Value::Str(value_node!( "1".to_string(), Position::new(2, 7) ))), @@ -1137,7 +1137,7 @@ fn test_field_value_parse() { field_value("foo = \"1\""), ( make_tok!("foo", 1, 1), - Expression::Simple(Value::String(value_node!("1".to_string(), 1, 7))) + Expression::Simple(Value::Str(value_node!("1".to_string(), 1, 7))) ) ); assert_parse!(