From 71644e960fbc23cabb66dd8ebd93b4666beb9503 Mon Sep 17 00:00:00 2001 From: dalance Date: Wed, 6 Nov 2019 15:11:59 +0900 Subject: [PATCH] Fix bugs --- CHANGELOG.md | 2 ++ sv-parser-parser/src/declarations/delays.rs | 4 ++++ .../src/source_text/class_items.rs | 19 ++++++++++++++++++- sv-parser-parser/src/tests.rs | 12 +++++++++++- .../src/declarations/delays.rs | 1 + .../src/source_text/class_items.rs | 8 +++++++- 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02cb917..a89c881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * [Fixed] randomize_call bug * [Fixed] parameter override by class type bug * [Fixed] hierarchical this bug +* [Fixed] hierarchical delay value bug +* [Fixed] const class new bug ## [v0.3.6](https://github.com/dalance/sv-parser/compare/v0.3.5...v0.3.6) - 2019-11-05 diff --git a/sv-parser-parser/src/declarations/delays.rs b/sv-parser-parser/src/declarations/delays.rs index d287fb7..bd7fb2d 100644 --- a/sv-parser-parser/src/declarations/delays.rs +++ b/sv-parser-parser/src/declarations/delays.rs @@ -70,6 +70,10 @@ pub(crate) fn delay_value(s: Span) -> IResult { map(time_literal, |x| DelayValue::TimeLiteral(Box::new(x))), map(real_number, |x| DelayValue::RealNumber(Box::new(x))), map(unsigned_number, |x| DelayValue::UnsignedNumber(Box::new(x))), + // BNF-WA + map(hierarchical_identifier, |x| { + DelayValue::HierarchicalIdentifier(Box::new(x)) + }), map(ps_identifier, |x| DelayValue::PsIdentifier(Box::new(x))), ))(s) } diff --git a/sv-parser-parser/src/source_text/class_items.rs b/sv-parser-parser/src/source_text/class_items.rs index d6b092d..47a77f4 100644 --- a/sv-parser-parser/src/source_text/class_items.rs +++ b/sv-parser-parser/src/source_text/class_items.rs @@ -100,7 +100,9 @@ pub(crate) fn class_property_const(s: Span) -> IResult { let (s, b) = many0(class_item_qualifier)(s)?; let (s, c) = data_type(s)?; let (s, d) = const_identifier(s)?; - let (s, e) = opt(pair(symbol("="), constant_expression))(s)?; + // BNF-WA + //let (s, e) = opt(pair(symbol("="), constant_expression))(s)?; + let (s, e) = opt(pair(symbol("="), class_property_const_expression))(s)?; let (s, f) = symbol(";")(s)?; Ok(( s, @@ -110,6 +112,21 @@ pub(crate) fn class_property_const(s: Span) -> IResult { )) } +#[tracable_parser] +#[packrat_parser] +pub(crate) fn class_property_const_expression( + s: Span, +) -> IResult { + alt(( + map(constant_expression, |x| { + ClassPropertyConstExpression::ConstantExpression(Box::new(x)) + }), + map(class_new, |x| { + ClassPropertyConstExpression::ClassNew(Box::new(x)) + }), + ))(s) +} + #[tracable_parser] #[packrat_parser] pub(crate) fn class_method(s: Span) -> IResult { diff --git a/sv-parser-parser/src/tests.rs b/sv-parser-parser/src/tests.rs index b596d26..e56e604 100644 --- a/sv-parser-parser/src/tests.rs +++ b/sv-parser-parser/src/tests.rs @@ -378,6 +378,16 @@ mod unit { r##"class a; function a b(); return this.a.b(); endfunction endclass"##, Ok((_, _)) ); + test!( + source_text, + r##"class a; const local a b = new("a"); endclass"##, + Ok((_, _)) + ); + test!( + source_text, + r##"module a; initial begin #a.b; end endmodule"##, + Ok((_, _)) + ); } } @@ -15838,7 +15848,7 @@ mod spec { fn debug() { test!( source_text, - r##"module a; initial begin this.a.b(); end endmodule"##, + r##"module a; initial begin #a.b; end endmodule"##, Ok((_, _)) ); nom_tracable::cumulative_histogram(); diff --git a/sv-parser-syntaxtree/src/declarations/delays.rs b/sv-parser-syntaxtree/src/declarations/delays.rs index d8af2d4..3b14748 100644 --- a/sv-parser-syntaxtree/src/declarations/delays.rs +++ b/sv-parser-syntaxtree/src/declarations/delays.rs @@ -52,6 +52,7 @@ pub enum DelayValue { UnsignedNumber(Box), RealNumber(Box), PsIdentifier(Box), + HierarchicalIdentifier(Box), TimeLiteral(Box), Step1(Box), } diff --git a/sv-parser-syntaxtree/src/source_text/class_items.rs b/sv-parser-syntaxtree/src/source_text/class_items.rs index 42bb59c..a7af17f 100644 --- a/sv-parser-syntaxtree/src/source_text/class_items.rs +++ b/sv-parser-syntaxtree/src/source_text/class_items.rs @@ -57,11 +57,17 @@ pub struct ClassPropertyConst { Vec, DataType, ConstIdentifier, - Option<(Symbol, ConstantExpression)>, + Option<(Symbol, ClassPropertyConstExpression)>, Symbol, ), } +#[derive(Clone, Debug, PartialEq, Node)] +pub enum ClassPropertyConstExpression { + ConstantExpression(Box), + ClassNew(Box), +} + #[derive(Clone, Debug, PartialEq, Node)] pub enum ClassMethod { Task(Box),