Skip to content

Commit

Permalink
actiondb: run rustfmt on the source code
Browse files Browse the repository at this point in the history
The default settings were applied:

./rustfmt --write-mode=replace /home/tibi/workspace/actiondb/src/lib.rs

Signed-off-by: Tibor Benke <ihrwein@gmail.com>
  • Loading branch information
ihrwein committed Oct 31, 2015
1 parent 383600b commit b3db276
Show file tree
Hide file tree
Showing 38 changed files with 1,183 additions and 889 deletions.
70 changes: 35 additions & 35 deletions src/bin/adbtool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,39 @@ const OUTPUT_FILE: &'static str = "output file";

fn build_command_line_argument_parser<'a, 'b, 'c, 'd, 'e, 'f>() -> App<'a, 'b, 'c, 'd, 'e, 'f> {
App::new(APPNAME)
.version(VERSION)
.author(AUTHOR)
.about("Tool for parsing unstructured data")
.arg(Arg::with_name(DEBUG)
.short("d")
.help("Enable debug messages"))
.subcommand(SubCommand::with_name(VALIDATE)
.about("validates pattern file")
.version(VERSION)
.author(AUTHOR)
.arg(Arg::with_name(PATTERN_FILE)
.required(true)
.index(1)
.help("The pattern file to be validated"))
.arg(Arg::with_name(IGNORE_ERRORS)
.short("i")
.help("Don't stop at the first test message error")))
.subcommand(SubCommand::with_name(PARSE)
.about("parses a file based on predefined patterns")
.version(VERSION)
.author(AUTHOR)
.arg(Arg::with_name(PATTERN_FILE)
.required(true)
.index(1)
.help("The pattern file which contains predefined patterns"))
.arg(Arg::with_name(INPUT_FILE)
.required(true)
.index(2)
.help("The input file to be parsed"))
.arg(Arg::with_name(OUTPUT_FILE)
.required(true)
.index(3)
.help("The output file where the results are written")))
.version(VERSION)
.author(AUTHOR)
.about("Tool for parsing unstructured data")
.arg(Arg::with_name(DEBUG)
.short("d")
.help("Enable debug messages"))
.subcommand(SubCommand::with_name(VALIDATE)
.about("validates pattern file")
.version(VERSION)
.author(AUTHOR)
.arg(Arg::with_name(PATTERN_FILE)
.required(true)
.index(1)
.help("The pattern file to be validated"))
.arg(Arg::with_name(IGNORE_ERRORS)
.short("i")
.help("Don't stop at the first test message error")))
.subcommand(SubCommand::with_name(PARSE)
.about("parses a file based on predefined patterns")
.version(VERSION)
.author(AUTHOR)
.arg(Arg::with_name(PATTERN_FILE)
.required(true)
.index(1)
.help("The pattern file which contains predefined patterns"))
.arg(Arg::with_name(INPUT_FILE)
.required(true)
.index(2)
.help("The input file to be parsed"))
.arg(Arg::with_name(OUTPUT_FILE)
.required(true)
.index(3)
.help("The output file where the results are written")))
}

fn handle_validate(matches: &ArgMatches) {
Expand All @@ -87,7 +87,7 @@ fn validate_patterns_independently(pattern_file: &str) {
error!("{}", error);
}
}
},
}
Err(error) => {
error!("{}", error);
std::process::exit(1);
Expand All @@ -113,7 +113,7 @@ fn setup_stdout_logger(log_level: LogLevelFilter) {
});
}

fn choose_log_level<'n, 'a>(matches: &ArgMatches<'n ,'a>) -> LogLevelFilter {
fn choose_log_level<'n, 'a>(matches: &ArgMatches<'n, 'a>) -> LogLevelFilter {
if matches.is_present(DEBUG) {
LogLevelFilter::Debug
} else {
Expand Down
12 changes: 8 additions & 4 deletions src/bin/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ use std::io::{BufReader, BufRead, Error, ErrorKind, BufWriter, Write};
use actiondb::Matcher;
use actiondb::matcher;

pub fn parse(pattern_file_path: &str, input_file_path: &str, output_file_path: &str) -> Result<(), Error> {
pub fn parse(pattern_file_path: &str,
input_file_path: &str,
output_file_path: &str)
-> Result<(), Error> {
match matcher::Factory::from_file(pattern_file_path) {
Ok(matcher) => {
let input_file = try!(File::open(input_file_path));
let mut output_file= try!(File::create(output_file_path));
let mut output_file = try!(File::create(output_file_path));
parse_file(&input_file, &mut output_file, &matcher);
Ok(())
},
}
Err(err) => {
Err(Error::new(ErrorKind::Other, format!("Failed to parse a pattern in the input file: {:?}", err)))
Err(Error::new(ErrorKind::Other,
format!("Failed to parse a pattern in the input file: {:?}", err)))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ mod test;
pub mod parser;

pub fn unescape_literal(literal: &str) -> String {
literal.replace(r#"\%\{"#, "%{")
literal.replace(r#"\%\{"#, "%{")
}
22 changes: 13 additions & 9 deletions src/grammar/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ pub fn pattern_with_factory<F: ParserFactory>(input: &str) -> ParseResult<Compil
self::pattern_parser::pattern::<F>(input)
}

/*
When you regenerate the grammar, don't forget to insert the F generic type parameter with
the following command:
rm -f pattern_parser.rs; cat pattern_parser.rs.IN | sed "s/\(fn [a-zA-Z0-9_]*<'input\)/\1, F: ParserFactory/" | sed "s/\(parse[a-zA-Z0-9_]*\)(/\1::<F>(/" >> pattern_parser.rs
The first sed add the F: ParserFactory generic type parameter to every function definition.
The second sed threads this F parameter through the call sites as well.
*/
//
// When you regenerate the grammar, don't forget to insert the F generic type
// parameter with
// the following command:
// rm -f pattern_parser.rs; cat pattern_parser.rs.IN | sed "s/\(fn
// [a-zA-Z0-9_]*<'input\)/\1, F: ParserFactory/" | sed
// "s/\(parse[a-zA-Z0-9_]*\)(/\1::<F>(/" >> pattern_parser.rs
//
// The first sed add the F: ParserFactory generic type parameter to every
// function definition.
// The second sed threads this F parameter through the call sites as well.
//
pub fn pattern(input: &str) -> ParseResult<CompiledPattern> {
use ::matcher::trie::parser_factory::TrieParserFactory;
use matcher::trie::parser_factory::TrieParserFactory;
self::pattern_parser::pattern::<TrieParserFactory>(input)
}
Loading

0 comments on commit b3db276

Please sign in to comment.