Fix 0x, 0b literals
This commit is contained in:
parent
ce848906c9
commit
31da29c324
@ -6,7 +6,7 @@ use std::str::FromStr;
|
||||
use nom::IResult;
|
||||
use nom::character::complete::{one_of, space0, alphanumeric0};
|
||||
use nom::bytes::complete::{tag, take, take_while, take_while1, take_until};
|
||||
use nom::combinator::{map, map_res, value, opt, verify};
|
||||
use nom::combinator::{cut, map, map_res, value, opt, verify};
|
||||
use nom::multi::{separated_list, separated_nonempty_list, many1, many0};
|
||||
use nom::error::{context, VerboseError};
|
||||
use nom::branch::alt;
|
||||
@ -70,7 +70,7 @@ fn number_literal(text: &str) -> ParseResult<ExpressionKind> {
|
||||
|
||||
|
||||
fn binary_literal(input: &str) -> ParseResult<ExpressionKind> {
|
||||
let p = preceded(tag("0b"), take_while1(|c: char| c == '0' || c == '1'));
|
||||
let p = preceded(tag("0b"), cut(take_while1(|c: char| c == '0' || c == '1')));
|
||||
let (rest, n): (&str, u64) = map_res(
|
||||
p, |hex_str: &str| u64::from_str_radix(hex_str, 2)
|
||||
)(input)?;
|
||||
@ -79,7 +79,7 @@ fn binary_literal(input: &str) -> ParseResult<ExpressionKind> {
|
||||
}
|
||||
|
||||
fn hex_literal(input: &str) -> ParseResult<ExpressionKind> {
|
||||
let p = preceded(tag("0x"), take_while1(|c: char| c.is_digit(16)));
|
||||
let p = preceded(tag("0x"), cut(take_while1(|c: char| c.is_digit(16))));
|
||||
let (rest, n): (&str, u64) = map_res(
|
||||
p, |hex_str: &str| u64::from_str_radix(hex_str, 16)
|
||||
)(input)?;
|
||||
@ -102,7 +102,7 @@ fn literal(input: &str) -> ParseResult<ExpressionKind> {
|
||||
hex_literal,
|
||||
binary_literal,
|
||||
number_literal,
|
||||
bool_literal
|
||||
bool_literal,
|
||||
))(input)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user