Fix time_literal spacing

This commit is contained in:
dalance 2020-01-22 19:21:00 +09:00
parent 6e887e22c7
commit c965a038d8
6 changed files with 44 additions and 9 deletions

View File

@ -2,6 +2,8 @@
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.4.19...Unreleased) - ReleaseDate ## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.4.19...Unreleased) - ReleaseDate
* [Fixed] time_literal spacing
## [v0.4.19](https://github.com/dalance/sv-parser/compare/v0.4.18...v0.4.19) - 2019-12-12 ## [v0.4.19](https://github.com/dalance/sv-parser/compare/v0.4.18...v0.4.19) - 2019-12-12
* [Added] include line check * [Added] include line check

View File

@ -185,6 +185,17 @@ pub(crate) fn fixed_point_number(s: Span) -> IResult<Span, FixedPointNumber> {
Ok((s, FixedPointNumber { nodes: (a, b, c) })) Ok((s, FixedPointNumber { nodes: (a, b, c) }))
} }
#[tracable_parser]
#[packrat_parser]
pub(crate) fn fixed_point_number_exact(s: Span) -> IResult<Span, FixedPointNumber> {
let (s, a) = unsigned_number_without_ws(s)?;
let (s, b) = map(tag("."), |x: Span| Symbol {
nodes: (into_locate(x), vec![]),
})(s)?;
let (s, c) = unsigned_number_exact(s)?;
Ok((s, FixedPointNumber { nodes: (a, b, c) }))
}
#[tracable_parser] #[tracable_parser]
#[packrat_parser] #[packrat_parser]
pub(crate) fn exp(s: Span) -> IResult<Span, Exp> { pub(crate) fn exp(s: Span) -> IResult<Span, Exp> {
@ -213,6 +224,13 @@ pub(crate) fn unsigned_number(s: Span) -> IResult<Span, UnsignedNumber> {
Ok((s, UnsignedNumber { nodes: a })) Ok((s, UnsignedNumber { nodes: a }))
} }
#[tracable_parser]
#[packrat_parser]
pub(crate) fn unsigned_number_exact(s: Span) -> IResult<Span, UnsignedNumber> {
let (s, a) = no_ws(unsigned_number_impl)(s)?;
Ok((s, UnsignedNumber { nodes: a }))
}
#[tracable_parser] #[tracable_parser]
pub(crate) fn unsigned_number_impl(s: Span) -> IResult<Span, Locate> { pub(crate) fn unsigned_number_impl(s: Span) -> IResult<Span, Locate> {
let (s, a) = digit1(s)?; let (s, a) = digit1(s)?;

View File

@ -293,7 +293,7 @@ pub(crate) fn time_literal(s: Span) -> IResult<Span, TimeLiteral> {
#[tracable_parser] #[tracable_parser]
#[packrat_parser] #[packrat_parser]
pub(crate) fn time_literal_unsigned(s: Span) -> IResult<Span, TimeLiteral> { pub(crate) fn time_literal_unsigned(s: Span) -> IResult<Span, TimeLiteral> {
let (s, a) = unsigned_number(s)?; let (s, a) = unsigned_number_exact(s)?;
let (s, b) = time_unit(s)?; let (s, b) = time_unit(s)?;
Ok(( Ok((
s, s,
@ -304,7 +304,7 @@ pub(crate) fn time_literal_unsigned(s: Span) -> IResult<Span, TimeLiteral> {
#[tracable_parser] #[tracable_parser]
#[packrat_parser] #[packrat_parser]
pub(crate) fn time_literal_fixed_point(s: Span) -> IResult<Span, TimeLiteral> { pub(crate) fn time_literal_fixed_point(s: Span) -> IResult<Span, TimeLiteral> {
let (s, a) = fixed_point_number(s)?; let (s, a) = fixed_point_number_exact(s)?;
let (s, b) = time_unit(s)?; let (s, b) = time_unit(s)?;
Ok(( Ok((
s, s,

View File

@ -585,13 +585,15 @@ pub(crate) fn source_description_not_directive(s: Span) -> IResult<Span, SourceD
pub(crate) fn timescale_compiler_directive(s: Span) -> IResult<Span, TimescaleCompilerDirective> { pub(crate) fn timescale_compiler_directive(s: Span) -> IResult<Span, TimescaleCompilerDirective> {
let (s, a) = symbol("`")(s)?; let (s, a) = symbol("`")(s)?;
let (s, b) = keyword("timescale")(s)?; let (s, b) = keyword("timescale")(s)?;
let (s, c) = time_literal(s)?; let (s, c) = unsigned_number(s)?;
let (s, d) = symbol("/")(s)?; let (s, d) = time_unit(s)?;
let (s, e) = time_literal(s)?; let (s, e) = symbol("/")(s)?;
let (s, f) = unsigned_number(s)?;
let (s, g) = time_unit(s)?;
Ok(( Ok((
s, s,
TimescaleCompilerDirective { TimescaleCompilerDirective {
nodes: (a, b, c, d, e), nodes: (a, b, c, d, e, f, g),
}, },
)) ))
} }

View File

@ -398,6 +398,11 @@ mod unit {
r##"module A; always begin a[ a_a[i] ].b <= c; end endmodule"##, r##"module A; always begin a[ a_a[i] ].b <= c; end endmodule"##,
Ok((_, _)) Ok((_, _))
); );
test!(
source_text,
r##"module a; initial begin #1 ps[idx] = 1'b1; end endmodule"##,
Ok((_, _))
);
} }
} }
@ -609,7 +614,7 @@ mod spec {
test!(number, "4.E3", Err(_)); test!(number, "4.E3", Err(_));
test!(number, ".2e-7", Err(_)); test!(number, ".2e-7", Err(_));
test!(primary, "2.1ns ", Ok((_, Primary::PrimaryLiteral(_)))); test!(primary, "2.1ns ", Ok((_, Primary::PrimaryLiteral(_))));
test!(primary, "40 ps ", Ok((_, Primary::PrimaryLiteral(_)))); test!(primary, "40ps ", Ok((_, Primary::PrimaryLiteral(_))));
test!( test!(
subroutine_call_statement, subroutine_call_statement,
r##"$display("Humpty Dumpty sat on a wall. \ r##"$display("Humpty Dumpty sat on a wall. \
@ -15858,7 +15863,7 @@ mod spec {
fn debug() { fn debug() {
test!( test!(
source_text, source_text,
r##"module A; always begin a[ a_a[i] ].b <= c; end endmodule"##, r##"module a; initial begin #1 ps[idx] = 1'b1; end endmodule"##,
Ok((_, _)) Ok((_, _))
); );
nom_tracable::cumulative_histogram(); nom_tracable::cumulative_histogram();

View File

@ -189,7 +189,15 @@ pub struct SourceDescriptionNotDirective {
#[derive(Clone, Debug, PartialEq, Node)] #[derive(Clone, Debug, PartialEq, Node)]
pub struct TimescaleCompilerDirective { pub struct TimescaleCompilerDirective {
pub nodes: (Symbol, Keyword, TimeLiteral, Symbol, TimeLiteral), pub nodes: (
Symbol,
Keyword,
UnsignedNumber,
TimeUnit,
Symbol,
UnsignedNumber,
TimeUnit,
),
} }
#[derive(Clone, Debug, PartialEq, Node)] #[derive(Clone, Debug, PartialEq, Node)]