From 74d637f511ec25b9d74ef175bc0e13fa550991b4 Mon Sep 17 00:00:00 2001 From: dalance Date: Mon, 19 Aug 2019 19:28:51 +0900 Subject: [PATCH] Fix single line comment --- sv-parser-parser/src/general/comments.rs | 8 ++++++-- sv-parser-parser/src/tests.rs | 9 +++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sv-parser-parser/src/general/comments.rs b/sv-parser-parser/src/general/comments.rs index 3f8fd5c..dd63b51 100644 --- a/sv-parser-parser/src/general/comments.rs +++ b/sv-parser-parser/src/general/comments.rs @@ -12,8 +12,12 @@ pub(crate) fn comment(s: Span) -> IResult { #[packrat_parser] pub(crate) fn one_line_comment(s: Span) -> IResult { let (s, a) = tag("//")(s)?; - let (s, b) = is_not("\n")(s)?; - let a = concat(a, b).unwrap(); + let (s, b) = opt(is_not("\n"))(s)?; + let a = if let Some(b) = b { + concat(a, b).unwrap() + } else { + a + }; Ok(( s, Comment { diff --git a/sv-parser-parser/src/tests.rs b/sv-parser-parser/src/tests.rs index d6b9b92..1a932e2 100644 --- a/sv-parser-parser/src/tests.rs +++ b/sv-parser-parser/src/tests.rs @@ -283,6 +283,7 @@ mod unit { #[test] fn test_comment() { test!(comment, "// comment", Ok((_, _))); + test!(comment, "//", Ok((_, _))); test!(comment, "/* comment\n\n */", Ok((_, _))); } @@ -15705,12 +15706,8 @@ mod spec { fn debug() { test!( source_text, - r##"`pragma protect encoding=(enctype="raw") - `pragma protect data_method="x-caesar", data_keyname="rot13", begin - `pragma protect - runtime_license=(library="lic.so",feature="runSecret",entry="chk", match=42) - `pragma protect end - "##, + r##"//aaa + //bbb"##, Ok((_, _)) ); }