From 1b36e0d29b81a9ca392cbb0386a9dc1f9a44c49d Mon Sep 17 00:00:00 2001 From: dalance Date: Thu, 28 Jan 2021 11:55:28 +0900 Subject: [PATCH] Fix constant_expression_ternary priority #30 --- CHANGELOG.md | 2 ++ sv-parser-parser/src/expressions/expressions.rs | 2 +- sv-parser-parser/src/tests.rs | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2ce661..7a25532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.10.5...Unreleased) - ReleaseDate +* [Fixed] constant_expression_ternary priority [#30](https://github.com/dalance/sv-parser/issues/30) + ## [v0.10.5](https://github.com/dalance/sv-parser/compare/v0.10.4...v0.10.5) - 2021-01-19 * [Fixed] missing comment after macro name [#29](https://github.com/dalance/sv-parser/issues/29) diff --git a/sv-parser-parser/src/expressions/expressions.rs b/sv-parser-parser/src/expressions/expressions.rs index 95244b1..f687525 100644 --- a/sv-parser-parser/src/expressions/expressions.rs +++ b/sv-parser-parser/src/expressions/expressions.rs @@ -78,8 +78,8 @@ pub(crate) fn expression_or_cond_pattern_ternary( #[packrat_parser] pub(crate) fn constant_expression(s: Span) -> IResult { alt(( - constant_expression_binary, constant_expression_ternary, + constant_expression_binary, constant_expression_unary, map(constant_primary, |x| { ConstantExpression::ConstantPrimary(Box::new(x)) diff --git a/sv-parser-parser/src/tests.rs b/sv-parser-parser/src/tests.rs index d8308df..3f4678b 100644 --- a/sv-parser-parser/src/tests.rs +++ b/sv-parser-parser/src/tests.rs @@ -457,6 +457,11 @@ mod unit { `end_keywords"##, Ok((_, _)) ); + test!( + source_text, + r##"module a; localparam a = (A == 1) ? 1 - 1 : (A == 1) ? 1 - 1 : 1 - 1; endmodule"##, + Ok((_, _)) + ); } } @@ -15930,7 +15935,7 @@ mod error { fn debug() { test!( source_text, - r##"module a; always begin a = b.c'(0); end endmodule"##, + r##"module a; localparam a = (A == 1) ? 1 - 1 : (A == 1) ? 1 - 1 : 1 - 1; endmodule"##, Ok((_, _)) ); nom_tracable::cumulative_histogram();