mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
Formatting: cargo fmt.
This commit is contained in:
parent
f4b5cf1b0c
commit
00c1e1751a
@ -12,15 +12,15 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use std;
|
use std;
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::convert::Into;
|
|
||||||
use std::cmp::Ordering;
|
|
||||||
use std::cmp::PartialOrd;
|
|
||||||
use std::cmp::Eq;
|
use std::cmp::Eq;
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::cmp::PartialEq;
|
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::Hash;
|
||||||
|
use std::hash::Hasher;
|
||||||
|
|
||||||
macro_rules! enum_type_equality {
|
macro_rules! enum_type_equality {
|
||||||
( $slf:ident, $r:expr, $( $l:pat ),* ) => {
|
( $slf:ident, $r:expr, $( $l:pat ),* ) => {
|
||||||
|
16
src/build.rs
16
src/build.rs
@ -13,23 +13,23 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! The build stage of the ucg compiler.
|
//! 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::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;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::convert::From;
|
|
||||||
|
|
||||||
use tokenizer::Span;
|
|
||||||
use ast::tree::*;
|
use ast::tree::*;
|
||||||
|
use error;
|
||||||
use format;
|
use format;
|
||||||
use parse::parse;
|
use parse::parse;
|
||||||
use error;
|
use tokenizer::Span;
|
||||||
|
|
||||||
impl MacroDef {
|
impl MacroDef {
|
||||||
/// Expands a ucg Macro using the given arguments into a new Tuple.
|
/// Expands a ucg Macro using the given arguments into a new Tuple.
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! An environment variable converter.
|
//! An environment variable converter.
|
||||||
use std::rc::Rc;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use ast::tree::*;
|
use ast::tree::*;
|
||||||
use build::Val;
|
use build::Val;
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! Contains code for converting a UCG Val into the command line flag output target.
|
//! 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::Result;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use build::Val;
|
use build::Val;
|
||||||
use convert::traits::Converter;
|
use convert::traits::Converter;
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//! Flags contains code for converting a UCG Val into the json output target.
|
//! 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::Result;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! The conversion stage of the ucg compiler.
|
//! The conversion stage of the ucg compiler.
|
||||||
|
pub mod env;
|
||||||
pub mod flags;
|
pub mod flags;
|
||||||
pub mod json;
|
pub mod json;
|
||||||
pub mod env;
|
|
||||||
pub mod traits;
|
pub mod traits;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! The traits used by the ucg compiler for converting Val intermediate format into the output formats..
|
//! 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::Result;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use build::Val;
|
use build::Val;
|
||||||
|
|
||||||
|
@ -409,17 +409,17 @@ extern crate serde_json;
|
|||||||
pub mod ast;
|
pub mod ast;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod tokenizer;
|
pub mod tokenizer;
|
||||||
pub mod parse;
|
|
||||||
pub mod build;
|
pub mod build;
|
||||||
pub mod convert;
|
pub mod convert;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
pub mod parse;
|
||||||
|
|
||||||
mod format;
|
mod format;
|
||||||
|
|
||||||
pub use ast::tree::Value;
|
|
||||||
pub use ast::tree::Expression;
|
pub use ast::tree::Expression;
|
||||||
pub use ast::tree::Statement;
|
pub use ast::tree::Statement;
|
||||||
|
pub use ast::tree::Value;
|
||||||
|
|
||||||
pub use parse::parse;
|
|
||||||
pub use build::Builder;
|
pub use build::Builder;
|
||||||
pub use build::Val;
|
pub use build::Val;
|
||||||
|
pub use parse::parse;
|
||||||
|
@ -16,12 +16,12 @@ extern crate clap;
|
|||||||
extern crate ucglib;
|
extern crate ucglib;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::rc::Rc;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use ucglib::build::Val;
|
|
||||||
use ucglib::build;
|
use ucglib::build;
|
||||||
|
use ucglib::build::Val;
|
||||||
use ucglib::convert::ConverterRunner;
|
use ucglib::convert::ConverterRunner;
|
||||||
|
|
||||||
// TODO(jwall): List the target output types automatically.
|
// TODO(jwall): List the target output types automatically.
|
||||||
|
12
src/parse.rs
12
src/parse.rs
@ -13,17 +13,17 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! The Parsing stage of the ucg compiler.
|
//! The Parsing stage of the ucg compiler.
|
||||||
use std::str::FromStr;
|
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use nom_locate::LocatedSpan;
|
|
||||||
use nom;
|
use nom;
|
||||||
use nom::InputLength;
|
|
||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
|
use nom::InputLength;
|
||||||
|
use nom_locate::LocatedSpan;
|
||||||
|
|
||||||
use ast::tree::*;
|
use ast::tree::*;
|
||||||
use tokenizer::*;
|
|
||||||
use error;
|
use error;
|
||||||
|
use tokenizer::*;
|
||||||
|
|
||||||
type NomResult<'a, O> = nom::IResult<TokenIter<'a>, O, error::Error>;
|
type NomResult<'a, O> = nom::IResult<TokenIter<'a>, O, error::Error>;
|
||||||
|
|
||||||
@ -844,8 +844,8 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use tokenizer::{tokenize, TokenIter};
|
use tokenizer::{tokenize, TokenIter};
|
||||||
|
|
||||||
use nom_locate::LocatedSpan;
|
|
||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
|
use nom_locate::LocatedSpan;
|
||||||
|
|
||||||
macro_rules! assert_parse {
|
macro_rules! assert_parse {
|
||||||
($parsemac:ident($i:expr), $out:expr) => {
|
($parsemac:ident($i:expr), $out:expr) => {
|
||||||
@ -1801,7 +1801,7 @@ mod test {
|
|||||||
(
|
(
|
||||||
make_tok!("foo", 1, 1),
|
make_tok!("foo", 1, 1),
|
||||||
Expression::Simple(Value::Selector(
|
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),
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//! The tokenization stage of the ucg compiler.
|
//! 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 ast::tree::*;
|
||||||
use error;
|
use error;
|
||||||
|
use nom;
|
||||||
|
use nom::{InputIter, InputLength, Slice};
|
||||||
|
use nom::{alpha, digit, is_alphanumeric, multispace};
|
||||||
|
use nom_locate::LocatedSpan;
|
||||||
use std;
|
use std;
|
||||||
use std::result::Result;
|
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
|
// paramater even though we don't explicitely pass it below. I don't
|
||||||
// particularly like this but I'm living with it for now.
|
// particularly like this but I'm living with it for now.
|
||||||
($i:expr, $type:expr, $tag:expr) => {
|
($i:expr, $type:expr, $tag:expr) => {
|
||||||
do_parse!($i,
|
do_parse!(
|
||||||
span: position!() >>
|
$i,
|
||||||
frag: tag!($tag) >>
|
span: position!() >> frag: tag!($tag) >> (Token {
|
||||||
(Token{
|
|
||||||
typ: $type,
|
typ: $type,
|
||||||
pos: Position::from(span),
|
pos: Position::from(span),
|
||||||
fragment: frag.fragment.to_string(),
|
fragment: frag.fragment.to_string(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
named!(emptytok( Span ) -> Token,
|
named!(emptytok( Span ) -> Token,
|
||||||
@ -472,34 +471,32 @@ macro_rules! match_type {
|
|||||||
match_type!($i, PUNCT => token_clone)
|
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();
|
let i_ = $i.clone();
|
||||||
use nom::Slice;
|
use nom::Slice;
|
||||||
use std::convert::Into;
|
use std::convert::Into;
|
||||||
if i_.input_len() == 0 {
|
if i_.input_len() == 0 {
|
||||||
nom::IResult::Error(
|
nom::IResult::Error(nom::ErrorKind::Custom(error::Error::new(
|
||||||
nom::ErrorKind::Custom(error::Error::new(
|
|
||||||
format!("End of Input! {}", $msg),
|
format!("End of Input! {}", $msg),
|
||||||
error::ErrorType::IncompleteParsing,
|
error::ErrorType::IncompleteParsing,
|
||||||
Position{line: 0, column: 0})))
|
Position { line: 0, column: 0 },
|
||||||
|
)))
|
||||||
} else {
|
} else {
|
||||||
let tok = &(i_[0]);
|
let tok = &(i_[0]);
|
||||||
if tok.typ == $t {
|
if tok.typ == $t {
|
||||||
match $h(tok) {
|
match $h(tok) {
|
||||||
Result::Ok(v) => nom::IResult::Done($i.slice(1..), v),
|
Result::Ok(v) => nom::IResult::Done($i.slice(1..), v),
|
||||||
Result::Err(e) => nom::IResult::Error(
|
Result::Err(e) => nom::IResult::Error(nom::ErrorKind::Custom(e.into())),
|
||||||
nom::ErrorKind::Custom(e.into())),
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nom::IResult::Error(nom::ErrorKind::Custom(error::Error::new(
|
nom::IResult::Error(nom::ErrorKind::Custom(error::Error::new(
|
||||||
$msg.to_string(),
|
$msg.to_string(),
|
||||||
error::ErrorType::UnexpectedToken,
|
error::ErrorType::UnexpectedToken,
|
||||||
tok.pos.clone())))
|
tok.pos.clone(),
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// nom style macro that matches various Tokens by type and value and allows optional
|
/// nom style macro that matches various Tokens by type and value and allows optional
|
||||||
@ -518,11 +515,16 @@ macro_rules! match_token {
|
|||||||
};
|
};
|
||||||
|
|
||||||
($i:expr,BAREWORD => $f:expr, $h:expr) => {
|
($i:expr,BAREWORD => $f:expr, $h:expr) => {
|
||||||
match_token!($i, TokenType::BAREWORD, $f, format!("Not a BAREWORD ({})", $f), $h)
|
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();
|
let i_ = $i.clone();
|
||||||
use nom::Slice;
|
use nom::Slice;
|
||||||
use std::convert::Into;
|
use std::convert::Into;
|
||||||
@ -530,17 +532,16 @@ macro_rules! match_token {
|
|||||||
if tok.typ == $t && &tok.fragment == $f {
|
if tok.typ == $t && &tok.fragment == $f {
|
||||||
match $h(tok) {
|
match $h(tok) {
|
||||||
Result::Ok(v) => nom::IResult::Done($i.slice(1..), v),
|
Result::Ok(v) => nom::IResult::Done($i.slice(1..), v),
|
||||||
Result::Err(e) => nom::IResult::Error(
|
Result::Err(e) => nom::IResult::Error(nom::ErrorKind::Custom(e.into())),
|
||||||
nom::ErrorKind::Custom(e.into())),
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nom::IResult::Error(nom::ErrorKind::Custom(error::Error::new(
|
nom::IResult::Error(nom::ErrorKind::Custom(error::Error::new(
|
||||||
format!("{} Instead is ({})", $msg, tok.fragment),
|
format!("{} Instead is ({})", $msg, tok.fragment),
|
||||||
error::ErrorType::UnexpectedToken,
|
error::ErrorType::UnexpectedToken,
|
||||||
tok.pos.clone())))
|
tok.pos.clone(),
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// nom style macro that matches punctuation Tokens.
|
/// 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>);
|
impl_token_iter_slice!(std::ops::Range<usize>);
|
||||||
@ -713,7 +714,7 @@ mod tokenizer_test {
|
|||||||
assert_eq!(tok.fragment, $input);
|
assert_eq!(tok.fragment, $input);
|
||||||
assert_eq!(tok.typ, $typ);
|
assert_eq!(tok.typ, $typ);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user