mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-24 18:39:50 -04:00
Cleanup and formatting.
* Unused code warnings. * Ran cargo fmt.
This commit is contained in:
parent
1e063fd129
commit
a2f689ce0d
18
src/build.rs
18
src/build.rs
@ -661,7 +661,8 @@ impl Builder {
|
||||
v.insert((count, expr_result));
|
||||
count += 1;
|
||||
}
|
||||
Entry::Occupied(mut v) => { // overriding field here.
|
||||
Entry::Occupied(mut v) => {
|
||||
// overriding field here.
|
||||
// Ensure that the new type matches the old type.
|
||||
let src_val = v.get().clone();
|
||||
if src_val.1.type_equal(&expr_result) {
|
||||
@ -681,12 +682,17 @@ impl Builder {
|
||||
// We want to maintain our order for the fields to make comparing tuples
|
||||
// easier in later code. So we sort by the field order before constructing a new tuple.
|
||||
new_fields.sort_by(|a, b| {
|
||||
let ta = a.1.clone(); let tb = b.1.clone(); ta.0.cmp(&tb.0)
|
||||
let ta = a.1.clone();
|
||||
let tb = b.1.clone();
|
||||
ta.0.cmp(&tb.0)
|
||||
});
|
||||
return Ok(Rc::new(Val::Tuple(new_fields.iter().map(|a| {
|
||||
let first = a.0.clone(); let t = a.1.clone();
|
||||
(first, t.1)
|
||||
}).collect())));
|
||||
return Ok(Rc::new(Val::Tuple(new_fields.iter()
|
||||
.map(|a| {
|
||||
let first = a.0.clone();
|
||||
let t = a.1.clone();
|
||||
(first, t.1)
|
||||
})
|
||||
.collect())));
|
||||
}
|
||||
Err(Box::new(error::Error::new(format!("Expected Tuple got {}", v),
|
||||
error::ErrorType::TypeFail,
|
||||
|
@ -33,7 +33,9 @@ impl JsonConverter {
|
||||
Ok(serde_json::Value::Array(v))
|
||||
}
|
||||
|
||||
fn convert_tuple(&self, items: &Vec<(ast::Positioned<String>, Rc<Val>)>) -> Result<serde_json::Value> {
|
||||
fn convert_tuple(&self,
|
||||
items: &Vec<(ast::Positioned<String>, Rc<Val>)>)
|
||||
-> Result<serde_json::Value> {
|
||||
let mut mp = serde_json::Map::new();
|
||||
for &(ref k, ref v) in items.iter() {
|
||||
mp.entry(k.val.clone()).or_insert(try!(self.convert_value(v)));
|
||||
@ -50,7 +52,7 @@ impl JsonConverter {
|
||||
None => panic!("Float is too large or Not a Number {}", f),
|
||||
};
|
||||
serde_json::Value::Number(n)
|
||||
},
|
||||
}
|
||||
&Val::Int(i) => {
|
||||
let n = match serde_json::Number::from_f64(i as f64) {
|
||||
Some(n) => n,
|
||||
@ -58,14 +60,14 @@ impl JsonConverter {
|
||||
None => panic!("Float is too large or Not a Number {}", i),
|
||||
};
|
||||
serde_json::Value::Number(n)
|
||||
},
|
||||
}
|
||||
&Val::String(ref s) => serde_json::Value::String(s.clone()),
|
||||
&Val::Macro(_) => {
|
||||
// TODO(jwall): We probably want to actually skip this but for now
|
||||
// we'll use null
|
||||
eprintln!("Skipping macro encoding as null...");
|
||||
serde_json::Value::Null
|
||||
},
|
||||
}
|
||||
&Val::List(ref l) => try!(self.convert_list(l)),
|
||||
&Val::Tuple(ref t) => try!(self.convert_tuple(t)),
|
||||
};
|
||||
|
18
src/parse.rs
18
src/parse.rs
@ -677,24 +677,6 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! assert_incomplete {
|
||||
($parsemac:ident( $i:expr )) => {
|
||||
assert_incomplete!($i, $parsemac)
|
||||
};
|
||||
($i:expr, $f:expr) => {
|
||||
{
|
||||
let input = LocatedSpan::new($i);
|
||||
match tokenize(input) {
|
||||
Err(_) => assert!(false),
|
||||
Ok(val) => {
|
||||
let result = $f(TokenIter{source: val.as_slice()});
|
||||
assert!(result.is_incomplete(), format!("Not Incomplete: {:?}", result));
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! assert_error {
|
||||
($parsemac:ident( $i:expr )) => {
|
||||
assert_error!($i, $parsemac)
|
||||
|
@ -40,9 +40,11 @@ fn escapequoted(input: Span) -> nom::IResult<Span, String> {
|
||||
let mut frag = String::new();
|
||||
let mut escape = false;
|
||||
for (i, c) in input.iter_indices() {
|
||||
if c == '\\' && ! escape { // eat this slash and set our escaping sentinel
|
||||
if c == '\\' && !escape {
|
||||
// eat this slash and set our escaping sentinel
|
||||
escape = true;
|
||||
} else if c == '"' && !escape { // Bail if this is an unescaped "
|
||||
} else if c == '"' && !escape {
|
||||
// Bail if this is an unescaped "
|
||||
// we exit here.
|
||||
return nom::IResult::Done(input.slice(i..), frag);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user