diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c77b64..4a4689e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased](https://github.com/dalance/sv-parser/compare/v0.4.18...Unreleased) - ReleaseDate * [Added] include line check +* [Fixed] resetall directive in design element ## [v0.4.18](https://github.com/dalance/sv-parser/compare/v0.4.17...v0.4.18) - 2019-12-12 diff --git a/sv-parser-parser/src/general/compiler_directives.rs b/sv-parser-parser/src/general/compiler_directives.rs index ddb49ee..8234fbd 100644 --- a/sv-parser-parser/src/general/compiler_directives.rs +++ b/sv-parser-parser/src/general/compiler_directives.rs @@ -64,6 +64,65 @@ pub(crate) fn compiler_directive(s: Span) -> IResult { ret } +#[tracable_parser] +#[packrat_parser] +pub(crate) fn compiler_directive_without_resetall(s: Span) -> IResult { + begin_directive(); + let ret = alt(( + map(include_compiler_directive, |x| { + CompilerDirective::IncludeCompilerDirective(Box::new(x)) + }), + map(text_macro_definition, |x| { + CompilerDirective::TextMacroDefinition(Box::new(x)) + }), + map(undefine_compiler_directive, |x| { + CompilerDirective::UndefineCompilerDirective(Box::new(x)) + }), + map(undefineall_compiler_directive, |x| { + CompilerDirective::UndefineallCompilerDirective(Box::new(x)) + }), + map(conditional_compiler_directive, |x| { + CompilerDirective::ConditionalCompilerDirective(Box::new(x)) + }), + map(timescale_compiler_directive, |x| { + CompilerDirective::TimescaleCompilerDirective(Box::new(x)) + }), + map(default_nettype_compiler_directive, |x| { + CompilerDirective::DefaultNettypeCompilerDirective(Box::new(x)) + }), + map(unconnected_drive_compiler_directive, |x| { + CompilerDirective::UnconnectedDriveCompilerDirective(Box::new(x)) + }), + map(nounconnected_drive_compiler_directive, |x| { + CompilerDirective::NounconnectedDriveCompilerDirective(Box::new(x)) + }), + map(celldefine_compiler_directive, |x| { + CompilerDirective::CelldefineDriveCompilerDirective(Box::new(x)) + }), + map(endcelldefine_compiler_directive, |x| { + CompilerDirective::EndcelldefineDriveCompilerDirective(Box::new(x)) + }), + map(pragma, |x| CompilerDirective::Pragma(Box::new(x))), + map(line_compiler_directive, |x| { + CompilerDirective::LineCompilerDirective(Box::new(x)) + }), + map(position_compiler_directive, |x| { + CompilerDirective::PositionCompilerDirective(Box::new(x)) + }), + map(keywords_directive, |x| { + CompilerDirective::KeywordsDirective(Box::new(x)) + }), + map(endkeywords_directive, |x| { + CompilerDirective::EndkeywordsDirective(Box::new(x)) + }), + map(text_macro_usage, |x| { + CompilerDirective::TextMacroUsage(Box::new(x)) + }), + ))(s); + end_directive(); + ret +} + #[tracable_parser] #[packrat_parser] pub(crate) fn resetall_compiler_directive(s: Span) -> IResult { diff --git a/sv-parser-parser/src/source_text/system_verilog_source_text.rs b/sv-parser-parser/src/source_text/system_verilog_source_text.rs index 84f0d31..d1b3b8a 100644 --- a/sv-parser-parser/src/source_text/system_verilog_source_text.rs +++ b/sv-parser-parser/src/source_text/system_verilog_source_text.rs @@ -15,6 +15,9 @@ pub(crate) fn source_text(s: Span) -> IResult { #[packrat_parser] pub(crate) fn description(s: Span) -> IResult { alt(( + map(resetall_compiler_directive, |x| { + Description::ResetallCompilerDirective(Box::new(x)) + }), map(module_declaration, |x| { Description::ModuleDeclaration(Box::new(x)) }), diff --git a/sv-parser-parser/src/utils.rs b/sv-parser-parser/src/utils.rs index 2926024..9221cfd 100644 --- a/sv-parser-parser/src/utils.rs +++ b/sv-parser-parser/src/utils.rs @@ -339,9 +339,10 @@ pub(crate) fn white_space(s: Span) -> IResult { map(preceded(peek(char('/')), comment), |x| { WhiteSpace::Comment(Box::new(x)) }), - map(preceded(peek(char('`')), compiler_directive), |x| { - WhiteSpace::CompilerDirective(Box::new(x)) - }), + map( + preceded(peek(char('`')), compiler_directive_without_resetall), + |x| WhiteSpace::CompilerDirective(Box::new(x)), + ), ))(s) } } diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index add611b..869e157 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -209,7 +209,11 @@ pub fn preprocess_str, U: AsRef>( _ => (), } match n { - NodeEvent::Enter(RefNode::ResetallCompilerDirective(_)) if !skip => {} + NodeEvent::Enter(RefNode::ResetallCompilerDirective(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::UndefineCompilerDirective(x)) if !skip => { let (_, _, ref name) = x.nodes; let id = identifier((&name.nodes.0).into(), &s).unwrap(); diff --git a/sv-parser-syntaxtree/src/source_text/system_verilog_source_text.rs b/sv-parser-syntaxtree/src/source_text/system_verilog_source_text.rs index 51e93ec..e66a47f 100644 --- a/sv-parser-syntaxtree/src/source_text/system_verilog_source_text.rs +++ b/sv-parser-syntaxtree/src/source_text/system_verilog_source_text.rs @@ -13,6 +13,7 @@ pub struct SourceText { #[derive(Clone, Debug, PartialEq, Node)] pub enum Description { + ResetallCompilerDirective(Box), ModuleDeclaration(Box), UdpDeclaration(Box), InterfaceDeclaration(Box),