Fix escaped_identifier

This commit is contained in:
dalance 2020-01-22 19:23:04 +09:00
parent c965a038d8
commit d3d090c3d4
6 changed files with 34 additions and 1 deletions

View File

@ -2,6 +2,7 @@
## [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] escaped_ideitifier including `` ` ``
* [Fixed] time_literal spacing * [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

View File

@ -548,6 +548,9 @@ pub(crate) fn source_description(s: Span) -> IResult<Span, SourceDescription> {
map(string_literal, |x| { map(string_literal, |x| {
SourceDescription::StringLiteral(Box::new(x)) SourceDescription::StringLiteral(Box::new(x))
}), }),
map(escaped_identifier, |x| {
SourceDescription::EscapedIdentifier(Box::new(x))
}),
source_description_not_directive, source_description_not_directive,
map(compiler_directive, |x| { map(compiler_directive, |x| {
SourceDescription::CompilerDirective(Box::new(x)) SourceDescription::CompilerDirective(Box::new(x))
@ -559,7 +562,7 @@ pub(crate) fn source_description(s: Span) -> IResult<Span, SourceDescription> {
#[packrat_parser] #[packrat_parser]
pub(crate) fn source_description_not_directive(s: Span) -> IResult<Span, SourceDescription> { pub(crate) fn source_description_not_directive(s: Span) -> IResult<Span, SourceDescription> {
let (s, a) = many1(alt(( let (s, a) = many1(alt((
is_not("`/\""), is_not("`/\"\\"),
terminated(tag("/"), peek(not(alt((tag("/"), tag("*")))))), terminated(tag("/"), peek(not(alt((tag("/"), tag("*")))))),
)))(s)?; )))(s)?;

View File

@ -403,6 +403,11 @@ mod unit {
r##"module a; initial begin #1 ps[idx] = 1'b1; end endmodule"##, r##"module a; initial begin #1 ps[idx] = 1'b1; end endmodule"##,
Ok((_, _)) Ok((_, _))
); );
test!(
source_text,
r##"module a; reg \`~!-_=+\|[]{};:'"",./<>? ; endmodule"##,
Ok((_, _))
);
} }
} }

View File

@ -234,6 +234,13 @@ pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>>(
let range = Range::new(locate.offset, locate.offset + locate.len); let range = Range::new(locate.offset, locate.offset + locate.len);
ret.push(locate.str(&s), Some((path.as_ref(), range))); 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 => { NodeEvent::Enter(RefNode::KeywordsDirective(x)) if !skip => {
let locate: Locate = x.try_into().unwrap(); let locate: Locate = x.try_into().unwrap();
let range = Range::new(locate.offset, locate.offset + locate.len); 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 })" "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
"##
);
}
} }

View File

@ -0,0 +1,3 @@
module a;
reg \`~!-_=+\|[]{};:'"",./<>? ;
endmodule

View File

@ -180,6 +180,7 @@ pub enum SourceDescription {
StringLiteral(Box<StringLiteral>), StringLiteral(Box<StringLiteral>),
NotDirective(Box<SourceDescriptionNotDirective>), NotDirective(Box<SourceDescriptionNotDirective>),
CompilerDirective(Box<CompilerDirective>), CompilerDirective(Box<CompilerDirective>),
EscapedIdentifier(Box<EscapedIdentifier>),
} }
#[derive(Clone, Debug, PartialEq, Node)] #[derive(Clone, Debug, PartialEq, Node)]