Formatting: cargo fmt.

This commit is contained in:
Jeremy Wall 2018-05-14 21:34:38 -05:00
parent f4b5cf1b0c
commit 00c1e1751a
11 changed files with 138 additions and 137 deletions

View File

@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std;
use std::collections::HashSet;
use std::borrow::Borrow;
use std::convert::Into;
use std::cmp::Ordering;
use std::cmp::PartialOrd;
use std::cmp::Eq;
use std::cmp::Ordering;
use std::cmp::PartialEq;
use std::hash::Hasher;
use std::cmp::PartialOrd;
use std::collections::HashSet;
use std::convert::Into;
use std::hash::Hash;
use std::hash::Hasher;
macro_rules! enum_type_equality {
( $slf:ident, $r:expr, $( $l:pat ),* ) => {
@ -106,10 +106,10 @@ impl Borrow<str> for Token {
/// Helper macro for making a Positioned Value.
macro_rules! value_node {
($v: expr, $p: expr) => {
($v:expr, $p:expr) => {
Positioned::new_with_pos($v, $p)
};
($v: expr, $l: expr, $c: expr) => {
($v:expr, $l:expr, $c:expr) => {
Positioned::new($v, $l, $c)
};
}
@ -117,31 +117,31 @@ macro_rules! value_node {
/// Helper macro for making a Token.
#[allow(unused_macros)]
macro_rules! make_tok {
(EOF => $l: expr, $c: expr) => {
(EOF => $l:expr, $c:expr) => {
Token::new("", TokenType::END, $l, $c)
};
(WS => $l: expr, $c: expr) => {
(WS => $l:expr, $c:expr) => {
Token::new("", TokenType::WS, $l, $c)
};
(CMT => $e: expr, $l: expr, $c: expr) => {
(CMT => $e:expr, $l:expr, $c:expr) => {
Token::new($e, TokenType::COMMENT, $l, $c)
};
(QUOT => $e: expr, $l: expr, $c: expr) => {
(QUOT => $e:expr, $l:expr, $c:expr) => {
Token::new($e, TokenType::QUOTED, $l, $c)
};
(PUNCT => $e: expr, $l: expr, $c: expr) => {
(PUNCT => $e:expr, $l:expr, $c:expr) => {
Token::new($e, TokenType::PUNCT, $l, $c)
};
(DIGIT => $e: expr, $l: expr, $c: expr) => {
(DIGIT => $e:expr, $l:expr, $c:expr) => {
Token::new($e, TokenType::DIGIT, $l, $c)
};
($e: expr, $l: expr, $c: expr) => {
($e:expr, $l:expr, $c:expr) => {
Token::new($e, TokenType::BAREWORD, $l, $c)
};
}
@ -149,15 +149,15 @@ macro_rules! make_tok {
/// Helper macro for making expressions.
#[allow(unused_macros)]
macro_rules! make_expr {
($e: expr) => {
($e:expr) => {
make_expr!($e, 1, 1)
};
($e: expr, $l: expr, $c: expr) => {
($e:expr, $l:expr, $c:expr) => {
Expression::Simple(Value::Symbol(Positioned::new($e.to_string(), $l, $c)))
};
($e: expr => int, $l: expr, $c: expr) => {
($e:expr => int, $l:expr, $c:expr) => {
Expression::Simple(Value::Int(Positioned::new($e, $l, $c)))
};
}

View File

@ -13,23 +13,23 @@
// limitations under the License.
//! The build stage of the ucg compiler.
use std::env;
use std::fs::File;
use std::io::Read;
use std::error::Error;
use std::collections::{HashMap, HashSet, VecDeque};
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet, VecDeque};
use std::convert::From;
use std::env;
use std::error::Error;
use std::fmt;
use std::fmt::{Display, Formatter};
use std::fs::File;
use std::io::Read;
use std::ops::Deref;
use std::rc::Rc;
use std::convert::From;
use tokenizer::Span;
use ast::tree::*;
use error;
use format;
use parse::parse;
use error;
use tokenizer::Span;
impl MacroDef {
/// Expands a ucg Macro using the given arguments into a new Tuple.
@ -295,7 +295,7 @@ pub struct Builder {
}
macro_rules! eval_binary_expr {
($case: pat, $pos: ident, $rside: ident, $result: expr, $msg: expr) => {
($case:pat, $pos:ident, $rside:ident, $result:expr, $msg:expr) => {
match $rside.as_ref() {
$case => {
return Ok(Rc::new($result));

View File

@ -13,9 +13,9 @@
// limitations under the License.
//! An environment variable converter.
use std::rc::Rc;
use std::io::Write;
use std::io::Result;
use std::io::Write;
use std::rc::Rc;
use ast::tree::*;
use build::Val;

View File

@ -13,9 +13,9 @@
// limitations under the License.
//! Contains code for converting a UCG Val into the command line flag output target.
use std::rc::Rc;
use std::io::Write;
use std::io::Result;
use std::io::Write;
use std::rc::Rc;
use build::Val;
use convert::traits::Converter;

View File

@ -8,9 +8,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Flags contains code for converting a UCG Val into the json output target.
use std::rc::Rc;
use std::io::Write;
use std::io::Result;
use std::io::Write;
use std::rc::Rc;
use serde_json;

View File

@ -13,9 +13,9 @@
// limitations under the License.
//! The conversion stage of the ucg compiler.
pub mod env;
pub mod flags;
pub mod json;
pub mod env;
pub mod traits;
use std::io;

View File

@ -13,9 +13,9 @@
// limitations under the License.
//! The traits used by the ucg compiler for converting Val intermediate format into the output formats..
use std::rc::Rc;
use std::io::Write;
use std::io::Result;
use std::io::Write;
use std::rc::Rc;
use build::Val;

View File

@ -409,17 +409,17 @@ extern crate serde_json;
pub mod ast;
#[macro_use]
pub mod tokenizer;
pub mod parse;
pub mod build;
pub mod convert;
pub mod error;
pub mod parse;
mod format;
pub use ast::tree::Value;
pub use ast::tree::Expression;
pub use ast::tree::Statement;
pub use ast::tree::Value;
pub use parse::parse;
pub use build::Builder;
pub use build::Val;
pub use parse::parse;

View File

@ -16,12 +16,12 @@ extern crate clap;
extern crate ucglib;
use std::fs::File;
use std::rc::Rc;
use std::io;
use std::process;
use std::rc::Rc;
use ucglib::build::Val;
use ucglib::build;
use ucglib::build::Val;
use ucglib::convert::ConverterRunner;
// TODO(jwall): List the target output types automatically.

View File

@ -13,17 +13,17 @@
// limitations under the License.
//! The Parsing stage of the ucg compiler.
use std::str::FromStr;
use std::borrow::Borrow;
use std::str::FromStr;
use nom_locate::LocatedSpan;
use nom;
use nom::InputLength;
use nom::IResult;
use nom::InputLength;
use nom_locate::LocatedSpan;
use ast::tree::*;
use tokenizer::*;
use error;
use tokenizer::*;
type NomResult<'a, O> = nom::IResult<TokenIter<'a>, O, error::Error>;
@ -844,14 +844,14 @@ mod test {
use super::*;
use tokenizer::{tokenize, TokenIter};
use nom_locate::LocatedSpan;
use nom::IResult;
use nom_locate::LocatedSpan;
macro_rules! assert_parse {
($parsemac: ident($i: expr), $out: expr) => {
($parsemac:ident($i:expr), $out:expr) => {
assert_parse!($i, $parsemac, $out)
};
($i: expr, $f: expr, $out: expr) => {{
($i:expr, $f:expr, $out:expr) => {{
let input = LocatedSpan::new($i);
match tokenize(input) {
Err(e) => assert!(false, format!("Tokenizer Error: {:?}", e)),
@ -866,10 +866,10 @@ mod test {
}
macro_rules! assert_error {
($parsemac: ident($i: expr)) => {
($parsemac:ident($i:expr)) => {
assert_error!($i, $parsemac)
};
($i: expr, $f: expr) => {{
($i:expr, $f:expr) => {{
let input = LocatedSpan::new($i);
match tokenize(input) {
Err(_) => assert!(true),
@ -1801,7 +1801,7 @@ mod test {
(
make_tok!("foo", 1, 1),
Expression::Simple(Value::Selector(
make_selector!(make_expr!("bar", 1, 7) => [ make_tok!("baz", 1, 11) ] => 1, 7)
make_selector!(make_expr!("bar", 1, 7) => [ make_tok!("baz", 1, 11) ] => 1, 7),
))
)
);

View File

@ -13,12 +13,12 @@
// limitations under the License.
//! The tokenization stage of the ucg compiler.
use nom_locate::LocatedSpan;
use nom;
use nom::{alpha, digit, is_alphanumeric, multispace};
use nom::{InputIter, InputLength, Slice};
use ast::tree::*;
use error;
use nom;
use nom::{InputIter, InputLength, Slice};
use nom::{alpha, digit, is_alphanumeric, multispace};
use nom_locate::LocatedSpan;
use std;
use std::result::Result;
@ -121,16 +121,15 @@ macro_rules! do_tag_tok {
// paramater even though we don't explicitely pass it below. I don't
// particularly like this but I'm living with it for now.
($i:expr, $type:expr, $tag:expr) => {
do_parse!($i,
span: position!() >>
frag: tag!($tag) >>
(Token{
do_parse!(
$i,
span: position!() >> frag: tag!($tag) >> (Token {
typ: $type,
pos: Position::from(span),
fragment: frag.fragment.to_string(),
})
)
}
};
}
named!(emptytok( Span ) -> Token,
@ -416,113 +415,116 @@ pub fn token_clone(t: &Token) -> Result<Token, error::Error> {
/// nom macro that matches a Token by type and uses an optional conversion handler
/// for the matched Token.
macro_rules! match_type {
($i:expr, BOOLEAN => $h:expr) => {
($i:expr,BOOLEAN => $h:expr) => {
match_type!($i, TokenType::BOOLEAN, "Not a Boolean", $h)
};
($i:expr, BOOLEAN) => {
($i:expr,BOOLEAN) => {
match_type!($i, BOOLEAN => token_clone)
};
($i:expr, COMMENT => $h:expr) => {
($i:expr,COMMENT => $h:expr) => {
match_type!($i, TokenType::COMMENT, "Not a Comment", $h)
};
($i:expr, COMMENT) => {
($i:expr,COMMENT) => {
match_type!($i, COMMENT => token_clone)
};
($i:expr, BAREWORD => $h:expr) => {
($i:expr,BAREWORD => $h:expr) => {
match_type!($i, TokenType::BAREWORD, "Not a Bareword", $h)
};
($i:expr, BAREWORD) => {
($i:expr,BAREWORD) => {
match_type!($i, BAREWORD => token_clone)
};
($i:expr, EMPTY => $h:expr) => {
($i:expr,EMPTY => $h:expr) => {
match_type!($i, TokenType::EMPTY, "Not NULL", $h)
};
($i:expr, EMPTY) => {
($i:expr,EMPTY) => {
match_type!($i, EMPTY => token_clone)
};
($i:expr, STR => $h:expr) => {
($i:expr,STR => $h:expr) => {
match_type!($i, TokenType::QUOTED, "Not a String", $h)
};
($i:expr, STR) => {
($i:expr,STR) => {
match_type!($i, STR => token_clone)
};
($i:expr, DIGIT => $h:expr) => {
($i:expr,DIGIT => $h:expr) => {
match_type!($i, TokenType::DIGIT, "Not a DIGIT", $h)
};
($i:expr, DIGIT) => {
($i:expr,DIGIT) => {
match_type!($i, DIGIT => token_clone)
};
($i:expr, PUNCT => $h:expr) => {
($i:expr,PUNCT => $h:expr) => {
match_type!($i, TokenType::PUNCT, "Not PUNCTUATION", $h)
};
($i:expr, PUNCT) => {
($i:expr,PUNCT) => {
match_type!($i, PUNCT => token_clone)
};
($i:expr, $t:expr, $msg:expr, $h:expr) => {
{
($i:expr, $t:expr, $msg:expr, $h:expr) => {{
let i_ = $i.clone();
use nom::Slice;
use std::convert::Into;
if i_.input_len() == 0 {
nom::IResult::Error(
nom::ErrorKind::Custom(error::Error::new(
nom::IResult::Error(nom::ErrorKind::Custom(error::Error::new(
format!("End of Input! {}", $msg),
error::ErrorType::IncompleteParsing,
Position{line: 0, column: 0})))
Position { line: 0, column: 0 },
)))
} else {
let tok = &(i_[0]);
if tok.typ == $t {
match $h(tok) {
Result::Ok(v) => nom::IResult::Done($i.slice(1..), v),
Result::Err(e) => nom::IResult::Error(
nom::ErrorKind::Custom(e.into())),
Result::Err(e) => nom::IResult::Error(nom::ErrorKind::Custom(e.into())),
}
} else {
nom::IResult::Error(nom::ErrorKind::Custom(error::Error::new(
$msg.to_string(),
error::ErrorType::UnexpectedToken,
tok.pos.clone())))
tok.pos.clone(),
)))
}
}
}
};
}};
}
/// nom style macro that matches various Tokens by type and value and allows optional
/// conversion handlers for the matched Token.
macro_rules! match_token {
($i:expr, PUNCT => $f:expr) => {
($i:expr,PUNCT => $f:expr) => {
match_token!($i, PUNCT => $f, token_clone)
};
($i:expr, PUNCT => $f:expr, $h:expr) => {
($i:expr,PUNCT => $f:expr, $h:expr) => {
match_token!($i, TokenType::PUNCT, $f, format!("Not PUNCT ({})", $f), $h)
};
($i:expr, BAREWORD => $f:expr) => {
($i:expr,BAREWORD => $f:expr) => {
match_token!($i, BAREWORD => $f, token_clone)
};
($i:expr, BAREWORD => $f:expr, $h:expr) => {
match_token!($i, TokenType::BAREWORD, $f, format!("Not a BAREWORD ({})", $f), $h)
($i:expr,BAREWORD => $f:expr, $h:expr) => {
match_token!(
$i,
TokenType::BAREWORD,
$f,
format!("Not a BAREWORD ({})", $f),
$h
)
};
($i:expr, $t:expr, $f:expr, $msg:expr, $h:expr) => {
{
($i:expr, $t:expr, $f:expr, $msg:expr, $h:expr) => {{
let i_ = $i.clone();
use nom::Slice;
use std::convert::Into;
@ -530,17 +532,16 @@ macro_rules! match_token {
if tok.typ == $t && &tok.fragment == $f {
match $h(tok) {
Result::Ok(v) => nom::IResult::Done($i.slice(1..), v),
Result::Err(e) => nom::IResult::Error(
nom::ErrorKind::Custom(e.into())),
Result::Err(e) => nom::IResult::Error(nom::ErrorKind::Custom(e.into())),
}
} else {
nom::IResult::Error(nom::ErrorKind::Custom(error::Error::new(
format!("{} Instead is ({})", $msg, tok.fragment),
error::ErrorType::UnexpectedToken,
tok.pos.clone())))
tok.pos.clone(),
)))
}
}
};
}};
}
/// nom style macro that matches punctuation Tokens.
@ -599,7 +600,7 @@ macro_rules! impl_token_iter_slice {
}
}
}
}
};
}
impl_token_iter_slice!(std::ops::Range<usize>);
@ -713,7 +714,7 @@ mod tokenizer_test {
assert_eq!(tok.fragment, $input);
assert_eq!(tok.typ, $typ);
}
}
};
}
#[test]