mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
No more Optional Position information.
This commit is contained in:
parent
0be96dc851
commit
b8c7d660e5
92
src/ast.rs
92
src/ast.rs
@ -153,7 +153,7 @@ impl Value {
|
|||||||
pub struct CallDef {
|
pub struct CallDef {
|
||||||
pub macroref: SelectorList,
|
pub macroref: SelectorList,
|
||||||
pub arglist: Vec<Expression>,
|
pub arglist: Vec<Expression>,
|
||||||
pub pos: Option<Position>,
|
pub pos: Position,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SelectDef selects a value from a tuple with a default if the value doesn't
|
/// SelectDef selects a value from a tuple with a default if the value doesn't
|
||||||
@ -163,29 +163,19 @@ pub struct SelectDef {
|
|||||||
pub val: Box<Expression>,
|
pub val: Box<Expression>,
|
||||||
pub default: Box<Expression>,
|
pub default: Box<Expression>,
|
||||||
pub tuple: FieldList,
|
pub tuple: FieldList,
|
||||||
pub pos: Option<Position>,
|
pub pos: Position,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jwall): This should have a way of rendering with position information.
|
// TODO(jwall): This should have a way of rendering with position information.
|
||||||
#[derive(Debug,Clone)]
|
#[derive(Debug,Clone)]
|
||||||
pub struct Positioned<T> {
|
pub struct Positioned<T> {
|
||||||
pub pos: Option<Position>,
|
pub pos: Position,
|
||||||
pub val: T,
|
pub val: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Positioned<T> {
|
impl<T> Positioned<T> {
|
||||||
pub fn new(v: T) -> Self {
|
pub fn new(v: T, pos: Position) -> Self {
|
||||||
Positioned {
|
Positioned { pos: pos, val: v }
|
||||||
pos: None,
|
|
||||||
val: v,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_with_pos(v: T, pos: Position) -> Self {
|
|
||||||
Positioned {
|
|
||||||
pos: Some(pos),
|
|
||||||
val: v,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +208,7 @@ impl<T: Hash> Hash for Positioned<T> {
|
|||||||
impl<'a> From<&'a Token> for Positioned<String> {
|
impl<'a> From<&'a Token> for Positioned<String> {
|
||||||
fn from(t: &'a Token) -> Positioned<String> {
|
fn from(t: &'a Token) -> Positioned<String> {
|
||||||
Positioned {
|
Positioned {
|
||||||
pos: Some(t.pos.clone()),
|
pos: t.pos.clone(),
|
||||||
val: t.fragment.to_string(),
|
val: t.fragment.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,7 +217,7 @@ impl<'a> From<&'a Token> for Positioned<String> {
|
|||||||
impl<'a> From<&'a LocatedNode<String>> for Positioned<String> {
|
impl<'a> From<&'a LocatedNode<String>> for Positioned<String> {
|
||||||
fn from(t: &LocatedNode<String>) -> Positioned<String> {
|
fn from(t: &LocatedNode<String>) -> Positioned<String> {
|
||||||
Positioned {
|
Positioned {
|
||||||
pos: Some(t.pos.clone()),
|
pos: t.pos.clone(),
|
||||||
val: t.val.clone(),
|
val: t.val.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,7 +231,7 @@ impl<'a> From<&'a LocatedNode<String>> for Positioned<String> {
|
|||||||
pub struct MacroDef {
|
pub struct MacroDef {
|
||||||
pub argdefs: Vec<Positioned<String>>,
|
pub argdefs: Vec<Positioned<String>>,
|
||||||
pub fields: FieldList,
|
pub fields: FieldList,
|
||||||
pub pos: Option<Position>,
|
pub pos: Position,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MacroDef {
|
impl MacroDef {
|
||||||
@ -354,21 +344,21 @@ pub struct BinaryOpDef {
|
|||||||
pub kind: BinaryExprType,
|
pub kind: BinaryExprType,
|
||||||
pub left: Value,
|
pub left: Value,
|
||||||
pub right: Box<Expression>,
|
pub right: Box<Expression>,
|
||||||
pub pos: Option<Position>,
|
pub pos: Position,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,PartialEq,Clone)]
|
#[derive(Debug,PartialEq,Clone)]
|
||||||
pub struct CopyDef {
|
pub struct CopyDef {
|
||||||
pub selector: SelectorList,
|
pub selector: SelectorList,
|
||||||
pub fields: FieldList,
|
pub fields: FieldList,
|
||||||
pub pos: Option<Position>,
|
pub pos: Position,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,PartialEq,Clone)]
|
#[derive(Debug,PartialEq,Clone)]
|
||||||
pub struct FormatDef {
|
pub struct FormatDef {
|
||||||
pub template: String,
|
pub template: String,
|
||||||
pub args: Vec<Expression>,
|
pub args: Vec<Expression>,
|
||||||
pub pos: Option<Position>,
|
pub pos: Position,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Expression encodes an expression. Expressions compute a value from operands.
|
/// Expression encodes an expression. Expressions compute a value from operands.
|
||||||
@ -417,18 +407,23 @@ mod ast_test {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_macro_validation_happy_path() {
|
pub fn test_macro_validation_happy_path() {
|
||||||
let def = MacroDef {
|
let def = MacroDef {
|
||||||
argdefs: vec![
|
argdefs: vec![Positioned::new("foo".to_string(),
|
||||||
Positioned::new("foo".to_string())
|
Position {
|
||||||
],
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
})],
|
||||||
fields: vec![
|
fields: vec![
|
||||||
(Token::new("f1", Position { line: 1, column: 1}), Expression::Binary(BinaryOpDef{
|
(Token::new("f1", Position { line: 1, column: 1}), Expression::Binary(BinaryOpDef{
|
||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::Symbol(make_value_node("foo".to_string(), 1, 1)),
|
left: Value::Symbol(make_value_node("foo".to_string(), 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
})),
|
})),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
assert!(def.validate_symbols().unwrap() == ());
|
assert!(def.validate_symbols().unwrap() == ());
|
||||||
}
|
}
|
||||||
@ -436,18 +431,23 @@ mod ast_test {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_macro_validation_fail() {
|
pub fn test_macro_validation_fail() {
|
||||||
let def = MacroDef {
|
let def = MacroDef {
|
||||||
argdefs: vec![
|
argdefs: vec![Positioned::new("foo".to_string(),
|
||||||
Positioned::new("foo".to_string())
|
Position {
|
||||||
],
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
})],
|
||||||
fields: vec![
|
fields: vec![
|
||||||
(Token::new("f1", Position{line: 1, column: 1}), Expression::Binary(BinaryOpDef{
|
(Token::new("f1", Position{line: 1, column: 1}), Expression::Binary(BinaryOpDef{
|
||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::Symbol(make_value_node("bar".to_string(), 1, 1)),
|
left: Value::Symbol(make_value_node("bar".to_string(), 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
})),
|
})),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
let mut expected = HashSet::new();
|
let mut expected = HashSet::new();
|
||||||
expected.insert("bar".to_string());
|
expected.insert("bar".to_string());
|
||||||
@ -457,9 +457,11 @@ mod ast_test {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_macro_validation_selector_happy_path() {
|
pub fn test_macro_validation_selector_happy_path() {
|
||||||
let def = MacroDef {
|
let def = MacroDef {
|
||||||
argdefs: vec![
|
argdefs: vec![Positioned::new("foo".to_string(),
|
||||||
Positioned::new("foo".to_string())
|
Position {
|
||||||
],
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
})],
|
||||||
fields: vec![
|
fields: vec![
|
||||||
(Token::new("f1", Position{line: 1, column: 1}), Expression::Binary(BinaryOpDef{
|
(Token::new("f1", Position{line: 1, column: 1}), Expression::Binary(BinaryOpDef{
|
||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
@ -467,10 +469,13 @@ mod ast_test {
|
|||||||
Token::new("foo", Position{line: 1, column: 1}),
|
Token::new("foo", Position{line: 1, column: 1}),
|
||||||
Token::new("quux", Position{line: 1, column: 1})], 1, 1)),
|
Token::new("quux", Position{line: 1, column: 1})], 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
})),
|
})),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
assert!(def.validate_symbols().unwrap() == ());
|
assert!(def.validate_symbols().unwrap() == ());
|
||||||
}
|
}
|
||||||
@ -478,9 +483,11 @@ mod ast_test {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_macro_validation_selector_fail() {
|
pub fn test_macro_validation_selector_fail() {
|
||||||
let def = MacroDef {
|
let def = MacroDef {
|
||||||
argdefs: vec![
|
argdefs: vec![Positioned::new("foo".to_string(),
|
||||||
Positioned::new("foo".to_string()),
|
Position {
|
||||||
],
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
})],
|
||||||
fields: vec![
|
fields: vec![
|
||||||
(Token::new("f1", Position{line: 1, column: 1}), Expression::Binary(BinaryOpDef{
|
(Token::new("f1", Position{line: 1, column: 1}), Expression::Binary(BinaryOpDef{
|
||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
@ -488,10 +495,13 @@ mod ast_test {
|
|||||||
Token::new("bar", Position{line: 1, column: 1}),
|
Token::new("bar", Position{line: 1, column: 1}),
|
||||||
Token::new("quux", Position{line: 1, column: 1})], 1, 1)),
|
Token::new("quux", Position{line: 1, column: 1})], 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
})),
|
})),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
let mut expected = HashSet::new();
|
let mut expected = HashSet::new();
|
||||||
expected.insert("bar".to_string());
|
expected.insert("bar".to_string());
|
||||||
|
174
src/build.rs
174
src/build.rs
@ -696,7 +696,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Div,
|
kind: BinaryExprType::Div,
|
||||||
left: Value::Int(make_value_node(2, 1, 1)),
|
left: Value::Int(make_value_node(2, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Int(1)),
|
Val::Int(1)),
|
||||||
(Expression::Binary(
|
(Expression::Binary(
|
||||||
@ -704,7 +704,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Div,
|
kind: BinaryExprType::Div,
|
||||||
left: Value::Float(make_value_node(2.0, 1, 1)),
|
left: Value::Float(make_value_node(2.0, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Float(make_value_node(2.0, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Float(make_value_node(2.0, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Float(1.0)),
|
Val::Float(1.0)),
|
||||||
],
|
],
|
||||||
@ -721,7 +721,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Div,
|
kind: BinaryExprType::Div,
|
||||||
left: Value::Float(make_value_node(2.0, 1, 1)),
|
left: Value::Float(make_value_node(2.0, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Float(1.0)),
|
Val::Float(1.0)),
|
||||||
],
|
],
|
||||||
@ -737,7 +737,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Mul,
|
kind: BinaryExprType::Mul,
|
||||||
left: Value::Int(make_value_node(2, 1, 1)),
|
left: Value::Int(make_value_node(2, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Int(4)),
|
Val::Int(4)),
|
||||||
(Expression::Binary(
|
(Expression::Binary(
|
||||||
@ -745,7 +745,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Mul,
|
kind: BinaryExprType::Mul,
|
||||||
left: Value::Float(make_value_node(2.0, 1, 1)),
|
left: Value::Float(make_value_node(2.0, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Float(make_value_node(2.0, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Float(make_value_node(2.0, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Float(4.0)),
|
Val::Float(4.0)),
|
||||||
],
|
],
|
||||||
@ -762,7 +762,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Mul,
|
kind: BinaryExprType::Mul,
|
||||||
left: Value::Float(make_value_node(2.0, 1, 1)),
|
left: Value::Float(make_value_node(2.0, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(20, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(20, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Float(1.0)),
|
Val::Float(1.0)),
|
||||||
],
|
],
|
||||||
@ -778,7 +778,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Sub,
|
kind: BinaryExprType::Sub,
|
||||||
left: Value::Int(make_value_node(2, 1, 1)),
|
left: Value::Int(make_value_node(2, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Int(1)),
|
Val::Int(1)),
|
||||||
(Expression::Binary(
|
(Expression::Binary(
|
||||||
@ -786,7 +786,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Sub,
|
kind: BinaryExprType::Sub,
|
||||||
left: Value::Float(make_value_node(2.0, 1, 1)),
|
left: Value::Float(make_value_node(2.0, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Float(make_value_node(1.0, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Float(make_value_node(1.0, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Float(1.0)),
|
Val::Float(1.0)),
|
||||||
],
|
],
|
||||||
@ -803,7 +803,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Sub,
|
kind: BinaryExprType::Sub,
|
||||||
left: Value::Float(make_value_node(2.0, 1, 1)),
|
left: Value::Float(make_value_node(2.0, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Float(1.0)),
|
Val::Float(1.0)),
|
||||||
],
|
],
|
||||||
@ -819,7 +819,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::Int(make_value_node(1, 1, 1)),
|
left: Value::Int(make_value_node(1, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(1, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Int(2)),
|
Val::Int(2)),
|
||||||
(Expression::Binary(
|
(Expression::Binary(
|
||||||
@ -827,7 +827,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::Float(make_value_node(1.0, 1, 1)),
|
left: Value::Float(make_value_node(1.0, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Float(make_value_node(1.0, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Float(make_value_node(1.0, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Float(2.0)),
|
Val::Float(2.0)),
|
||||||
(Expression::Binary(
|
(Expression::Binary(
|
||||||
@ -835,7 +835,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::String(make_value_node("foo".to_string(), 1, 1)),
|
left: Value::String(make_value_node("foo".to_string(), 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::String(make_value_node("bar".to_string(), 1, 1)))),
|
right: Box::new(Expression::Simple(Value::String(make_value_node("bar".to_string(), 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::String("foobar".to_string())),
|
Val::String("foobar".to_string())),
|
||||||
], b);
|
], b);
|
||||||
@ -851,7 +851,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::Float(make_value_node(2.0, 1, 1)),
|
left: Value::Float(make_value_node(2.0, 1, 1)),
|
||||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
right: Box::new(Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Float(1.0)),
|
Val::Float(1.0)),
|
||||||
],
|
],
|
||||||
@ -868,7 +868,7 @@ mod test {
|
|||||||
(Expression::Simple(Value::Tuple(make_value_node(vec![
|
(Expression::Simple(Value::Tuple(make_value_node(vec![
|
||||||
(Token::new("bar", Position{line: 1, column: 1}), Expression::Simple(Value::Int(make_value_node(1, 1, 1))))
|
(Token::new("bar", Position{line: 1, column: 1}), Expression::Simple(Value::Int(make_value_node(1, 1, 1))))
|
||||||
], 1, 1))),
|
], 1, 1))),
|
||||||
Val::Tuple(vec![(Positioned::new_with_pos("bar".to_string(), Position{line: 1, column: 1}),
|
Val::Tuple(vec![(Positioned::new("bar".to_string(), Position{line: 1, column: 1}),
|
||||||
Rc::new(Val::Int(1)))])),
|
Rc::new(Val::Int(1)))])),
|
||||||
],
|
],
|
||||||
Builder::new());
|
Builder::new());
|
||||||
@ -877,7 +877,13 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_eval_simple_lookup_expr() {
|
fn test_eval_simple_lookup_expr() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out.entry(Positioned::new("var1".to_string())).or_insert(Rc::new(Val::Int(1)));
|
b.out
|
||||||
|
.entry(Positioned::new("var1".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
|
.or_insert(Rc::new(Val::Int(1)));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Simple(Value::Symbol(make_value_node("var1".to_string(), 1, 1))), Val::Int(1)),
|
(Expression::Simple(Value::Symbol(make_value_node("var1".to_string(), 1, 1))), Val::Int(1)),
|
||||||
],
|
],
|
||||||
@ -887,7 +893,13 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_eval_simple_lookup_error() {
|
fn test_eval_simple_lookup_error() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out.entry(Positioned::new("var1".to_string())).or_insert(Rc::new(Val::Int(1)));
|
b.out
|
||||||
|
.entry(Positioned::new("var1".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
|
.or_insert(Rc::new(Val::Int(1)));
|
||||||
let expr = Expression::Simple(Value::Symbol(make_value_node("var".to_string(), 1, 1)));
|
let expr = Expression::Simple(Value::Symbol(make_value_node("var".to_string(), 1, 1)));
|
||||||
assert!(b.eval_expr(&expr).is_err());
|
assert!(b.eval_expr(&expr).is_err());
|
||||||
}
|
}
|
||||||
@ -896,24 +908,30 @@ mod test {
|
|||||||
fn test_eval_selector_expr() {
|
fn test_eval_selector_expr() {
|
||||||
// TODO(jwall): Tests for this expression.
|
// TODO(jwall): Tests for this expression.
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out.entry(Positioned::new("var1".to_string())).or_insert(Rc::new(Val::Tuple(vec![
|
b.out.entry(Positioned::new("var1".to_string(), Position{line: 1, column: 0})).or_insert(Rc::new(Val::Tuple(vec![
|
||||||
(Positioned::new("lvl1".to_string()), Rc::new(Val::Tuple(
|
(Positioned::new("lvl1".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Tuple(
|
||||||
vec![
|
vec![
|
||||||
(Positioned::new("lvl2".to_string()), Rc::new(Val::Int(3))),
|
(Positioned::new("lvl2".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(3))),
|
||||||
]
|
]
|
||||||
))),
|
))),
|
||||||
])));
|
])));
|
||||||
b.out.entry(Positioned::new("var2".to_string())).or_insert(Rc::new(Val::Int(2)));
|
|
||||||
b.out
|
b.out
|
||||||
.entry(Positioned::new("var3".to_string()))
|
.entry(Positioned::new("var2".to_string(),
|
||||||
.or_insert(Rc::new(Val::Tuple(vec![(Positioned::new("lvl1".to_string()),
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
|
.or_insert(Rc::new(Val::Int(2)));
|
||||||
|
b.out
|
||||||
|
.entry(Positioned::new("var3".to_string(), Position{line: 1, column: 0}))
|
||||||
|
.or_insert(Rc::new(Val::Tuple(vec![(Positioned::new("lvl1".to_string(), Position{line: 1, column: 0}),
|
||||||
Rc::new(Val::Int(4)))])));
|
Rc::new(Val::Int(4)))])));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Simple(Value::Selector(make_value_node(vec![Token::new("var1", Position{line: 1, column: 1})], 1, 1))), Val::Tuple(
|
(Expression::Simple(Value::Selector(make_value_node(vec![Token::new("var1", Position{line: 1, column: 1})], 1, 1))), Val::Tuple(
|
||||||
vec![
|
vec![
|
||||||
(Positioned::new("lvl1".to_string()), Rc::new(Val::Tuple(
|
(Positioned::new("lvl1".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Tuple(
|
||||||
vec![
|
vec![
|
||||||
(Positioned::new("lvl2".to_string()), Rc::new(Val::Int(3))),
|
(Positioned::new("lvl2".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(3))),
|
||||||
]
|
]
|
||||||
))),
|
))),
|
||||||
]
|
]
|
||||||
@ -922,7 +940,7 @@ mod test {
|
|||||||
Token::new("lvl1", Position{line: 1, column: 1})], 1, 1))),
|
Token::new("lvl1", Position{line: 1, column: 1})], 1, 1))),
|
||||||
Val::Tuple(
|
Val::Tuple(
|
||||||
vec![
|
vec![
|
||||||
(Positioned::new("lvl2".to_string()), Rc::new(Val::Int(3))),
|
(Positioned::new("lvl2".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(3))),
|
||||||
]
|
]
|
||||||
)),
|
)),
|
||||||
(Expression::Simple(Value::Selector(make_value_node(vec![Token::new("var1", Position{line: 1, column: 1}),
|
(Expression::Simple(Value::Selector(make_value_node(vec![Token::new("var1", Position{line: 1, column: 1}),
|
||||||
@ -942,7 +960,7 @@ mod test {
|
|||||||
fn test_expr_copy_no_such_tuple() {
|
fn test_expr_copy_no_such_tuple() {
|
||||||
let b = Builder::new();
|
let b = Builder::new();
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Copy(CopyDef{selector: vec![Token::new("tpl1", Position{line: 1, column: 1})], fields: Vec::new(), pos: None}),
|
(Expression::Copy(CopyDef{selector: vec![Token::new("tpl1", Position{line: 1, column: 1})], fields: Vec::new(), pos: Position{line: 1, column: 0}}),
|
||||||
Val::Tuple(Vec::new())),
|
Val::Tuple(Vec::new())),
|
||||||
], b);
|
], b);
|
||||||
}
|
}
|
||||||
@ -951,9 +969,15 @@ mod test {
|
|||||||
#[should_panic(expected = "Expected Tuple got Integer")]
|
#[should_panic(expected = "Expected Tuple got Integer")]
|
||||||
fn test_expr_copy_not_a_tuple() {
|
fn test_expr_copy_not_a_tuple() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out.entry(Positioned::new("tpl1".to_string())).or_insert(Rc::new(Val::Int(1)));
|
b.out
|
||||||
|
.entry(Positioned::new("tpl1".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
|
.or_insert(Rc::new(Val::Int(1)));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Copy(CopyDef{selector: vec![Token::new("tpl1", Position{line: 1, column: 1})], fields: Vec::new(), pos: None}),
|
(Expression::Copy(CopyDef{selector: vec![Token::new("tpl1", Position{line: 1, column: 1})], fields: Vec::new(), pos: Position{line: 1, column: 0}}),
|
||||||
Val::Tuple(Vec::new())),
|
Val::Tuple(Vec::new())),
|
||||||
], b);
|
], b);
|
||||||
}
|
}
|
||||||
@ -962,8 +986,8 @@ mod test {
|
|||||||
#[should_panic(expected = "Expected type Integer for field fld1 but got String")]
|
#[should_panic(expected = "Expected type Integer for field fld1 but got String")]
|
||||||
fn test_expr_copy_field_type_error() {
|
fn test_expr_copy_field_type_error() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out.entry(Positioned::new("tpl1".to_string())).or_insert(Rc::new(Val::Tuple(vec![
|
b.out.entry(Positioned::new("tpl1".to_string(), Position{line: 1, column: 0})).or_insert(Rc::new(Val::Tuple(vec![
|
||||||
(Positioned::new("fld1".to_string()), Rc::new(Val::Int(1))),
|
(Positioned::new("fld1".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(1))),
|
||||||
])));
|
])));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Copy(
|
(Expression::Copy(
|
||||||
@ -971,10 +995,10 @@ mod test {
|
|||||||
selector: vec![Token::new("tpl1", Position{line: 1, column: 1})],
|
selector: vec![Token::new("tpl1", Position{line: 1, column: 1})],
|
||||||
fields: vec![(Token::new("fld1", Position{line: 1, column: 1}),
|
fields: vec![(Token::new("fld1", Position{line: 1, column: 1}),
|
||||||
Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1))))],
|
Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1))))],
|
||||||
pos: None}),
|
pos: Position{line: 1, column: 0}}),
|
||||||
Val::Tuple(
|
Val::Tuple(
|
||||||
vec![
|
vec![
|
||||||
(Positioned::new_with_pos("fld1".to_string(), Position{line: 1, column: 1}), Rc::new(Val::String("2".to_string()))),
|
(Positioned::new("fld1".to_string(), Position{line: 1, column: 1}), Rc::new(Val::String("2".to_string()))),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
], b);
|
], b);
|
||||||
@ -986,8 +1010,8 @@ mod test {
|
|||||||
fn test_expr_copy() {
|
fn test_expr_copy() {
|
||||||
// TODO(jwall): Tests for this expression.
|
// TODO(jwall): Tests for this expression.
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out.entry(Positioned::new("tpl1".to_string())).or_insert(Rc::new(Val::Tuple(vec![
|
b.out.entry(Positioned::new("tpl1".to_string(), Position{line: 1, column: 0})).or_insert(Rc::new(Val::Tuple(vec![
|
||||||
(Positioned::new("fld1".to_string()), Rc::new(Val::Int(1))),
|
(Positioned::new("fld1".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(1))),
|
||||||
])));
|
])));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Copy(
|
(Expression::Copy(
|
||||||
@ -995,7 +1019,7 @@ mod test {
|
|||||||
selector: vec![Token::new("tpl1", Position{line: 1, column: 1})],
|
selector: vec![Token::new("tpl1", Position{line: 1, column: 1})],
|
||||||
fields: vec![(Token::new("fld2", Position{line: 1, column: 1}),
|
fields: vec![(Token::new("fld2", Position{line: 1, column: 1}),
|
||||||
Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1))))],
|
Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1))))],
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
// Add a new field to the copy
|
// Add a new field to the copy
|
||||||
Val::Tuple(
|
Val::Tuple(
|
||||||
@ -1003,8 +1027,8 @@ mod test {
|
|||||||
// that the compare assertion is correct. The ordering has no
|
// that the compare assertion is correct. The ordering has no
|
||||||
// semantics though so at some point we should probably be less restrictive.
|
// semantics though so at some point we should probably be less restrictive.
|
||||||
vec![
|
vec![
|
||||||
(Positioned::new("fld1".to_string()), Rc::new(Val::Int(1))),
|
(Positioned::new("fld1".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(1))),
|
||||||
(Positioned::new_with_pos("fld2".to_string(), Position{line: 1, column: 1}), Rc::new(Val::String("2".to_string()))),
|
(Positioned::new("fld2".to_string(), Position{line: 1, column: 1}), Rc::new(Val::String("2".to_string()))),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
// Overwrite a field in the copy
|
// Overwrite a field in the copy
|
||||||
@ -1017,19 +1041,19 @@ mod test {
|
|||||||
(Token::new("fld2", Position{line: 1, column: 1}),
|
(Token::new("fld2", Position{line: 1, column: 1}),
|
||||||
Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1)))),
|
Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1)))),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Tuple(
|
Val::Tuple(
|
||||||
vec![
|
vec![
|
||||||
(Positioned::new("fld1".to_string()), Rc::new(Val::Int(3))),
|
(Positioned::new("fld1".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(3))),
|
||||||
(Positioned::new("fld2".to_string()), Rc::new(Val::String("2".to_string()))),
|
(Positioned::new("fld2".to_string(), Position{line: 1, column: 0}), Rc::new(Val::String("2".to_string()))),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
// The source tuple is still unmodified.
|
// The source tuple is still unmodified.
|
||||||
(Expression::Simple(Value::Selector(make_value_node(vec![Token::new("tpl1", Position{line: 1, column: 1})], 1, 1))),
|
(Expression::Simple(Value::Selector(make_value_node(vec![Token::new("tpl1", Position{line: 1, column: 1})], 1, 1))),
|
||||||
Val::Tuple(
|
Val::Tuple(
|
||||||
vec![
|
vec![
|
||||||
(Positioned::new("fld1".to_string()), Rc::new(Val::Int(1))),
|
(Positioned::new("fld1".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(1))),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
], b);
|
], b);
|
||||||
@ -1038,21 +1062,21 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_macro_call() {
|
fn test_macro_call() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out.entry(Positioned::new("tstmac".to_string())).or_insert(Rc::new(Val::Macro(MacroDef{
|
b.out.entry(Positioned::new("tstmac".to_string(), Position{line: 1, column: 0})).or_insert(Rc::new(Val::Macro(MacroDef{
|
||||||
argdefs: vec![Positioned::new("arg1".to_string())],
|
argdefs: vec![Positioned::new("arg1".to_string(), Position{line: 1, column: 0})],
|
||||||
fields: vec![
|
fields: vec![
|
||||||
(Token::new("foo", Position{line: 1, column: 1}), Expression::Simple(Value::Symbol(make_value_node("arg1".to_string(), 1, 1)))),
|
(Token::new("foo", Position{line: 1, column: 1}), Expression::Simple(Value::Symbol(make_value_node("arg1".to_string(), 1, 1)))),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
})));
|
})));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Call(CallDef{
|
(Expression::Call(CallDef{
|
||||||
macroref: vec![Token::new("tstmac", Position{line: 1, column: 1})],
|
macroref: vec![Token::new("tstmac", Position{line: 1, column: 1})],
|
||||||
arglist: vec![Expression::Simple(Value::String(make_value_node("bar".to_string(), 1, 1)))],
|
arglist: vec![Expression::Simple(Value::String(make_value_node("bar".to_string(), 1, 1)))],
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Tuple(vec![
|
Val::Tuple(vec![
|
||||||
(Positioned::new_with_pos("foo".to_string(), Position{line: 1, column: 1}),
|
(Positioned::new("foo".to_string(), Position{line: 1, column: 1}),
|
||||||
Rc::new(Val::String("bar".to_string()))),
|
Rc::new(Val::String("bar".to_string()))),
|
||||||
])),
|
])),
|
||||||
], b);
|
], b);
|
||||||
@ -1063,23 +1087,27 @@ mod test {
|
|||||||
fn test_macro_hermetic() {
|
fn test_macro_hermetic() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out
|
b.out
|
||||||
.entry(Positioned::new("arg1".to_string()))
|
.entry(Positioned::new("arg1".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
.or_insert(Rc::new(Val::String("bar".to_string())));
|
.or_insert(Rc::new(Val::String("bar".to_string())));
|
||||||
b.out.entry(Positioned::new("tstmac".to_string())).or_insert(Rc::new(Val::Macro(MacroDef{
|
b.out.entry(Positioned::new("tstmac".to_string(), Position{line: 1, column: 0})).or_insert(Rc::new(Val::Macro(MacroDef{
|
||||||
argdefs: vec![Positioned::new("arg2".to_string())],
|
argdefs: vec![Positioned::new("arg2".to_string(), Position{line: 1, column: 0})],
|
||||||
fields: vec![
|
fields: vec![
|
||||||
(Token::new("foo", Position{line: 1, column: 1}), Expression::Simple(Value::Symbol(make_value_node("arg1".to_string(), 1, 1)))),
|
(Token::new("foo", Position{line: 1, column: 1}), Expression::Simple(Value::Symbol(make_value_node("arg1".to_string(), 1, 1)))),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
})));
|
})));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Call(CallDef{
|
(Expression::Call(CallDef{
|
||||||
macroref: vec![Token::new("tstmac", Position{line: 1, column: 1})],
|
macroref: vec![Token::new("tstmac", Position{line: 1, column: 1})],
|
||||||
arglist: vec![Expression::Simple(Value::String(make_value_node("bar".to_string(), 1, 1)))],
|
arglist: vec![Expression::Simple(Value::String(make_value_node("bar".to_string(), 1, 1)))],
|
||||||
pos: None,
|
pos: Position{line: 1, column: 1},
|
||||||
}),
|
}),
|
||||||
Val::Tuple(vec![
|
Val::Tuple(vec![
|
||||||
(Positioned::new("foo".to_string()), Rc::new(Val::String("bar".to_string()))),
|
(Positioned::new("foo".to_string(), Position{line: 1, column: 0}), Rc::new(Val::String("bar".to_string()))),
|
||||||
])),
|
])),
|
||||||
], b);
|
], b);
|
||||||
}
|
}
|
||||||
@ -1088,10 +1116,18 @@ mod test {
|
|||||||
fn test_select_expr() {
|
fn test_select_expr() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out
|
b.out
|
||||||
.entry(Positioned::new("foo".to_string()))
|
.entry(Positioned::new("foo".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
.or_insert(Rc::new(Val::String("bar".to_string())));
|
.or_insert(Rc::new(Val::String("bar".to_string())));
|
||||||
b.out
|
b.out
|
||||||
.entry(Positioned::new("baz".to_string()))
|
.entry(Positioned::new("baz".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
.or_insert(Rc::new(Val::String("boo".to_string())));
|
.or_insert(Rc::new(Val::String("boo".to_string())));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Select(SelectDef{
|
(Expression::Select(SelectDef{
|
||||||
@ -1101,7 +1137,7 @@ mod test {
|
|||||||
(Token::new("foo", Position{line: 1, column: 1}), Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1)))),
|
(Token::new("foo", Position{line: 1, column: 1}), Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1)))),
|
||||||
(Token::new("bar", Position{line: 1, column: 1}), Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
(Token::new("bar", Position{line: 1, column: 1}), Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Int(2)),
|
Val::Int(2)),
|
||||||
(Expression::Select(SelectDef{
|
(Expression::Select(SelectDef{
|
||||||
@ -1111,7 +1147,7 @@ mod test {
|
|||||||
(Token::new("bar", Position{line: 1, column: 1}), Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
(Token::new("bar", Position{line: 1, column: 1}), Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
||||||
(Token::new("quux", Position{line: 1, column: 1}), Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1)))),
|
(Token::new("quux", Position{line: 1, column: 1}), Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1)))),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
// If the field doesn't exist then we get the default.
|
// If the field doesn't exist then we get the default.
|
||||||
Val::Int(1)),
|
Val::Int(1)),
|
||||||
@ -1122,7 +1158,13 @@ mod test {
|
|||||||
#[should_panic(expected ="Expected String but got Integer in Select expression")]
|
#[should_panic(expected ="Expected String but got Integer in Select expression")]
|
||||||
fn test_select_expr_not_a_string() {
|
fn test_select_expr_not_a_string() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out.entry(Positioned::new("foo".to_string())).or_insert(Rc::new(Val::Int(4)));
|
b.out
|
||||||
|
.entry(Positioned::new("foo".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
|
.or_insert(Rc::new(Val::Int(4)));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Select(SelectDef{
|
(Expression::Select(SelectDef{
|
||||||
val: Box::new(Expression::Simple(Value::Symbol(make_value_node("foo".to_string(), 1, 1)))),
|
val: Box::new(Expression::Simple(Value::Symbol(make_value_node("foo".to_string(), 1, 1)))),
|
||||||
@ -1131,7 +1173,7 @@ mod test {
|
|||||||
(Token::new("bar", Position{line: 1, column: 1}), Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
(Token::new("bar", Position{line: 1, column: 1}), Expression::Simple(Value::Int(make_value_node(2, 1, 1)))),
|
||||||
(Token::new("quux", Position{line: 1, column: 1}), Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1)))),
|
(Token::new("quux", Position{line: 1, column: 1}), Expression::Simple(Value::String(make_value_node("2".to_string(), 1, 1)))),
|
||||||
],
|
],
|
||||||
pos: None,
|
pos: Position{line: 1, column: 0},
|
||||||
}),
|
}),
|
||||||
Val::Int(2)),
|
Val::Int(2)),
|
||||||
], b);
|
], b);
|
||||||
@ -1160,23 +1202,27 @@ mod test {
|
|||||||
fn test_build_file_string() {
|
fn test_build_file_string() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.build_file_string("foo.ucg", "let foo = 1;".to_string()).unwrap();
|
b.build_file_string("foo.ucg", "let foo = 1;".to_string()).unwrap();
|
||||||
let key = Positioned::new("foo".to_string());
|
let key = Positioned::new("foo".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
});
|
||||||
assert!(b.out.contains_key(&key));
|
assert!(b.out.contains_key(&key));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_asset_symbol_lookups() {
|
fn test_asset_symbol_lookups() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.assets.entry(Positioned::new("foo".to_string())).or_insert(Rc::new(Val::Tuple(vec![
|
b.assets.entry(Positioned::new("foo".to_string(), Position{line: 1, column: 0})).or_insert(Rc::new(Val::Tuple(vec![
|
||||||
(Positioned::new("bar".to_string()), Rc::new(Val::Tuple(vec![
|
(Positioned::new("bar".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Tuple(vec![
|
||||||
(Positioned::new("quux".to_string()), Rc::new(Val::Int(1))),
|
(Positioned::new("quux".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(1))),
|
||||||
]))),
|
]))),
|
||||||
])));
|
])));
|
||||||
test_expr_to_val(vec![
|
test_expr_to_val(vec![
|
||||||
(Expression::Simple(Value::Symbol(make_value_node("foo".to_string(), 1, 1))),
|
(Expression::Simple(Value::Symbol(make_value_node("foo".to_string(), 1, 1))),
|
||||||
Val::Tuple(vec![
|
Val::Tuple(vec![
|
||||||
(Positioned::new("bar".to_string()), Rc::new(Val::Tuple(vec![
|
(Positioned::new("bar".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Tuple(vec![
|
||||||
(Positioned::new("quux".to_string()), Rc::new(Val::Int(1))),
|
(Positioned::new("quux".to_string(), Position{line: 1, column: 0}), Rc::new(Val::Int(1))),
|
||||||
]))),
|
]))),
|
||||||
])),
|
])),
|
||||||
],
|
],
|
||||||
|
77
src/parse.rs
77
src/parse.rs
@ -182,10 +182,10 @@ fn tuple_to_binary_expression(tpl: (Span, BinaryExprType, Value, Expression))
|
|||||||
kind: tpl.1,
|
kind: tpl.1,
|
||||||
left: tpl.2,
|
left: tpl.2,
|
||||||
right: Box::new(tpl.3),
|
right: Box::new(tpl.3),
|
||||||
pos: Some(Position {
|
pos: Position {
|
||||||
line: tpl.0.line as usize,
|
line: tpl.0.line as usize,
|
||||||
column: tpl.0.offset as usize,
|
column: tpl.0.offset as usize,
|
||||||
}),
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,10 +253,10 @@ fn tuple_to_copy(t: (Span, SelectorList, FieldList)) -> ParseResult<Expression>
|
|||||||
Ok(Expression::Copy(CopyDef {
|
Ok(Expression::Copy(CopyDef {
|
||||||
selector: t.1,
|
selector: t.1,
|
||||||
fields: t.2,
|
fields: t.2,
|
||||||
pos: Some(Position {
|
pos: Position {
|
||||||
line: t.0.line as usize,
|
line: t.0.line as usize,
|
||||||
column: t.0.offset as usize,
|
column: t.0.offset as usize,
|
||||||
}),
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,16 +282,16 @@ fn tuple_to_macro(mut t: (Span, Vec<Value>, Value)) -> ParseResult<Expression> {
|
|||||||
.drain(0..)
|
.drain(0..)
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
Positioned {
|
Positioned {
|
||||||
pos: Some(s.pos().clone()),
|
pos: s.pos().clone(),
|
||||||
val: s.to_string(),
|
val: s.to_string(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
fields: v.val,
|
fields: v.val,
|
||||||
pos: Some(Position {
|
pos: Position {
|
||||||
line: t.0.line as usize,
|
line: t.0.line as usize,
|
||||||
column: t.0.offset as usize,
|
column: t.0.offset as usize,
|
||||||
}),
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
// TODO(jwall): Show a better version of the unexpected parsed value.
|
// TODO(jwall): Show a better version of the unexpected parsed value.
|
||||||
@ -326,10 +326,10 @@ fn tuple_to_select(t: (Span, Expression, Expression, Value)) -> ParseResult<Expr
|
|||||||
val: Box::new(t.1),
|
val: Box::new(t.1),
|
||||||
default: Box::new(t.2),
|
default: Box::new(t.2),
|
||||||
tuple: v.val,
|
tuple: v.val,
|
||||||
pos: Some(Position {
|
pos: Position {
|
||||||
line: t.0.line as usize,
|
line: t.0.line as usize,
|
||||||
column: t.0.offset as usize,
|
column: t.0.offset as usize,
|
||||||
}),
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
// TODO(jwall): Show a better version of the unexpected parsed value.
|
// TODO(jwall): Show a better version of the unexpected parsed value.
|
||||||
@ -357,7 +357,7 @@ fn tuple_to_format(t: (Token, Vec<Expression>)) -> ParseResult<Expression> {
|
|||||||
Ok(Expression::Format(FormatDef {
|
Ok(Expression::Format(FormatDef {
|
||||||
template: t.0.fragment.to_string(),
|
template: t.0.fragment.to_string(),
|
||||||
args: t.1,
|
args: t.1,
|
||||||
pos: Some(t.0.pos),
|
pos: t.0.pos,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,10 +380,10 @@ fn tuple_to_call(t: (Span, Value, Vec<Expression>)) -> ParseResult<Expression> {
|
|||||||
Ok(Expression::Call(CallDef {
|
Ok(Expression::Call(CallDef {
|
||||||
macroref: sl.val,
|
macroref: sl.val,
|
||||||
arglist: t.2,
|
arglist: t.2,
|
||||||
pos: Some(Position {
|
pos: Position {
|
||||||
line: t.0.line as usize,
|
line: t.0.line as usize,
|
||||||
column: t.0.offset as usize,
|
column: t.0.offset as usize,
|
||||||
}),
|
},
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
Err(Box::new(ParseError::UnexpectedToken("Selector".to_string(), format!("{:?}", t.0))))
|
Err(Box::new(ParseError::UnexpectedToken("Selector".to_string(), format!("{:?}", t.0))))
|
||||||
@ -767,7 +767,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 5})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 5})))),
|
||||||
pos: Some(Position { line: 1, column: 0 }),
|
pos: Position { line: 1, column: 0 },
|
||||||
})));
|
})));
|
||||||
assert_eq!(expression(LocatedSpan::new("1 - 1")),
|
assert_eq!(expression(LocatedSpan::new("1 - 1")),
|
||||||
IResult::Done(LocatedSpan {
|
IResult::Done(LocatedSpan {
|
||||||
@ -779,7 +779,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Sub,
|
kind: BinaryExprType::Sub,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 5})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 5})))),
|
||||||
pos: Some(Position { line: 1, column: 0 }),
|
pos: Position { line: 1, column: 0 },
|
||||||
})));
|
})));
|
||||||
assert_eq!(expression(LocatedSpan::new("1 * 1")),
|
assert_eq!(expression(LocatedSpan::new("1 * 1")),
|
||||||
IResult::Done(LocatedSpan {
|
IResult::Done(LocatedSpan {
|
||||||
@ -791,7 +791,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Mul,
|
kind: BinaryExprType::Mul,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 5})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 5})))),
|
||||||
pos: Some(Position { line: 1, column: 0 }),
|
pos: Position { line: 1, column: 0 },
|
||||||
})));
|
})));
|
||||||
assert_eq!(expression(LocatedSpan::new("1 / 1")),
|
assert_eq!(expression(LocatedSpan::new("1 / 1")),
|
||||||
IResult::Done(LocatedSpan {
|
IResult::Done(LocatedSpan {
|
||||||
@ -803,7 +803,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Div,
|
kind: BinaryExprType::Div,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 5})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 5})))),
|
||||||
pos: Some(Position { line: 1, column: 0 }),
|
pos: Position { line: 1, column: 0 },
|
||||||
})));
|
})));
|
||||||
|
|
||||||
assert_eq!(expression(LocatedSpan::new("1+1")),
|
assert_eq!(expression(LocatedSpan::new("1+1")),
|
||||||
@ -816,7 +816,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 3})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 3})))),
|
||||||
pos: Some(Position { line: 1, column: 0 }),
|
pos: Position { line: 1, column: 0 },
|
||||||
})));
|
})));
|
||||||
assert_eq!(expression(LocatedSpan::new("1-1")),
|
assert_eq!(expression(LocatedSpan::new("1-1")),
|
||||||
IResult::Done(LocatedSpan {
|
IResult::Done(LocatedSpan {
|
||||||
@ -828,7 +828,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Sub,
|
kind: BinaryExprType::Sub,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 3})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 3})))),
|
||||||
pos: Some(Position { line: 1, column: 0 }),
|
pos: Position { line: 1, column: 0 },
|
||||||
})));
|
})));
|
||||||
assert_eq!(expression(LocatedSpan::new("1*1")),
|
assert_eq!(expression(LocatedSpan::new("1*1")),
|
||||||
IResult::Done(LocatedSpan {
|
IResult::Done(LocatedSpan {
|
||||||
@ -840,7 +840,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Mul,
|
kind: BinaryExprType::Mul,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 3})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 3})))),
|
||||||
pos: Some(Position { line: 1, column: 0 }),
|
pos: Position { line: 1, column: 0 },
|
||||||
})));
|
})));
|
||||||
assert_eq!(expression(LocatedSpan::new("1/1")),
|
assert_eq!(expression(LocatedSpan::new("1/1")),
|
||||||
IResult::Done(LocatedSpan {
|
IResult::Done(LocatedSpan {
|
||||||
@ -852,7 +852,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Div,
|
kind: BinaryExprType::Div,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 1})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 3})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 3})))),
|
||||||
pos: Some(Position { line: 1, column: 0 }),
|
pos: Position { line: 1, column: 0 },
|
||||||
})));
|
})));
|
||||||
let macro_expr = "macro (arg1, arg2) => { foo = arg1 }";
|
let macro_expr = "macro (arg1, arg2) => { foo = arg1 }";
|
||||||
assert_eq!(expression(LocatedSpan::new(macro_expr)),
|
assert_eq!(expression(LocatedSpan::new(macro_expr)),
|
||||||
@ -863,15 +863,14 @@ mod test {
|
|||||||
},
|
},
|
||||||
Expression::Macro(MacroDef{
|
Expression::Macro(MacroDef{
|
||||||
argdefs: vec![
|
argdefs: vec![
|
||||||
Positioned::new_with_pos("arg1".to_string(), Position{line: 1, column: 8}),
|
Positioned::new("arg1".to_string(), Position{line: 1, column: 8}),
|
||||||
Positioned::new_with_pos("arg2".to_string(), Position{line: 1, column: 14}),
|
Positioned::new("arg2".to_string(), Position{line: 1, column: 14}),
|
||||||
],
|
],
|
||||||
fields: vec![
|
fields: vec![
|
||||||
(Token::new("foo", Position{line: 1, column: 25}),
|
(Token::new("foo", Position{line: 1, column: 25}),
|
||||||
Expression::Simple(Value::Symbol(value_node!("arg1".to_string(), Position{line: 1, column: 31})))),
|
Expression::Simple(Value::Symbol(value_node!("arg1".to_string(), Position{line: 1, column: 31})))),
|
||||||
],
|
],
|
||||||
// FIXME(jwall): I think this is incorrect.
|
pos: Position{line: 1, column: 0},
|
||||||
pos: Some(Position{line: 1, column: 0}),
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -889,7 +888,7 @@ mod test {
|
|||||||
(Token::new("foo", Position{line: 1, column: 18}),
|
(Token::new("foo", Position{line: 1, column: 18}),
|
||||||
Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 24}))))
|
Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 24}))))
|
||||||
],
|
],
|
||||||
pos: Some(Position{line: 1, column: 0}),
|
pos: Position{line: 1, column: 0},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -907,7 +906,7 @@ mod test {
|
|||||||
Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 10}))),
|
Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 10}))),
|
||||||
Expression::Simple(Value::String(value_node!("foo".to_string(), Position{line: 1, column: 13}))),
|
Expression::Simple(Value::String(value_node!("foo".to_string(), Position{line: 1, column: 13}))),
|
||||||
],
|
],
|
||||||
pos: Some(Position{line: 1, column: 0}),
|
pos: Position{line: 1, column: 0},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -924,7 +923,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 2})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 2})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 6})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 6})))),
|
||||||
pos: Some(Position { line: 1, column: 1 }),
|
pos: Position { line: 1, column: 1 },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -952,7 +951,7 @@ mod test {
|
|||||||
template: "foo @ @".to_string(),
|
template: "foo @ @".to_string(),
|
||||||
args: vec![Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 14}))),
|
args: vec![Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 14}))),
|
||||||
Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 17})))],
|
Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 17})))],
|
||||||
pos: Some(Position{line: 1, column: 1}),
|
pos: Position{line: 1, column: 1},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -970,7 +969,7 @@ mod test {
|
|||||||
template: "foo @ @".to_string(),
|
template: "foo @ @".to_string(),
|
||||||
args: vec![Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 12}))),
|
args: vec![Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 12}))),
|
||||||
Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 15})))],
|
Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 15})))],
|
||||||
pos: Some(Position { line: 1, column: 1 }),
|
pos: Position { line: 1, column: 1 },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -999,7 +998,7 @@ mod test {
|
|||||||
Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 6}))),
|
Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 6}))),
|
||||||
Expression::Simple(Value::String(value_node!("foo".to_string(), Position{line: 1, column: 9}))),
|
Expression::Simple(Value::String(value_node!("foo".to_string(), Position{line: 1, column: 9}))),
|
||||||
],
|
],
|
||||||
pos: Some(Position{line: 1, column: 0}),
|
pos: Position{line: 1, column: 0},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1019,7 +1018,7 @@ mod test {
|
|||||||
Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 10}))),
|
Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 10}))),
|
||||||
Expression::Simple(Value::String(value_node!("foo".to_string(), Position{line: 1, column: 13}))),
|
Expression::Simple(Value::String(value_node!("foo".to_string(), Position{line: 1, column: 13}))),
|
||||||
],
|
],
|
||||||
pos: Some(Position{line: 1, column: 0}),
|
pos: Position{line: 1, column: 0},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1045,7 +1044,7 @@ mod test {
|
|||||||
tuple: vec![
|
tuple: vec![
|
||||||
(Token::new("foo", Position{line: 1, column: 18}), Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 24}))))
|
(Token::new("foo", Position{line: 1, column: 18}), Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 24}))))
|
||||||
],
|
],
|
||||||
pos: Some(Position{line: 1, column: 0}),
|
pos: Position{line: 1, column: 0},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1074,12 +1073,12 @@ mod test {
|
|||||||
line: 1
|
line: 1
|
||||||
},
|
},
|
||||||
Expression::Macro(MacroDef{
|
Expression::Macro(MacroDef{
|
||||||
argdefs: vec![Positioned::new_with_pos("arg1".to_string(), Position{line: 1, column: 8}),
|
argdefs: vec![Positioned::new("arg1".to_string(), Position{line: 1, column: 8}),
|
||||||
Positioned::new_with_pos("arg2".to_string(), Position{line: 1, column: 14})],
|
Positioned::new("arg2".to_string(), Position{line: 1, column: 14})],
|
||||||
fields: vec![(Token::new("foo", Position{line: 1, column: 24}), Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 28})))),
|
fields: vec![(Token::new("foo", Position{line: 1, column: 24}), Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 28})))),
|
||||||
(Token::new("bar", Position{line: 1, column: 30}), Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 34}))))
|
(Token::new("bar", Position{line: 1, column: 30}), Expression::Simple(Value::Int(value_node!(2, Position{line: 1, column: 34}))))
|
||||||
],
|
],
|
||||||
pos: Some(Position{line: 1, column: 0}),
|
pos: Position{line: 1, column: 0},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1102,7 +1101,7 @@ mod test {
|
|||||||
Expression::Copy(CopyDef{
|
Expression::Copy(CopyDef{
|
||||||
selector: vec![Token::new("foo", Position{line: 1, column: 1})],
|
selector: vec![Token::new("foo", Position{line: 1, column: 1})],
|
||||||
fields: Vec::new(),
|
fields: Vec::new(),
|
||||||
pos: Some(Position{line: 1, column: 0}),
|
pos: Position{line: 1, column: 0},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1119,7 +1118,7 @@ mod test {
|
|||||||
selector: vec![Token::new("foo", Position{line: 1, column: 1})],
|
selector: vec![Token::new("foo", Position{line: 1, column: 1})],
|
||||||
fields: vec![(Token::new("bar", Position{line: 1, column: 5}),
|
fields: vec![(Token::new("bar", Position{line: 1, column: 5}),
|
||||||
Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 9}))))],
|
Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 9}))))],
|
||||||
pos: Some(Position{line: 1, column: 0}),
|
pos: Position{line: 1, column: 0},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1146,7 +1145,7 @@ mod test {
|
|||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 2})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 2})),
|
||||||
right: Box::new(Expression::Simple(
|
right: Box::new(Expression::Simple(
|
||||||
Value::Int(value_node!(1, Position{line: 1, column: 6})))),
|
Value::Int(value_node!(1, Position{line: 1, column: 6})))),
|
||||||
pos: Some(Position { line: 1, column: 1 }),
|
pos: Position { line: 1, column: 1 },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -1311,7 +1310,7 @@ mod test {
|
|||||||
kind: BinaryExprType::Add,
|
kind: BinaryExprType::Add,
|
||||||
left: Value::Int(value_node!(1, Position{line: 1, column: 35})),
|
left: Value::Int(value_node!(1, Position{line: 1, column: 35})),
|
||||||
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 37})))),
|
right: Box::new(Expression::Simple(Value::Int(value_node!(1, Position{line: 1, column: 37})))),
|
||||||
pos: Some(Position { line: 1, column: 34 }),
|
pos: Position { line: 1, column: 34 },
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user