class SyntaxTree::Parser

def on_comment(value)

Experimental RBS support (using type sampling data from the type_fusion project).

def on_comment: (String value) -> untyped

This signature was generated using 37 samples from 1 application.

on_comment: (String value) -> Comment
:call-seq:
def on_comment(value)
  # char is the index of the # character in the source.
  char = char_pos
  location =
    Location.token(
      line: lineno,
      char: char,
      column: current_column,
      size: value.size - 1
    )
  # Loop backward in the source string, starting from the beginning of the
  # comment, and find the first character that is not a space or a tab. If
  # index is -1, this indicates that we've checked all of the characters
  # back to the start of the source, so this comment must be at the
  # beginning of the file.
  #
  # We are purposefully not using rindex or regular expressions here because
  # they check if there are invalid characters, which is actually possible
  # with the use of __END__ syntax.
  index = char - 1
  while index > -1 && (source[index] == "\t" || source[index] == " ")
    index -= 1
  end
  # If we found a character that was not a space or a tab before the comment
  # and it's a newline, then this comment is inline. Otherwise, it stands on
  # its own and can be attached as its own node in the tree.
  inline = index != -1 && source[index] != "\n"
  comment =
    Comment.new(value: value.chomp, inline: inline, location: location)
  @comments << comment
  comment
end