This commit is contained in:
dalance 2019-11-06 15:11:59 +09:00
parent b08195b68a
commit 71644e960f
6 changed files with 43 additions and 3 deletions

View File

@ -6,6 +6,8 @@
* [Fixed] randomize_call bug * [Fixed] randomize_call bug
* [Fixed] parameter override by class type bug * [Fixed] parameter override by class type bug
* [Fixed] hierarchical this 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 ## [v0.3.6](https://github.com/dalance/sv-parser/compare/v0.3.5...v0.3.6) - 2019-11-05

View File

@ -70,6 +70,10 @@ pub(crate) fn delay_value(s: Span) -> IResult<Span, DelayValue> {
map(time_literal, |x| DelayValue::TimeLiteral(Box::new(x))), map(time_literal, |x| DelayValue::TimeLiteral(Box::new(x))),
map(real_number, |x| DelayValue::RealNumber(Box::new(x))), map(real_number, |x| DelayValue::RealNumber(Box::new(x))),
map(unsigned_number, |x| DelayValue::UnsignedNumber(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))), map(ps_identifier, |x| DelayValue::PsIdentifier(Box::new(x))),
))(s) ))(s)
} }

View File

@ -100,7 +100,9 @@ pub(crate) fn class_property_const(s: Span) -> IResult<Span, ClassProperty> {
let (s, b) = many0(class_item_qualifier)(s)?; let (s, b) = many0(class_item_qualifier)(s)?;
let (s, c) = data_type(s)?; let (s, c) = data_type(s)?;
let (s, d) = const_identifier(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)?; let (s, f) = symbol(";")(s)?;
Ok(( Ok((
s, s,
@ -110,6 +112,21 @@ pub(crate) fn class_property_const(s: Span) -> IResult<Span, ClassProperty> {
)) ))
} }
#[tracable_parser]
#[packrat_parser]
pub(crate) fn class_property_const_expression(
s: Span,
) -> IResult<Span, ClassPropertyConstExpression> {
alt((
map(constant_expression, |x| {
ClassPropertyConstExpression::ConstantExpression(Box::new(x))
}),
map(class_new, |x| {
ClassPropertyConstExpression::ClassNew(Box::new(x))
}),
))(s)
}
#[tracable_parser] #[tracable_parser]
#[packrat_parser] #[packrat_parser]
pub(crate) fn class_method(s: Span) -> IResult<Span, ClassMethod> { pub(crate) fn class_method(s: Span) -> IResult<Span, ClassMethod> {

View File

@ -378,6 +378,16 @@ mod unit {
r##"class a; function a b(); return this.a.b(); endfunction endclass"##, r##"class a; function a b(); return this.a.b(); endfunction endclass"##,
Ok((_, _)) 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() { fn debug() {
test!( test!(
source_text, source_text,
r##"module a; initial begin this.a.b(); end endmodule"##, r##"module a; initial begin #a.b; end endmodule"##,
Ok((_, _)) Ok((_, _))
); );
nom_tracable::cumulative_histogram(); nom_tracable::cumulative_histogram();

View File

@ -52,6 +52,7 @@ pub enum DelayValue {
UnsignedNumber(Box<UnsignedNumber>), UnsignedNumber(Box<UnsignedNumber>),
RealNumber(Box<RealNumber>), RealNumber(Box<RealNumber>),
PsIdentifier(Box<PsIdentifier>), PsIdentifier(Box<PsIdentifier>),
HierarchicalIdentifier(Box<HierarchicalIdentifier>),
TimeLiteral(Box<TimeLiteral>), TimeLiteral(Box<TimeLiteral>),
Step1(Box<Keyword>), Step1(Box<Keyword>),
} }

View File

@ -57,11 +57,17 @@ pub struct ClassPropertyConst {
Vec<ClassItemQualifier>, Vec<ClassItemQualifier>,
DataType, DataType,
ConstIdentifier, ConstIdentifier,
Option<(Symbol, ConstantExpression)>, Option<(Symbol, ClassPropertyConstExpression)>,
Symbol, Symbol,
), ),
} }
#[derive(Clone, Debug, PartialEq, Node)]
pub enum ClassPropertyConstExpression {
ConstantExpression(Box<ConstantExpression>),
ClassNew(Box<ClassNew>),
}
#[derive(Clone, Debug, PartialEq, Node)] #[derive(Clone, Debug, PartialEq, Node)]
pub enum ClassMethod { pub enum ClassMethod {
Task(Box<ClassMethodTask>), Task(Box<ClassMethodTask>),