array 인자

This commit is contained in:
freestrings 2019-02-22 00:22:30 +09:00
parent 17a4f3b479
commit d6c35de863
8 changed files with 562 additions and 382 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.idea/*
.vscode
!.idea/runConfigurations/
/target/
Cargo.lock

View File

@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="filter_filter - trace" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<configuration default="false" name="filter_return_type - trace" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="channel" value="DEFAULT" />
<option name="command" value="test --package rs-jsonpath --lib jsonpath::json_filter::tests::filter -- --exact" />
<option name="command" value="test --package rs-jsonpath --lib jsonpath::json_filter::tests::return_type -- --exact" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="true" />
<option name="backtrace" value="NO" />

View File

@ -44,8 +44,7 @@
},
"friends": [
{
"id": 0,
"name": "Millicent Norman"
"id": 0
},
{
"id": 1,

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,4 @@
mod path_reader;
mod tokenizer;
mod parser;
mod json_filter;
mod utils;
mod json_filter;

View File

@ -5,12 +5,35 @@ use super::tokenizer::{
PreloadedTokenizer,
TokenError,
};
use super::utils;
const DUMMY: usize = 0;
type Result<T> = result::Result<T, String>;
mod utils {
use std::result;
pub fn vec_to_int<F>(vec: &Vec<char>, msg_handler: F) -> result::Result<isize, String>
where F: Fn() -> String {
match vec.iter().map(|c| *c).collect::<String>().as_str().parse::<isize>() {
Ok(n) => Ok(n),
_ => Err(msg_handler())
}
}
pub fn vec_to_float<F>(vec: &Vec<char>, msg_handler: F) -> result::Result<f64, String>
where F: Fn() -> String {
match vec.iter().map(|c| *c).collect::<String>().as_str().parse::<f64>() {
Ok(n) => Ok(n),
_ => Err(msg_handler())
}
}
pub fn vec_to_string(vec: &Vec<char>) -> String {
vec.iter().map(|c| *c).collect::<String>()
}
}
#[derive(Debug, PartialEq)]
pub enum ParseToken {
// '$'
@ -649,9 +672,9 @@ pub trait NodeVisitor {
}
ParseToken::Filter(_) => {
node.left.map(|n| self.visit(*n));
self.clean_filter_context();
self.end_term();
node.right.map(|n| self.visit(*n));
self.clean_filter_context();
self.end_term();
self.visit_token(node.token);
}
_ => {}
@ -659,7 +682,7 @@ pub trait NodeVisitor {
}
fn visit_token(&mut self, token: ParseToken);
fn clean_filter_context(&mut self) {}
fn end_term(&mut self) {}
}
#[cfg(test)]

View File

@ -291,28 +291,22 @@ impl<'a> PreloadedTokenizer<'a> {
pub fn new(input: &'a str) -> Self {
let mut tokenizer = Tokenizer::new(input);
let mut tokens = vec![];
let mut err = TokenError::Eof;
let mut err_pos = 0;
loop {
match tokenizer.next_token() {
Ok(t) => {
tokens.insert(0, (tokenizer.current_pos(), t));
}
Err(e) => {
err = e;
err_pos = tokenizer.current_pos();
break;
return PreloadedTokenizer {
origin_input: input.clone(),
err: e,
err_pos: tokenizer.current_pos(),
tokens,
curr_pos: None,
};
}
}
}
PreloadedTokenizer {
origin_input: input.clone(),
err,
err_pos,
tokens,
curr_pos: None,
}
}
pub fn peek_token(&self) -> result::Result<&Token, TokenError> {

View File

@ -1,21 +0,0 @@
use std::result;
pub fn vec_to_int<F>(vec: &Vec<char>, msg_handler: F) -> result::Result<isize, String>
where F: Fn() -> String {
match vec.iter().map(|c| *c).collect::<String>().as_str().parse::<isize>() {
Ok(n) => Ok(n),
_ => Err(msg_handler())
}
}
pub fn vec_to_float<F>(vec: &Vec<char>, msg_handler: F) -> result::Result<f64, String>
where F: Fn() -> String {
match vec.iter().map(|c| *c).collect::<String>().as_str().parse::<f64>() {
Ok(n) => Ok(n),
_ => Err(msg_handler())
}
}
pub fn vec_to_string(vec: &Vec<char>) -> String {
vec.iter().map(|c| *c).collect::<String>()
}