Fixed panic issue caused by integer and float parsing.. #215
This commit is contained in:
parent
b60c57bc40
commit
23988675fe
@ -2,10 +2,11 @@ use crate::pos::Positioned;
|
|||||||
use crate::query::*;
|
use crate::query::*;
|
||||||
use crate::utils::{unquote_string, PositionCalculator};
|
use crate::utils::{unquote_string, PositionCalculator};
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
use crate::Result;
|
use crate::{Error, Result};
|
||||||
use pest::iterators::Pair;
|
use pest::iterators::Pair;
|
||||||
use pest::Parser;
|
use pest::Parser;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::num::{ParseFloatError, ParseIntError};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[grammar = "query.pest"]
|
#[grammar = "query.pest"]
|
||||||
@ -241,8 +242,24 @@ fn parse_value2(pair: Pair<Rule>, pc: &mut PositionCalculator) -> Result<Value>
|
|||||||
Rule::object => parse_object_value(pair, pc)?,
|
Rule::object => parse_object_value(pair, pc)?,
|
||||||
Rule::array => parse_array_value(pair, pc)?,
|
Rule::array => parse_array_value(pair, pc)?,
|
||||||
Rule::variable => Value::Variable(parse_variable(pair, pc)?.into_inner()),
|
Rule::variable => Value::Variable(parse_variable(pair, pc)?.into_inner()),
|
||||||
Rule::float => Value::Float(pair.as_str().parse().unwrap()),
|
Rule::float => {
|
||||||
Rule::int => Value::Int(pair.as_str().parse().unwrap()),
|
let pos = pc.step(&pair);
|
||||||
|
Value::Float(
|
||||||
|
pair.as_str()
|
||||||
|
.parse()
|
||||||
|
.map_err(|err: ParseFloatError| Error {
|
||||||
|
pos,
|
||||||
|
message: err.to_string(),
|
||||||
|
})?,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Rule::int => {
|
||||||
|
let pos = pc.step(&pair);
|
||||||
|
Value::Int(pair.as_str().parse().map_err(|err: ParseIntError| Error {
|
||||||
|
pos,
|
||||||
|
message: err.to_string(),
|
||||||
|
})?)
|
||||||
|
}
|
||||||
Rule::string => Value::String({
|
Rule::string => Value::String({
|
||||||
let pos = pc.step(&pair);
|
let pos = pc.step(&pair);
|
||||||
unquote_string(pair.as_str(), pos)?
|
unquote_string(pair.as_str(), pos)?
|
||||||
|
Loading…
Reference in New Issue
Block a user