From c965a038d889dd17a296eaf076caf14354997e81 Mon Sep 17 00:00:00 2001 From: dalance Date: Wed, 22 Jan 2020 19:21:00 +0900 Subject: [PATCH] Fix time_literal spacing --- CHANGELOG.md | 2 ++ sv-parser-parser/src/expressions/numbers.rs | 18 ++++++++++++++++++ sv-parser-parser/src/expressions/primaries.rs | 4 ++-- .../src/general/compiler_directives.rs | 10 ++++++---- sv-parser-parser/src/tests.rs | 9 +++++++-- .../src/general/compiler_directives.rs | 10 +++++++++- 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a84807a..2da4f48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [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 * [Added] include line check diff --git a/sv-parser-parser/src/expressions/numbers.rs b/sv-parser-parser/src/expressions/numbers.rs index f7a3807..03eb149 100644 --- a/sv-parser-parser/src/expressions/numbers.rs +++ b/sv-parser-parser/src/expressions/numbers.rs @@ -185,6 +185,17 @@ pub(crate) fn fixed_point_number(s: Span) -> IResult { Ok((s, FixedPointNumber { nodes: (a, b, c) })) } +#[tracable_parser] +#[packrat_parser] +pub(crate) fn fixed_point_number_exact(s: Span) -> IResult { + 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] #[packrat_parser] pub(crate) fn exp(s: Span) -> IResult { @@ -213,6 +224,13 @@ pub(crate) fn unsigned_number(s: Span) -> IResult { Ok((s, UnsignedNumber { nodes: a })) } +#[tracable_parser] +#[packrat_parser] +pub(crate) fn unsigned_number_exact(s: Span) -> IResult { + let (s, a) = no_ws(unsigned_number_impl)(s)?; + Ok((s, UnsignedNumber { nodes: a })) +} + #[tracable_parser] pub(crate) fn unsigned_number_impl(s: Span) -> IResult { let (s, a) = digit1(s)?; diff --git a/sv-parser-parser/src/expressions/primaries.rs b/sv-parser-parser/src/expressions/primaries.rs index a307d28..1ad2819 100644 --- a/sv-parser-parser/src/expressions/primaries.rs +++ b/sv-parser-parser/src/expressions/primaries.rs @@ -293,7 +293,7 @@ pub(crate) fn time_literal(s: Span) -> IResult { #[tracable_parser] #[packrat_parser] pub(crate) fn time_literal_unsigned(s: Span) -> IResult { - let (s, a) = unsigned_number(s)?; + let (s, a) = unsigned_number_exact(s)?; let (s, b) = time_unit(s)?; Ok(( s, @@ -304,7 +304,7 @@ pub(crate) fn time_literal_unsigned(s: Span) -> IResult { #[tracable_parser] #[packrat_parser] pub(crate) fn time_literal_fixed_point(s: Span) -> IResult { - let (s, a) = fixed_point_number(s)?; + let (s, a) = fixed_point_number_exact(s)?; let (s, b) = time_unit(s)?; Ok(( s, diff --git a/sv-parser-parser/src/general/compiler_directives.rs b/sv-parser-parser/src/general/compiler_directives.rs index 8234fbd..6a2d1f2 100644 --- a/sv-parser-parser/src/general/compiler_directives.rs +++ b/sv-parser-parser/src/general/compiler_directives.rs @@ -585,13 +585,15 @@ pub(crate) fn source_description_not_directive(s: Span) -> IResult IResult { let (s, a) = symbol("`")(s)?; let (s, b) = keyword("timescale")(s)?; - let (s, c) = time_literal(s)?; - let (s, d) = symbol("/")(s)?; - let (s, e) = time_literal(s)?; + let (s, c) = unsigned_number(s)?; + let (s, d) = time_unit(s)?; + let (s, e) = symbol("/")(s)?; + let (s, f) = unsigned_number(s)?; + let (s, g) = time_unit(s)?; Ok(( s, TimescaleCompilerDirective { - nodes: (a, b, c, d, e), + nodes: (a, b, c, d, e, f, g), }, )) } diff --git a/sv-parser-parser/src/tests.rs b/sv-parser-parser/src/tests.rs index 71ec1d8..a26301b 100644 --- a/sv-parser-parser/src/tests.rs +++ b/sv-parser-parser/src/tests.rs @@ -398,6 +398,11 @@ mod unit { r##"module A; always begin a[ a_a[i] ].b <= c; end endmodule"##, 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, ".2e-7", Err(_)); test!(primary, "2.1ns ", Ok((_, Primary::PrimaryLiteral(_)))); - test!(primary, "40 ps ", Ok((_, Primary::PrimaryLiteral(_)))); + test!(primary, "40ps ", Ok((_, Primary::PrimaryLiteral(_)))); test!( subroutine_call_statement, r##"$display("Humpty Dumpty sat on a wall. \ @@ -15858,7 +15863,7 @@ mod spec { fn debug() { test!( 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((_, _)) ); nom_tracable::cumulative_histogram(); diff --git a/sv-parser-syntaxtree/src/general/compiler_directives.rs b/sv-parser-syntaxtree/src/general/compiler_directives.rs index 4d91b52..40f2990 100644 --- a/sv-parser-syntaxtree/src/general/compiler_directives.rs +++ b/sv-parser-syntaxtree/src/general/compiler_directives.rs @@ -189,7 +189,15 @@ pub struct SourceDescriptionNotDirective { #[derive(Clone, Debug, PartialEq, Node)] pub struct TimescaleCompilerDirective { - pub nodes: (Symbol, Keyword, TimeLiteral, Symbol, TimeLiteral), + pub nodes: ( + Symbol, + Keyword, + UnsignedNumber, + TimeUnit, + Symbol, + UnsignedNumber, + TimeUnit, + ), } #[derive(Clone, Debug, PartialEq, Node)]