mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-25 18:49:50 -04:00
Cleanup: formatting and todos
cargo fmt changed a fixme to a todo
This commit is contained in:
parent
594e14cd0f
commit
389f395383
10
src/ast.rs
10
src/ast.rs
@ -54,8 +54,8 @@ macro_rules! value_node {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type FieldList = Vec<(Token, Expression)>; // str is expected to be a symbol
|
pub type FieldList = Vec<(Token, Expression)>; // Token is expected to be a symbol
|
||||||
pub type SelectorList = Vec<Token>; // str is expected to always be a symbol.
|
pub type SelectorList = Vec<Token>; // Token is expected to always be a symbol.
|
||||||
|
|
||||||
#[derive(Debug,PartialEq,Clone)]
|
#[derive(Debug,PartialEq,Clone)]
|
||||||
pub struct LocatedNode<T> {
|
pub struct LocatedNode<T> {
|
||||||
@ -497,11 +497,7 @@ 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![Positioned::new("foo".to_string(),
|
argdefs: vec![Positioned::new("foo".to_string(), Position {line: 1, column: 0})],
|
||||||
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,
|
||||||
|
57
src/build.rs
57
src/build.rs
@ -205,7 +205,7 @@ impl Val {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_list(&self) -> bool {
|
pub fn is_list(&self) -> bool {
|
||||||
if let &Val::Tuple(_) = self {
|
if let &Val::Tuple(_) = self {
|
||||||
return true;
|
return true;
|
||||||
@ -429,22 +429,22 @@ impl Builder {
|
|||||||
let next = it.next().unwrap();
|
let next = it.next().unwrap();
|
||||||
match vref.as_ref() {
|
match vref.as_ref() {
|
||||||
&Val::Tuple(_) => {
|
&Val::Tuple(_) => {
|
||||||
// This unwrap is safe because we already checked for
|
// This unwrap is safe because we already checked for
|
||||||
// Tuple in the pattern match.
|
// Tuple in the pattern match.
|
||||||
let fs = vref.get_fields().unwrap();
|
let fs = vref.get_fields().unwrap();
|
||||||
if let Some(vv) = Self::find_in_fieldlist(&next.fragment, fs) {
|
if let Some(vv) = Self::find_in_fieldlist(&next.fragment, fs) {
|
||||||
stack.push_back(vv.clone());
|
stack.push_back(vv.clone());
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// TODO(jwall): A better error for this would be nice.
|
// TODO(jwall): A better error for this would be nice.
|
||||||
return Err(Box::new(BuildError::NoSuchSymbol(format!("Unable to \
|
return Err(Box::new(BuildError::NoSuchSymbol(format!("Unable to \
|
||||||
match selector \
|
match selector \
|
||||||
path {:?}",
|
path {:?}",
|
||||||
sl))));
|
sl))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Val::List(ref elems) => {
|
&Val::List(ref elems) => {
|
||||||
// FIXME(jwall): better error reporting here would probably be good.
|
// TODO(jwall): better error reporting here would probably be good.
|
||||||
let idx = try!(next.fragment.parse::<usize>());
|
let idx = try!(next.fragment.parse::<usize>());
|
||||||
if idx < elems.len() {
|
if idx < elems.len() {
|
||||||
stack.push_back(elems[idx].clone());
|
stack.push_back(elems[idx].clone());
|
||||||
@ -943,16 +943,23 @@ mod test {
|
|||||||
]
|
]
|
||||||
))),
|
))),
|
||||||
])));
|
])));
|
||||||
b.out.entry(Positioned::new("var2".to_string(),
|
b.out
|
||||||
Position {line: 1, column: 0}))
|
.entry(Positioned::new("var2".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
.or_insert(Rc::new(Val::Int(2)));
|
.or_insert(Rc::new(Val::Int(2)));
|
||||||
b.out.entry(Positioned::new("var3".to_string(),
|
b.out
|
||||||
Position {line: 1, column: 0}))
|
.entry(Positioned::new("var3".to_string(),
|
||||||
.or_insert(Rc::new(Val::Tuple(
|
Position {
|
||||||
vec![(Positioned::new("lvl1".to_string(),
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
}))
|
||||||
|
.or_insert(Rc::new(Val::Tuple(vec![(Positioned::new("lvl1".to_string(),
|
||||||
Position {line: 1, column: 0}),
|
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![
|
||||||
@ -985,8 +992,13 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_eval_selector_list_expr() {
|
fn test_eval_selector_list_expr() {
|
||||||
let mut b = Builder::new();
|
let mut b = Builder::new();
|
||||||
b.out.entry(Positioned::new("var1".to_string(), Position{line: 1, column: 1})).or_insert(Rc::new(Val::List(
|
b.out
|
||||||
vec![
|
.entry(Positioned::new("var1".to_string(),
|
||||||
|
Position {
|
||||||
|
line: 1,
|
||||||
|
column: 1,
|
||||||
|
}))
|
||||||
|
.or_insert(Rc::new(Val::List(vec![
|
||||||
Rc::new(Val::String("val1".to_string())),
|
Rc::new(Val::String("val1".to_string())),
|
||||||
Rc::new(Val::Tuple(vec![
|
Rc::new(Val::Tuple(vec![
|
||||||
(Positioned::new("var2".to_string(), Position{line: 1, column: 1}),
|
(Positioned::new("var2".to_string(), Position{line: 1, column: 1}),
|
||||||
@ -1001,7 +1013,8 @@ mod test {
|
|||||||
Token::new("0", Position{line: 1, column: 1})
|
Token::new("0", Position{line: 1, column: 1})
|
||||||
], 1, 1))),
|
], 1, 1))),
|
||||||
Val::String("val1".to_string()))
|
Val::String("val1".to_string()))
|
||||||
], b);
|
],
|
||||||
|
b);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -27,14 +27,12 @@ pub struct ConverterRunner {
|
|||||||
impl ConverterRunner {
|
impl ConverterRunner {
|
||||||
pub fn new(typ: &str) -> Result<Self, String> {
|
pub fn new(typ: &str) -> Result<Self, String> {
|
||||||
if typ == "flags" {
|
if typ == "flags" {
|
||||||
return Ok(ConverterRunner {
|
return Ok(ConverterRunner { converter: Box::new(flags::FlagConverter::new()) });
|
||||||
converter: Box::new(flags::FlagConverter::new()),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return Err(format!("Unknown Target output type: {}", typ))
|
return Err(format!("Unknown Target output type: {}", typ));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert(&self, v: Rc<Val>, w: Box<Write>) -> io::Result<()> {
|
pub fn convert(&self, v: Rc<Val>, w: Box<Write>) -> io::Result<()> {
|
||||||
self.converter.convert(v, w)
|
self.converter.convert(v, w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ fn main() {
|
|||||||
let sym = matches.value_of("sym");
|
let sym = matches.value_of("sym");
|
||||||
let target = matches.value_of("target").unwrap();
|
let target = matches.value_of("target").unwrap();
|
||||||
let mut builder = build::Builder::new();
|
let mut builder = build::Builder::new();
|
||||||
match ConverterRunner::new(target) {
|
match ConverterRunner::new(target) {
|
||||||
Ok(converter) => {
|
Ok(converter) => {
|
||||||
let result = builder.build_file(file);
|
let result = builder.build_file(file);
|
||||||
if !result.is_ok() {
|
if !result.is_ok() {
|
||||||
@ -87,7 +87,7 @@ fn main() {
|
|||||||
eprintln!("{}", msg);
|
eprintln!("{}", msg);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(matches) = app.subcommand_matches("validate") {
|
} else if let Some(matches) = app.subcommand_matches("validate") {
|
||||||
let file = matches.value_of("INPUT").unwrap();
|
let file = matches.value_of("INPUT").unwrap();
|
||||||
let mut builder = build::Builder::new();
|
let mut builder = build::Builder::new();
|
||||||
|
19
src/parse.rs
19
src/parse.rs
@ -175,11 +175,11 @@ pub fn selector_or_symbol(input: Span) -> IResult<Span, Value> {
|
|||||||
match sym {
|
match sym {
|
||||||
IResult::Incomplete(i) => {
|
IResult::Incomplete(i) => {
|
||||||
return IResult::Incomplete(i);
|
return IResult::Incomplete(i);
|
||||||
},
|
}
|
||||||
IResult::Error(_) => {
|
IResult::Error(_) => {
|
||||||
// TODO(jwall): Maybe be smarter about the error reporting here?
|
// TODO(jwall): Maybe be smarter about the error reporting here?
|
||||||
return ws!(input, selector_value);
|
return ws!(input, selector_value);
|
||||||
},
|
}
|
||||||
IResult::Done(rest, val) => {
|
IResult::Done(rest, val) => {
|
||||||
return IResult::Done(rest, val);
|
return IResult::Done(rest, val);
|
||||||
}
|
}
|
||||||
@ -442,8 +442,8 @@ named!(call_expression( Span ) -> Expression,
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
fn tuple_to_list<Sp: Into<Position> >(t: (Sp, Vec<Expression>)) -> ParseResult<Expression> {
|
fn tuple_to_list<Sp: Into<Position>>(t: (Sp, Vec<Expression>)) -> ParseResult<Expression> {
|
||||||
return Ok(Expression::List(ListDef{
|
return Ok(Expression::List(ListDef {
|
||||||
elems: t.1,
|
elems: t.1,
|
||||||
pos: t.0.into(),
|
pos: t.0.into(),
|
||||||
}));
|
}));
|
||||||
@ -555,10 +555,10 @@ pub fn parse(input: Span) -> IResult<Span, Vec<Statement>> {
|
|||||||
match ws!(i, statement) {
|
match ws!(i, statement) {
|
||||||
IResult::Error(e) => {
|
IResult::Error(e) => {
|
||||||
return IResult::Error(e);
|
return IResult::Error(e);
|
||||||
},
|
}
|
||||||
IResult::Incomplete(i) => {
|
IResult::Incomplete(i) => {
|
||||||
return IResult::Incomplete(i);
|
return IResult::Incomplete(i);
|
||||||
},
|
}
|
||||||
IResult::Done(rest, stmt) => {
|
IResult::Done(rest, stmt) => {
|
||||||
out.push(stmt);
|
out.push(stmt);
|
||||||
i = rest;
|
i = rest;
|
||||||
@ -571,12 +571,13 @@ pub fn parse(input: Span) -> IResult<Span, Vec<Statement>> {
|
|||||||
return IResult::Done(i, out);
|
return IResult::Done(i, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
//named!(pub parse( Span ) -> Vec<Statement>, many1!());
|
// named!(pub parse( Span ) -> Vec<Statement>, many1!());
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::{Statement, Expression, Value, MacroDef, SelectDef, CallDef};
|
use super::{Statement, Expression, Value, MacroDef, SelectDef, CallDef};
|
||||||
use super::{number, symbol, parse, field_value, selector_value, selector_or_symbol, tuple, grouped_expression, list_expression};
|
use super::{number, symbol, parse, field_value, selector_value, selector_or_symbol, tuple,
|
||||||
|
grouped_expression, list_expression};
|
||||||
use super::{copy_expression, macro_expression, select_expression};
|
use super::{copy_expression, macro_expression, select_expression};
|
||||||
use super::{format_expression, call_expression, expression};
|
use super::{format_expression, call_expression, expression};
|
||||||
use super::{expression_statement, let_statement, import_statement, statement};
|
use super::{expression_statement, let_statement, import_statement, statement};
|
||||||
@ -1306,7 +1307,7 @@ mod test {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(list_expression(LocatedSpan::new("[1, 1]")),
|
assert_eq!(list_expression(LocatedSpan::new("[1, 1]")),
|
||||||
IResult::Done(LocatedSpan{fragment: "", offset: 6, line: 1},
|
IResult::Done(LocatedSpan{fragment: "", offset: 6, line: 1},
|
||||||
Expression::List(
|
Expression::List(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user