Clear internal state at each parse
This commit is contained in:
parent
50fd04c3bd
commit
bc25ea914e
@ -2,6 +2,8 @@
|
||||
|
||||
## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.10.3...Unreleased) - ReleaseDate
|
||||
|
||||
* [Fixed] uncleared internal state
|
||||
|
||||
## [v0.10.3](https://github.com/dalance/sv-parser/compare/v0.10.2...v0.10.3) - 2021-01-08
|
||||
|
||||
* [Fixed] empty port list is parsed as non-ANSI style
|
||||
|
@ -91,26 +91,32 @@ impl HasExtraState<bool> for SpanInfo {
|
||||
nom_packrat::storage!(AnyNode, bool, 1024);
|
||||
|
||||
pub fn sv_parser(s: Span) -> IResult<Span, SourceText> {
|
||||
nom_packrat::init!();
|
||||
init();
|
||||
source_text(s)
|
||||
}
|
||||
|
||||
pub fn sv_parser_incomplete(s: Span) -> IResult<Span, SourceText> {
|
||||
nom_packrat::init!();
|
||||
init();
|
||||
source_text_incomplete(s)
|
||||
}
|
||||
|
||||
pub fn lib_parser(s: Span) -> IResult<Span, LibraryText> {
|
||||
nom_packrat::init!();
|
||||
init();
|
||||
library_text(s)
|
||||
}
|
||||
|
||||
pub fn lib_parser_incomplete(s: Span) -> IResult<Span, LibraryText> {
|
||||
nom_packrat::init!();
|
||||
init();
|
||||
library_text_incomplete(s)
|
||||
}
|
||||
|
||||
pub fn pp_parser(s: Span) -> IResult<Span, PreprocessorText> {
|
||||
nom_packrat::init!();
|
||||
init();
|
||||
preprocessor_text(s)
|
||||
}
|
||||
|
||||
fn init() {
|
||||
nom_packrat::init!();
|
||||
clear_directive();
|
||||
clear_version();
|
||||
}
|
||||
|
@ -351,9 +351,13 @@ pub(crate) fn end_directive() {
|
||||
IN_DIRECTIVE.with(|x| x.borrow_mut().pop());
|
||||
}
|
||||
|
||||
pub(crate) fn clear_directive() {
|
||||
IN_DIRECTIVE.with(|x| x.borrow_mut().clear());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) enum VersionSpecifier {
|
||||
Ieee1364_1995,
|
||||
Ieee1364_2001,
|
||||
@ -418,6 +422,12 @@ pub(crate) fn current_version() -> Option<VersionSpecifier> {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn clear_version() {
|
||||
CURRENT_VERSION.with(|current_version| {
|
||||
current_version.borrow_mut().clear();
|
||||
});
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
pub(crate) fn concat<'a>(a: Span<'a>, b: Span<'a>) -> Option<Span<'a>> {
|
||||
|
@ -277,4 +277,46 @@ mod test {
|
||||
let comment = unwrap_node!(&syntax_tree, Comment);
|
||||
assert!(comment.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_continuous() {
|
||||
let src = r##"`ifdef A
|
||||
`endif
|
||||
|
||||
module FetchStage();
|
||||
always_comb begin
|
||||
for (int j = i + 1; j < FETCH_WIDTH; j++) begin
|
||||
end
|
||||
break;
|
||||
end
|
||||
|
||||
AddrPath fetchAddrOut;
|
||||
endmodule"##;
|
||||
|
||||
let src_broken = r##"`ifdef A
|
||||
endif
|
||||
|
||||
module FetchStage();
|
||||
always_comb begin
|
||||
for (int j = i + 1; j < FETCH_WIDTH; j++) begin
|
||||
end
|
||||
break;
|
||||
end
|
||||
|
||||
AddrPath fetchAddrOut;
|
||||
endmodule"##;
|
||||
|
||||
let path = PathBuf::from("");
|
||||
let defines = HashMap::new();
|
||||
let ret = parse_sv_str(src, &path, &defines, &[""], false, false);
|
||||
assert!(ret.is_ok());
|
||||
let ret = parse_sv_str(src_broken, &path, &defines, &[""], false, false);
|
||||
assert!(ret.is_err());
|
||||
let ret = parse_sv_str(src, &path, &defines, &[""], false, false);
|
||||
assert!(ret.is_ok());
|
||||
let ret = parse_sv_str(src_broken, &path, &defines, &[""], false, false);
|
||||
assert!(ret.is_err());
|
||||
let ret = parse_sv_str(src, &path, &defines, &[""], false, false);
|
||||
assert!(ret.is_ok());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user