Add support for negative integers.
This commit is contained in:
@@ -119,6 +119,7 @@ pub struct Partial<'a> {
|
||||
pub enum OwnedLiteral {
|
||||
LString(String),
|
||||
LPositiveInteger(u64),
|
||||
LNegativeInteger(i64),
|
||||
LFloat(f64),
|
||||
}
|
||||
|
||||
@@ -354,6 +355,34 @@ fn postitive_integer_literal(i: &str) -> IResult<&str, u64> {
|
||||
)(i)
|
||||
}
|
||||
|
||||
/// No decimals, just the sign and digits
|
||||
fn negative_integer_literal(i: &str) -> IResult<&str, i64> {
|
||||
map(
|
||||
verify(
|
||||
map(
|
||||
recognize(tuple((tag("-"), digit1))),
|
||||
|number_string: &str| number_string.parse::<i64>(),
|
||||
),
|
||||
|parse_result| parse_result.is_ok(),
|
||||
),
|
||||
|parsed_number| parsed_number.unwrap(),
|
||||
)(i)
|
||||
}
|
||||
|
||||
/// A non-scientific notation float (sign, digits, decimal, and more digits)
|
||||
fn float_literal(i: &str) -> IResult<&str, f64> {
|
||||
map(
|
||||
verify(
|
||||
map(
|
||||
recognize(tuple((opt(one_of("+-")), digit1, tag("."), digit1))),
|
||||
|number_string: &str| number_string.parse::<f64>(),
|
||||
),
|
||||
|parse_result| parse_result.is_ok(),
|
||||
),
|
||||
|parsed_number| parsed_number.unwrap(),
|
||||
)(i)
|
||||
}
|
||||
|
||||
fn template_string_rvalue(i: &str) -> IResult<&str, Vec<PartialNameElement>> {
|
||||
let (i, template_string) = verify(quoted_string, |s: &String| {
|
||||
partial_quoted_tag(s.as_str()).is_ok()
|
||||
@@ -376,6 +405,12 @@ fn rvalue(i: &str) -> IResult<&str, RValue> {
|
||||
map(postitive_integer_literal, |num| {
|
||||
RValue::RVLiteral(OwnedLiteral::LPositiveInteger(num))
|
||||
}),
|
||||
map(negative_integer_literal, |num| {
|
||||
RValue::RVLiteral(OwnedLiteral::LNegativeInteger(num))
|
||||
}),
|
||||
map(float_literal, |num| {
|
||||
RValue::RVLiteral(OwnedLiteral::LFloat(num))
|
||||
}),
|
||||
))(i)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user