diff --git a/src/engine.rs b/src/engine.rs index dfc1225c..ff549a1c 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -758,6 +758,8 @@ pub struct Engine { pub(crate) limits: Limits, /// Disable doc-comments? + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] pub(crate) disable_doc_comments: bool, } @@ -874,6 +876,8 @@ impl Engine { max_map_size: None, }, + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] disable_doc_comments: false, }; @@ -930,6 +934,8 @@ impl Engine { max_map_size: None, }, + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] disable_doc_comments: false, } } diff --git a/src/engine_settings.rs b/src/engine_settings.rs index 017d19b0..f2860b25 100644 --- a/src/engine_settings.rs +++ b/src/engine_settings.rs @@ -33,7 +33,11 @@ impl Engine { pub fn optimization_level(&self) -> crate::OptimizationLevel { self.optimization_level } - /// Enable/disable doc-comments. + /// _(METADATA)_ Enable/disable doc-comments for functions. + /// Exported under the `metadata` feature only. + /// Not available under `no_function`. + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] #[inline(always)] pub fn enable_doc_comments(&mut self, enable: bool) -> &mut Self { self.disable_doc_comments = !enable; diff --git a/src/token.rs b/src/token.rs index cf5b06f2..e0aaa36c 100644 --- a/src/token.rs +++ b/src/token.rs @@ -838,6 +838,8 @@ pub struct TokenizeState { /// Include comments? pub include_comments: bool, /// Disable doc-comments? + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] pub disable_doc_comments: bool, /// Is the current tokenizer position within the text stream of an interpolated string? pub is_within_text_terminated_by: Option, @@ -1155,6 +1157,8 @@ fn is_numeric_digit(c: char) -> bool { } /// Test if the comment block is a doc-comment. +#[cfg(not(feature = "no_function"))] +#[cfg(feature = "metadata")] #[inline(always)] pub fn is_doc_comment(comment: &str) -> bool { (comment.starts_with("///") && !comment.starts_with("////")) @@ -1178,10 +1182,22 @@ fn get_next_token_inner( state.comment_level = scan_block_comment(stream, state.comment_level, pos, &mut comment); - if state.include_comments - || (!state.disable_doc_comments && is_doc_comment(comment.as_ref().unwrap())) - { + let include_comments = state.include_comments; + + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] + let include_comments = + if !state.disable_doc_comments && is_doc_comment(comment.as_ref().unwrap()) { + true + } else { + include_comments + }; + + if include_comments { return Some((Token::Comment(comment.unwrap()), start_pos)); + } else if state.comment_level > 0 { + // Reached EOF without ending comment block + return None; } } @@ -1496,6 +1512,8 @@ fn get_next_token_inner( eat_next(stream, pos); let mut comment = match stream.peek_next() { + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] Some('/') if !state.disable_doc_comments => { eat_next(stream, pos); @@ -1529,6 +1547,8 @@ fn get_next_token_inner( eat_next(stream, pos); let mut comment = match stream.peek_next() { + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] Some('*') if !state.disable_doc_comments => { eat_next(stream, pos); @@ -2024,6 +2044,8 @@ impl Engine { comment_level: 0, end_with_none: false, include_comments: false, + #[cfg(not(feature = "no_function"))] + #[cfg(feature = "metadata")] disable_doc_comments: self.disable_doc_comments, is_within_text_terminated_by: None, }, diff --git a/tests/comments.rs b/tests/comments.rs index 72f64aed..4c3452f7 100644 --- a/tests/comments.rs +++ b/tests/comments.rs @@ -27,6 +27,7 @@ fn test_comments() -> Result<(), Box> { } #[cfg(not(feature = "no_function"))] +#[cfg(feature = "metadata")] #[test] fn test_comments_doc() -> Result<(), Box> { let mut engine = Engine::new();