From 9c0f60b6ce3de54b25bc7380c3aaa69479fd60ad Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 22 Nov 2021 01:52:08 -0800 Subject: [PATCH] Fix more parser bugs --- schala-lang/src/parsing/peg_parser.rs | 12 ++++++------ schala-lang/src/parsing/test.rs | 8 ++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/schala-lang/src/parsing/peg_parser.rs b/schala-lang/src/parsing/peg_parser.rs index bb2ed8c..e81b3dc 100644 --- a/schala-lang/src/parsing/peg_parser.rs +++ b/schala-lang/src/parsing/peg_parser.rs @@ -470,7 +470,7 @@ peg::parser! { bin_literal() / hex_literal() / unmarked_literal() rule unmarked_literal() -> ExpressionKind = - digits:digits() { ExpressionKind::NatLiteral(digits.parse().unwrap()) } + digits:digits() { let n = digits.chars().filter(|ch| *ch != '_').collect::().parse().unwrap(); ExpressionKind::NatLiteral(n) } rule bin_literal() -> ExpressionKind = "0b" digits:bin_digits() {? parse_binary(digits).map(ExpressionKind::NatLiteral) } @@ -482,12 +482,12 @@ peg::parser! { ds:$( digits() "." digits()? / "." digits() ) { ExpressionKind::FloatLiteral(ds.parse().unwrap()) } rule digits() -> &'input str = $((digit_group() "_"*)+) - rule bin_digits() -> &'input str = $((bin_digit_group() "_"*)+) - rule hex_digits() -> &'input str = $((hex_digit_group() "_"*)+) + rule bin_digits() -> &'input str = $((bin_digit_group() "_"*)+) + rule hex_digits() -> &'input str = $((hex_digit_group() "_"*)+) - rule digit_group() -> &'input str = $(['0'..='9']+) - rule bin_digit_group() -> &'input str = $(['0' | '1']+) - rule hex_digit_group() -> &'input str = $(['0'..='9' | 'a'..='f' | 'A'..='F']+) + rule digit_group() -> &'input str = $(['0'..='9']+) + rule bin_digit_group() -> &'input str = $(['0' | '1']+) + rule hex_digit_group() -> &'input str = $(['0'..='9' | 'a'..='f' | 'A'..='F']+) } } diff --git a/schala-lang/src/parsing/test.rs b/schala-lang/src/parsing/test.rs index 21079f3..e23078f 100644 --- a/schala-lang/src/parsing/test.rs +++ b/schala-lang/src/parsing/test.rs @@ -1383,7 +1383,6 @@ fn blocks() { assert_block!("{}", vec![].into()); - //TODO this case is broken in the peg version let source = r#"{ //hella @@ -1391,11 +1390,8 @@ fn blocks() { 11; /*chutney*/0xf }"#; - let mut parser = Parser::new(); - let block = parser.block_comb(source); - - assert_eq!( - block.unwrap(), + assert_block!( + source, vec![ Statement { id: Default::default(),