Module: Y2R::AST::YCP::Comments
- Defined in:
- lib/y2r/ast/ycp.rb
Overview
Contains utility functions related to comment processing.
Defined Under Namespace
Classes: Whitespace
Constant Summary collapse
- COMMENT_SPLITTING_REGEXP =
/ \#[^\n]*(\n|$) # one-line hash comment | \/\/[^\n]*(\n|$) # one-line slash comment | \/\* # multi-line comment ( [^*]|\*(?!\/) )* \*\/ | ((?!\#|\/\/|\/\*).)+ # non-comment /xm- YAST_TYPES_REGEXP =
/(void|any|boolean|string|symbol|integer|float|term|path|byteblock|block\s*<.*>|list(\s*<.*>|)|map(\s*<.*>|))/
Class Method Summary collapse
- .process_comment_after(node, comment, options) ⇒ Object
- .process_comment_before(node, comment, options) ⇒ Object
Class Method Details
.process_comment_after(node, comment, options) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/y2r/ast/ycp.rb', line 256 def process_comment_after(node, comment, ) whitespace = [:whitespace] comment = fix_delimiters(node, comment) comment = strip_leading_whitespace(comment) comment = strip_trailing_whitespace(comment) if whitespace.drop_after_above? comment = drop_leading_empty_lines(comment) end if whitespace.drop_after_below? comment = drop_trailing_empty_lines(comment) end # In whitespace-dropping mode we want to remove empty comments # completely. Note that returning "" instead of nil would not be # enough, at that would cause adding a newline into the generated # code at some places. if whitespace.drop_after_above? || whitespace.drop_after_below? comment = nil if comment.empty? end comment end |
.process_comment_before(node, comment, options) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/y2r/ast/ycp.rb', line 215 def process_comment_before(node, comment, ) whitespace = [:whitespace] comment = fix_delimiters(node, comment) comment = strip_leading_whitespace(comment) comment = strip_trailing_whitespace(comment) if whitespace.drop_before_above? comment = drop_leading_empty_lines(comment) end if whitespace.drop_before_below? comment = drop_trailing_empty_lines(comment) else # In many before comments, there is a line of whitespace caused by # separation of the comment from the node it belongs to. For # example, in this case, the comment and the node are separated by # "\n ": # # { # /* Comment */ # y2milestone("M1"); # } # # We need to remove such lines of whitespace (which are now empty # because of whitespace stripping above), but not touch any # additional ones). comment = drop_trailing_empty_line(comment) end # In whitespace-dropping mode we want to remove empty comments # completely. Note that returning "" instead of nil would not be # enough, at that would cause adding a newline into the generated # code at some places. if whitespace.drop_before_above? || whitespace.drop_before_below? comment = nil if comment.empty? end comment end |