Skip to content

Commit

Permalink
Implement copy on jsonpath::Pos.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Nov 27, 2023
1 parent a8e7fe9 commit b7346a8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions packages/hurl/src/jsonpath/parser/combinators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use super::reader::Reader;
use super::{ParseFunc, ParseResult};

pub fn zero_or_more<T>(f: ParseFunc<T>, p: &mut Reader) -> ParseResult<Vec<T>> {
let _start = p.state.clone();
let _start = p.state;

let mut v: Vec<T> = Vec::new();
loop {
let initial_state = p.state.clone();
let initial_state = p.state;
if p.is_eof() {
return Ok(v);
}
Expand All @@ -50,7 +50,7 @@ pub fn zero_or_more<T>(f: ParseFunc<T>, p: &mut Reader) -> ParseResult<Vec<T>> {
/// Typically this should be recoverable
pub fn choice<T>(fs: &[ParseFunc<T>], reader: &mut Reader) -> ParseResult<T> {
for (pos, f) in fs.iter().enumerate() {
let start = reader.state.clone();
let start = reader.state;
if pos == fs.len() - 1 {
return f(reader);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/jsonpath/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use error::Error;
use reader::Reader;

#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Pos {
pub line: usize,
pub column: usize,
Expand Down
24 changes: 12 additions & 12 deletions packages/hurl/src/jsonpath/parser/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn query(reader: &mut Reader) -> ParseResult<Query> {
let selectors = zero_or_more(selector, reader)?;
if !reader.is_eof() {
return Err(Error {
pos: reader.state.pos.clone(),
pos: reader.state.pos,
recoverable: false,
inner: ParseError::Expecting {
value: "eof".to_string(),
Expand Down Expand Up @@ -61,7 +61,7 @@ fn selector(reader: &mut Reader) -> ParseResult<Selector> {
}

fn selector_array_index_or_array_indices(reader: &mut Reader) -> Result<Selector, Error> {
let initial_state = reader.state.clone();
let initial_state = reader.state;
try_left_bracket(reader)?;
let mut indexes = vec![];
let i = match natural(reader) {
Expand All @@ -76,7 +76,7 @@ fn selector_array_index_or_array_indices(reader: &mut Reader) -> Result<Selector
};
indexes.push(i);
loop {
let state = reader.state.clone();
let state = reader.state;
if try_literal(",", reader).is_ok() {
let i = match natural(reader) {
Err(e) => {
Expand All @@ -99,7 +99,7 @@ fn selector_array_index_or_array_indices(reader: &mut Reader) -> Result<Selector
if let Err(e) = try_literal("]", reader) {
reader.state = initial_state;
return Err(Error {
pos: reader.state.pos.clone(),
pos: reader.state.pos,
recoverable: true,
inner: e.inner,
});
Expand All @@ -121,10 +121,10 @@ fn selector_array_wildcard(reader: &mut Reader) -> Result<Selector, Error> {

fn selector_array_slice(reader: &mut Reader) -> Result<Selector, Error> {
try_left_bracket(reader)?;
let state = reader.state.clone();
let state = reader.state;
let start = match integer(reader) {
Err(_) => {
reader.state = state.clone();
reader.state = state;
None
}
Ok(v) => Some(v),
Expand All @@ -138,7 +138,7 @@ fn selector_array_slice(reader: &mut Reader) -> Result<Selector, Error> {
},
});
};
let state = reader.state.clone();
let state = reader.state;
let end = match integer(reader) {
Err(_) => {
reader.state = state;
Expand All @@ -162,7 +162,7 @@ fn selector_object_key_bracket(reader: &mut Reader) -> Result<Selector, Error> {
try_left_bracket(reader)?;
match string_value(reader) {
Err(_) => Err(Error {
pos: reader.state.pos.clone(),
pos: reader.state.pos,
recoverable: true,
inner: ParseError::Expecting {
value: "value string".to_string(),
Expand All @@ -178,7 +178,7 @@ fn selector_object_key_bracket(reader: &mut Reader) -> Result<Selector, Error> {
fn selector_object_key(reader: &mut Reader) -> Result<Selector, Error> {
if !reader.try_literal(".") {
return Err(Error {
pos: reader.state.pos.clone(),
pos: reader.state.pos,
recoverable: true,
inner: ParseError::Expecting {
value: "[ or .".to_string(),
Expand All @@ -189,7 +189,7 @@ fn selector_object_key(reader: &mut Reader) -> Result<Selector, Error> {
let s = reader.read_while(|c| c.is_alphanumeric() || *c == '_' || *c == '-');
if s.is_empty() {
return Err(Error {
pos: reader.state.pos.clone(),
pos: reader.state.pos,
recoverable: false,
inner: ParseError::Expecting {
value: "empty value".to_string(),
Expand All @@ -216,7 +216,7 @@ fn selector_recursive_key(reader: &mut Reader) -> Result<Selector, Error> {
}

fn try_left_bracket(reader: &mut Reader) -> Result<(), Error> {
let start = reader.state.clone();
let start = reader.state;
if literal(".[", reader).is_err() {
reader.state = start;
try_literal("[", reader)?;
Expand All @@ -236,7 +236,7 @@ fn predicate(reader: &mut Reader) -> ParseResult<Predicate> {
// @.key>=value GreaterThanOrEqual(Key, Value)
literal("@.", reader)?; // assume key value for the time being
let key = key_path(reader)?;
let state = reader.state.clone();
let state = reader.state;
let func = match predicate_func(reader) {
Ok(f) => f,
Err(_) => {
Expand Down
16 changes: 8 additions & 8 deletions packages/hurl/src/jsonpath/parser/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::error::{Error, ParseError};
use super::{ParseResult, Reader};

pub fn natural(reader: &mut Reader) -> ParseResult<usize> {
let start = reader.state.clone();
let start = reader.state;

if reader.is_eof() {
return Err(Error {
Expand All @@ -42,7 +42,7 @@ pub fn natural(reader: &mut Reader) -> ParseResult<usize> {
});
}

let save = reader.state.clone();
let save = reader.state;
let s = reader.read_while(|c| c.is_ascii_digit());

// if the first digit is zero, you should not have any more digits
Expand Down Expand Up @@ -103,7 +103,7 @@ pub fn string_value(reader: &mut Reader) -> Result<String, Error> {
match reader.read() {
None => {
return Err(Error {
pos: reader.state.pos.clone(),
pos: reader.state.pos,
recoverable: false,
inner: ParseError::Expecting {
value: String::from("'"),
Expand All @@ -119,7 +119,7 @@ pub fn string_value(reader: &mut Reader) -> Result<String, Error> {
}
_ => {
return Err(Error {
pos: reader.state.pos.clone(),
pos: reader.state.pos,
recoverable: false,
inner: ParseError::Expecting {
value: String::from("'"),
Expand Down Expand Up @@ -148,7 +148,7 @@ pub fn key_name(reader: &mut Reader) -> Result<String, Error> {
c
} else {
return Err(Error {
pos: reader.state.pos.clone(),
pos: reader.state.pos,
recoverable: false,
inner: ParseError::Expecting {
value: "key".to_string(),
Expand All @@ -158,7 +158,7 @@ pub fn key_name(reader: &mut Reader) -> Result<String, Error> {
}
None => {
return Err(Error {
pos: reader.state.pos.clone(),
pos: reader.state.pos,
recoverable: false,
inner: ParseError::Expecting {
value: "key".to_string(),
Expand Down Expand Up @@ -187,7 +187,7 @@ pub fn literal(s: &str, reader: &mut Reader) -> ParseResult<()> {
// does not return a value
// non recoverable reader
// => use combinator recover to make it recoverable
let start = reader.state.clone();
let start = reader.state;
if reader.clone().is_eof() {
return Err(Error {
pos: start.pos,
Expand All @@ -198,7 +198,7 @@ pub fn literal(s: &str, reader: &mut Reader) -> ParseResult<()> {
});
}
for c in s.chars() {
let _state = reader.state.clone();
let _state = reader.state;
match reader.read() {
None => {
return Err(Error {
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/jsonpath/parser/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Reader {
pub state: ReaderState,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct ReaderState {
pub cursor: usize,
pub pos: Pos,
Expand Down

0 comments on commit b7346a8

Please sign in to comment.