From d3d090c3d4a366575c62ec2297f0faaef4a6eec6 Mon Sep 17 00:00:00 2001 From: dalance Date: Wed, 22 Jan 2020 19:23:04 +0900 Subject: [PATCH] Fix escaped_identifier --- CHANGELOG.md | 1 + .../src/general/compiler_directives.rs | 5 ++++- sv-parser-parser/src/tests.rs | 5 +++++ sv-parser-pp/src/preprocess.rs | 20 +++++++++++++++++++ sv-parser-pp/testcases/test12.sv | 3 +++ .../src/general/compiler_directives.rs | 1 + 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 sv-parser-pp/testcases/test12.sv diff --git a/CHANGELOG.md b/CHANGELOG.md index 2da4f48..88c72b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.4.19...Unreleased) - ReleaseDate +* [Fixed] escaped_ideitifier including `` ` `` * [Fixed] time_literal spacing ## [v0.4.19](https://github.com/dalance/sv-parser/compare/v0.4.18...v0.4.19) - 2019-12-12 diff --git a/sv-parser-parser/src/general/compiler_directives.rs b/sv-parser-parser/src/general/compiler_directives.rs index 6a2d1f2..eaf4770 100644 --- a/sv-parser-parser/src/general/compiler_directives.rs +++ b/sv-parser-parser/src/general/compiler_directives.rs @@ -548,6 +548,9 @@ pub(crate) fn source_description(s: Span) -> IResult { map(string_literal, |x| { SourceDescription::StringLiteral(Box::new(x)) }), + map(escaped_identifier, |x| { + SourceDescription::EscapedIdentifier(Box::new(x)) + }), source_description_not_directive, map(compiler_directive, |x| { SourceDescription::CompilerDirective(Box::new(x)) @@ -559,7 +562,7 @@ pub(crate) fn source_description(s: Span) -> IResult { #[packrat_parser] pub(crate) fn source_description_not_directive(s: Span) -> IResult { let (s, a) = many1(alt(( - is_not("`/\""), + is_not("`/\"\\"), terminated(tag("/"), peek(not(alt((tag("/"), tag("*")))))), )))(s)?; diff --git a/sv-parser-parser/src/tests.rs b/sv-parser-parser/src/tests.rs index a26301b..13519cf 100644 --- a/sv-parser-parser/src/tests.rs +++ b/sv-parser-parser/src/tests.rs @@ -403,6 +403,11 @@ mod unit { r##"module a; initial begin #1 ps[idx] = 1'b1; end endmodule"##, Ok((_, _)) ); + test!( + source_text, + r##"module a; reg \`~!-_=+\|[]{};:'"",./<>? ; endmodule"##, + Ok((_, _)) + ); } } diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index 869e157..af0e1d8 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -234,6 +234,13 @@ pub fn preprocess_str, U: AsRef>( let range = Range::new(locate.offset, locate.offset + locate.len); ret.push(locate.str(&s), Some((path.as_ref(), range))); } + NodeEvent::Enter(RefNode::SourceDescription(SourceDescription::EscapedIdentifier( + x, + ))) if !skip => { + let locate: Locate = (&**x).try_into().unwrap(); + let range = Range::new(locate.offset, locate.offset + locate.len); + ret.push(locate.str(&s), Some((path.as_ref(), range))); + } NodeEvent::Enter(RefNode::KeywordsDirective(x)) if !skip => { let locate: Locate = x.try_into().unwrap(); let range = Range::new(locate.offset, locate.offset + locate.len); @@ -785,4 +792,17 @@ endmodule "Err(Error { inner: \n\nInclude line can\'t have other items })" ); } + + #[test] + fn test12() { + let (ret, _) = + preprocess(get_testcase("test12.sv"), &HashMap::new(), &[] as &[String]).unwrap(); + assert_eq!( + ret.text(), + r##"module a; +reg \`~!-_=+\|[]{};:'"",./<>? ; +endmodule +"## + ); + } } diff --git a/sv-parser-pp/testcases/test12.sv b/sv-parser-pp/testcases/test12.sv new file mode 100644 index 0000000..4f2d653 --- /dev/null +++ b/sv-parser-pp/testcases/test12.sv @@ -0,0 +1,3 @@ +module a; +reg \`~!-_=+\|[]{};:'"",./<>? ; +endmodule diff --git a/sv-parser-syntaxtree/src/general/compiler_directives.rs b/sv-parser-syntaxtree/src/general/compiler_directives.rs index 40f2990..e0c7c26 100644 --- a/sv-parser-syntaxtree/src/general/compiler_directives.rs +++ b/sv-parser-syntaxtree/src/general/compiler_directives.rs @@ -180,6 +180,7 @@ pub enum SourceDescription { StringLiteral(Box), NotDirective(Box), CompilerDirective(Box), + EscapedIdentifier(Box), } #[derive(Clone, Debug, PartialEq, Node)]