Fix parse error of cast
This commit is contained in:
parent
782f120b4a
commit
1e281dcc35
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.6.1...Unreleased) - ReleaseDate
|
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.6.1...Unreleased) - ReleaseDate
|
||||||
|
|
||||||
|
* [Fixed] parse error of cast
|
||||||
|
|
||||||
## [v0.6.1](https://github.com/dalance/sv-parser/compare/v0.6.0...v0.6.1) - 2020-02-09
|
## [v0.6.1](https://github.com/dalance/sv-parser/compare/v0.6.0...v0.6.1) - 2020-02-09
|
||||||
|
|
||||||
* [Changed] update str-concat
|
* [Changed] update str-concat
|
||||||
|
@ -12,7 +12,23 @@ pub(crate) fn casting_type(s: Span) -> IResult<Span, CastingType> {
|
|||||||
map(signing, |x| CastingType::Signing(Box::new(x))),
|
map(signing, |x| CastingType::Signing(Box::new(x))),
|
||||||
map(keyword("string"), |x| CastingType::String(Box::new(x))),
|
map(keyword("string"), |x| CastingType::String(Box::new(x))),
|
||||||
map(keyword("const"), |x| CastingType::Const(Box::new(x))),
|
map(keyword("const"), |x| CastingType::Const(Box::new(x))),
|
||||||
map(constant_primary, |x| {
|
map(constant_primary_without_cast, |x| {
|
||||||
|
CastingType::ConstantPrimary(Box::new(x))
|
||||||
|
}),
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[recursive_parser]
|
||||||
|
#[packrat_parser]
|
||||||
|
#[tracable_parser]
|
||||||
|
#[packrat_parser]
|
||||||
|
pub(crate) fn constant_casting_type(s: Span) -> IResult<Span, CastingType> {
|
||||||
|
alt((
|
||||||
|
map(simple_type, |x| CastingType::SimpleType(Box::new(x))),
|
||||||
|
map(signing, |x| CastingType::Signing(Box::new(x))),
|
||||||
|
map(keyword("string"), |x| CastingType::String(Box::new(x))),
|
||||||
|
map(keyword("const"), |x| CastingType::Const(Box::new(x))),
|
||||||
|
map(constant_primary_without_cast, |x| {
|
||||||
CastingType::ConstantPrimary(Box::new(x))
|
CastingType::ConstantPrimary(Box::new(x))
|
||||||
}),
|
}),
|
||||||
))(s)
|
))(s)
|
||||||
|
@ -41,6 +41,42 @@ pub(crate) fn constant_primary(s: Span) -> IResult<Span, ConstantPrimary> {
|
|||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracable_parser]
|
||||||
|
#[packrat_parser]
|
||||||
|
pub(crate) fn constant_primary_without_cast(s: Span) -> IResult<Span, ConstantPrimary> {
|
||||||
|
alt((
|
||||||
|
// BNF-WA
|
||||||
|
map(keyword("$"), |x| ConstantPrimary::Dollar(Box::new(x))),
|
||||||
|
map(keyword("null"), |x| ConstantPrimary::Null(Box::new(x))),
|
||||||
|
map(constant_assignment_pattern_expression, |x| {
|
||||||
|
ConstantPrimary::ConstantAssignmentPatternExpression(Box::new(x))
|
||||||
|
}),
|
||||||
|
map(primary_literal, |x| {
|
||||||
|
ConstantPrimary::PrimaryLiteral(Box::new(x))
|
||||||
|
}),
|
||||||
|
constant_primary_mintypmax_expression,
|
||||||
|
map(
|
||||||
|
terminated(constant_function_call, peek(not(one_of("[.")))),
|
||||||
|
|x| ConstantPrimary::ConstantFunctionCall(Box::new(x)),
|
||||||
|
),
|
||||||
|
constant_primary_ps_parameter,
|
||||||
|
constant_primary_specparam,
|
||||||
|
map(genvar_identifier, |x| {
|
||||||
|
ConstantPrimary::GenvarIdentifier(Box::new(x))
|
||||||
|
}),
|
||||||
|
constant_primary_formal_port,
|
||||||
|
constant_primary_enum,
|
||||||
|
constant_primary_concatenation,
|
||||||
|
constant_primary_multiple_concatenation,
|
||||||
|
map(constant_let_expression, |x| {
|
||||||
|
ConstantPrimary::ConstantLetExpression(Box::new(x))
|
||||||
|
}),
|
||||||
|
map(type_reference, |x| {
|
||||||
|
ConstantPrimary::TypeReference(Box::new(x))
|
||||||
|
}),
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
#[tracable_parser]
|
#[tracable_parser]
|
||||||
#[packrat_parser]
|
#[packrat_parser]
|
||||||
pub(crate) fn constant_primary_ps_parameter(s: Span) -> IResult<Span, ConstantPrimary> {
|
pub(crate) fn constant_primary_ps_parameter(s: Span) -> IResult<Span, ConstantPrimary> {
|
||||||
@ -402,7 +438,7 @@ pub(crate) fn constant_select(s: Span) -> IResult<Span, ConstantSelect> {
|
|||||||
#[tracable_parser]
|
#[tracable_parser]
|
||||||
#[packrat_parser]
|
#[packrat_parser]
|
||||||
pub(crate) fn constant_cast(s: Span) -> IResult<Span, ConstantCast> {
|
pub(crate) fn constant_cast(s: Span) -> IResult<Span, ConstantCast> {
|
||||||
let (s, a) = casting_type(s)?;
|
let (s, a) = constant_casting_type(s)?;
|
||||||
let (s, b) = symbol("'")(s)?;
|
let (s, b) = symbol("'")(s)?;
|
||||||
let (s, c) = paren(constant_expression)(s)?;
|
let (s, c) = paren(constant_expression)(s)?;
|
||||||
Ok((s, ConstantCast { nodes: (a, b, c) }))
|
Ok((s, ConstantCast { nodes: (a, b, c) }))
|
||||||
|
@ -418,6 +418,11 @@ mod unit {
|
|||||||
r##"module test(); specify $setup(posedge CSB, edge[01,0x,x1,1x] CL, tps, a); endspecify endmodule"##,
|
r##"module test(); specify $setup(posedge CSB, edge[01,0x,x1,1x] CL, tps, a); endspecify endmodule"##,
|
||||||
Ok((_, _))
|
Ok((_, _))
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
source_text,
|
||||||
|
r##"module a; assign a = a[$clog2(a)'(a)]; endmodule"##,
|
||||||
|
Ok((_, _))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15876,10 +15881,6 @@ mod spec {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn debug() {
|
fn debug() {
|
||||||
test!(
|
test!(expression, r##"a[$clog2(a)'(a)]"##, Ok((_, _)));
|
||||||
source_text,
|
|
||||||
r##"module a; initial begin #1 ps[idx] = 1'b1; end endmodule"##,
|
|
||||||
Ok((_, _))
|
|
||||||
);
|
|
||||||
nom_tracable::cumulative_histogram();
|
nom_tracable::cumulative_histogram();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user