mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
MAINT: Formatting cleanup.
This commit is contained in:
parent
9b5b7aa793
commit
8009c6a8a5
@ -605,9 +605,11 @@ impl MacroDef {
|
|||||||
stack.push(expr);
|
stack.push(expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Expression::Call(ref def) => for expr in def.arglist.iter() {
|
&Expression::Call(ref def) => {
|
||||||
stack.push(expr);
|
for expr in def.arglist.iter() {
|
||||||
},
|
stack.push(expr);
|
||||||
|
}
|
||||||
|
}
|
||||||
&Expression::Simple(ref val) => {
|
&Expression::Simple(ref val) => {
|
||||||
let mut syms_set = self.validate_value_symbols(&mut stack, val);
|
let mut syms_set = self.validate_value_symbols(&mut stack, val);
|
||||||
bad_symbols.extend(syms_set.drain());
|
bad_symbols.extend(syms_set.drain());
|
||||||
|
@ -302,7 +302,8 @@ impl Builder {
|
|||||||
"Error building file: {}\n{}",
|
"Error building file: {}\n{}",
|
||||||
self.file.to_string_lossy(),
|
self.file.to_string_lossy(),
|
||||||
e.as_ref()
|
e.as_ref()
|
||||||
).as_ref(),
|
)
|
||||||
|
.as_ref(),
|
||||||
);
|
);
|
||||||
Err(Box::new(err))
|
Err(Box::new(err))
|
||||||
}
|
}
|
||||||
@ -578,12 +579,7 @@ impl Builder {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
&Val::List(ref elems) => {
|
&Val::List(ref elems) => {
|
||||||
self.lookup_in_list(
|
self.lookup_in_list(&mut stack, sl, (&next.pos, &next.fragment), elems)?;
|
||||||
&mut stack,
|
|
||||||
sl,
|
|
||||||
(&next.pos, &next.fragment),
|
|
||||||
elems
|
|
||||||
)?;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -737,7 +733,9 @@ 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(left.equal(right.as_ref(), pos.clone())?)))
|
Ok(Rc::new(Val::Boolean(
|
||||||
|
left.equal(right.as_ref(), pos.clone())?,
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_not_deep_equal(
|
fn do_not_deep_equal(
|
||||||
@ -746,7 +744,9 @@ 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(!left.equal(right.as_ref(), pos.clone())?)))
|
Ok(Rc::new(Val::Boolean(
|
||||||
|
!left.equal(right.as_ref(), pos.clone())?,
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_gt(&self, pos: &Position, left: Rc<Val>, right: Rc<Val>) -> Result<Rc<Val>, Box<Error>> {
|
fn do_gt(&self, pos: &Position, left: Rc<Val>, right: Rc<Val>) -> Result<Rc<Val>, Box<Error>> {
|
||||||
@ -981,7 +981,8 @@ impl Builder {
|
|||||||
let first = a.0.clone();
|
let first = a.0.clone();
|
||||||
let t = a.1.clone();
|
let t = a.1.clone();
|
||||||
(first, t.1)
|
(first, t.1)
|
||||||
}).collect(),
|
})
|
||||||
|
.collect(),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1073,7 +1074,7 @@ impl Builder {
|
|||||||
self.file.clone(),
|
self.file.clone(),
|
||||||
self.assets.clone(),
|
self.assets.clone(),
|
||||||
self.env.clone(),
|
self.env.clone(),
|
||||||
argvals
|
argvals,
|
||||||
)?;
|
)?;
|
||||||
return Ok(Rc::new(Val::Tuple(fields)));
|
return Ok(Rc::new(Val::Tuple(fields)));
|
||||||
}
|
}
|
||||||
@ -1184,7 +1185,7 @@ impl Builder {
|
|||||||
self.file.clone(),
|
self.file.clone(),
|
||||||
self.assets.clone(),
|
self.assets.clone(),
|
||||||
self.env.clone(),
|
self.env.clone(),
|
||||||
argvals
|
argvals,
|
||||||
)?;
|
)?;
|
||||||
if let Some(v) = Self::find_in_fieldlist(&def.field, &fields) {
|
if let Some(v) = Self::find_in_fieldlist(&def.field, &fields) {
|
||||||
match def.typ {
|
match def.typ {
|
||||||
|
@ -212,7 +212,8 @@ mod exec_test {
|
|||||||
"let script = {
|
"let script = {
|
||||||
command = \"/bin/echo\",
|
command = \"/bin/echo\",
|
||||||
};",
|
};",
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let result = b.get_out_by_name("script").unwrap();
|
let result = b.get_out_by_name("script").unwrap();
|
||||||
let mut expected = "#!/usr/bin/env bash\n".to_string();
|
let mut expected = "#!/usr/bin/env bash\n".to_string();
|
||||||
expected.push_str("# Turn on unofficial Bash-Strict-Mode\n");
|
expected.push_str("# Turn on unofficial Bash-Strict-Mode\n");
|
||||||
@ -236,7 +237,8 @@ mod exec_test {
|
|||||||
quux = \"baz\",
|
quux = \"baz\",
|
||||||
},
|
},
|
||||||
};",
|
};",
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let result = b.get_out_by_name("script").unwrap();
|
let result = b.get_out_by_name("script").unwrap();
|
||||||
let mut expected = "#!/usr/bin/env bash\n".to_string();
|
let mut expected = "#!/usr/bin/env bash\n".to_string();
|
||||||
expected.push_str("# Turn on unofficial Bash-Strict-Mode\n");
|
expected.push_str("# Turn on unofficial Bash-Strict-Mode\n");
|
||||||
@ -267,7 +269,8 @@ mod exec_test {
|
|||||||
{flag1 = 1},
|
{flag1 = 1},
|
||||||
],
|
],
|
||||||
};",
|
};",
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let result = b.get_out_by_name("script").unwrap();
|
let result = b.get_out_by_name("script").unwrap();
|
||||||
let mut expected = "#!/usr/bin/env bash\n".to_string();
|
let mut expected = "#!/usr/bin/env bash\n".to_string();
|
||||||
expected.push_str("# Turn on unofficial Bash-Strict-Mode\n");
|
expected.push_str("# Turn on unofficial Bash-Strict-Mode\n");
|
||||||
|
@ -75,25 +75,27 @@ impl FlagConverter {
|
|||||||
&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) => {
|
||||||
if let &Val::Empty = val.as_ref() {
|
for &(ref name, ref val) in flds.iter() {
|
||||||
self.write_flag_name(pfx, &name.val, w)?;
|
if let &Val::Empty = val.as_ref() {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
match val.as_ref() {
|
|
||||||
&Val::Tuple(_) => {
|
|
||||||
let new_pfx = format!("{}{}.", pfx, name);
|
|
||||||
self.write(&new_pfx, val, w)?;
|
|
||||||
}
|
|
||||||
&Val::List(ref def) => {
|
|
||||||
self.write_list_flag(pfx, &name.val, def, w)?;
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
self.write_flag_name(pfx, &name.val, w)?;
|
self.write_flag_name(pfx, &name.val, w)?;
|
||||||
self.write(pfx, &val, w)?;
|
continue;
|
||||||
|
}
|
||||||
|
match val.as_ref() {
|
||||||
|
&Val::Tuple(_) => {
|
||||||
|
let new_pfx = format!("{}{}.", pfx, name);
|
||||||
|
self.write(&new_pfx, val, w)?;
|
||||||
|
}
|
||||||
|
&Val::List(ref def) => {
|
||||||
|
self.write_list_flag(pfx, &name.val, def, w)?;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
self.write_flag_name(pfx, &name.val, w)?;
|
||||||
|
self.write(pfx, &val, w)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
&Val::Macro(ref _def) => {
|
&Val::Macro(ref _def) => {
|
||||||
// This is ignored
|
// This is ignored
|
||||||
eprintln!("Skipping macro...");
|
eprintln!("Skipping macro...");
|
||||||
|
@ -40,8 +40,7 @@ impl JsonConverter {
|
|||||||
) -> std::io::Result<serde_json::Value> {
|
) -> std::io::Result<serde_json::Value> {
|
||||||
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(self.convert_value(v)?);
|
||||||
.or_insert(self.convert_value(v)?);
|
|
||||||
}
|
}
|
||||||
Ok(serde_json::Value::Object(mp))
|
Ok(serde_json::Value::Object(mp))
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,7 @@ impl TomlConverter {
|
|||||||
fn convert_tuple(&self, items: &Vec<(ast::PositionedItem<String>, Rc<Val>)>) -> ConvertResult {
|
fn convert_tuple(&self, items: &Vec<(ast::PositionedItem<String>, Rc<Val>)>) -> ConvertResult {
|
||||||
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(self.convert_value(v)?);
|
||||||
.or_insert(self.convert_value(v)?);
|
|
||||||
}
|
}
|
||||||
Ok(toml::Value::Table(mp))
|
Ok(toml::Value::Table(mp))
|
||||||
}
|
}
|
||||||
|
@ -243,35 +243,35 @@ macro_rules! alt_peek {
|
|||||||
// inputs. So handle with care.
|
// inputs. So handle with care.
|
||||||
fn number(input: SliceIter<Token>) -> Result<SliceIter<Token>, Value> {
|
fn number(input: SliceIter<Token>) -> Result<SliceIter<Token>, Value> {
|
||||||
let parsed = do_each!(input,
|
let parsed = do_each!(input,
|
||||||
num => either!(
|
num => either!(
|
||||||
complete!(
|
complete!(
|
||||||
"Not a float",
|
"Not a float",
|
||||||
do_each!( // 1.0
|
do_each!( // 1.0
|
||||||
prefix => match_type!(DIGIT),
|
prefix => match_type!(DIGIT),
|
||||||
has_dot => punct!("."),
|
has_dot => punct!("."),
|
||||||
suffix => match_type!(DIGIT),
|
suffix => match_type!(DIGIT),
|
||||||
(Some(prefix.clone()), Some(has_dot.clone()), Some(suffix.clone()))
|
(Some(prefix.clone()), Some(has_dot.clone()), Some(suffix.clone()))
|
||||||
)),
|
)),
|
||||||
complete!(
|
complete!(
|
||||||
"Not a float",
|
"Not a float",
|
||||||
do_each!( // 1.
|
do_each!( // 1.
|
||||||
prefix => match_type!(DIGIT),
|
prefix => match_type!(DIGIT),
|
||||||
has_dot => punct!("."),
|
has_dot => punct!("."),
|
||||||
(Some(prefix.clone()), Some(has_dot.clone()), None)
|
(Some(prefix.clone()), Some(has_dot.clone()), None)
|
||||||
)),
|
)),
|
||||||
complete!(
|
complete!(
|
||||||
"Not a float",
|
"Not a float",
|
||||||
do_each!( // .1
|
do_each!( // .1
|
||||||
has_dot => punct!("."),
|
has_dot => punct!("."),
|
||||||
suffix => match_type!(DIGIT),
|
suffix => match_type!(DIGIT),
|
||||||
(None, Some(has_dot.clone()), Some(suffix.clone()))
|
(None, Some(has_dot.clone()), Some(suffix.clone()))
|
||||||
)),
|
)),
|
||||||
do_each!( // 1
|
do_each!( // 1
|
||||||
prefix => match_type!(DIGIT),
|
prefix => match_type!(DIGIT),
|
||||||
(Some(prefix.clone()), None, None)
|
(Some(prefix.clone()), None, None)
|
||||||
)),
|
)),
|
||||||
(num)
|
(num)
|
||||||
);
|
);
|
||||||
match parsed {
|
match parsed {
|
||||||
Result::Abort(e) => Result::Abort(e),
|
Result::Abort(e) => Result::Abort(e),
|
||||||
Result::Fail(e) => Result::Fail(e),
|
Result::Fail(e) => Result::Fail(e),
|
||||||
@ -538,7 +538,8 @@ fn tuple_to_macro<'a>(
|
|||||||
.map(|s| PositionedItem {
|
.map(|s| PositionedItem {
|
||||||
pos: s.pos().clone(),
|
pos: s.pos().clone(),
|
||||||
val: s.to_string(),
|
val: s.to_string(),
|
||||||
}).collect();
|
})
|
||||||
|
.collect();
|
||||||
match val {
|
match val {
|
||||||
Value::Tuple(v) => Ok(Expression::Macro(MacroDef {
|
Value::Tuple(v) => Ok(Expression::Macro(MacroDef {
|
||||||
argdefs: arglist,
|
argdefs: arglist,
|
||||||
@ -945,12 +946,12 @@ make_fn!(
|
|||||||
//trace_macros!(true);
|
//trace_macros!(true);
|
||||||
fn statement(i: SliceIter<Token>) -> Result<SliceIter<Token>, Statement> {
|
fn statement(i: SliceIter<Token>) -> Result<SliceIter<Token>, Statement> {
|
||||||
return alt_peek!(i,
|
return alt_peek!(i,
|
||||||
word!("assert") => trace_nom!(assert_statement) |
|
word!("assert") => trace_nom!(assert_statement) |
|
||||||
word!("import") => trace_nom!(import_statement) |
|
word!("import") => trace_nom!(import_statement) |
|
||||||
word!("let") => trace_nom!(let_statement) |
|
word!("let") => trace_nom!(let_statement) |
|
||||||
word!("out") => trace_nom!(out_statement) |
|
word!("out") => trace_nom!(out_statement) |
|
||||||
trace_nom!(expression_statement)
|
trace_nom!(expression_statement)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//trace_macros!(false);
|
//trace_macros!(false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user