From 31da29c3248fa1ce32ecc711f055d85c8db32c11 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 7 Mar 2020 03:54:49 -0800 Subject: [PATCH] Fix 0x, 0b literals --- schala-lang/language/src/parser.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/schala-lang/language/src/parser.rs b/schala-lang/language/src/parser.rs index 6ec0eb0..1b71802 100644 --- a/schala-lang/language/src/parser.rs +++ b/schala-lang/language/src/parser.rs @@ -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 { fn binary_literal(input: &str) -> ParseResult { - 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 { } fn hex_literal(input: &str) -> ParseResult { - 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 { hex_literal, binary_literal, number_literal, - bool_literal + bool_literal, ))(input) }