class Yoda::Parsing::Query::CurrentCommentTokenQuery

Provides helper methods to find the current comment token (token on current position) and its kind.

Attributes

comment[R]
location_in_comment[R]

Public Class Methods

new(comment, location_in_comment) click to toggle source

@param comment [String] @param location_in_comment [Location] represents relative coordinates of the current position from the beginning position of the current comment.

# File lib/yoda/parsing/query/current_comment_token_query.rb, line 10
def initialize(comment, location_in_comment)
  fail ArgumentError, comment unless comment.is_a?(String)
  fail ArgumentError, location_in_comment unless location_in_comment.is_a?(Location)
  @comment = comment
  @location_in_comment = location_in_comment
end

Public Instance Methods

at_sign?() click to toggle source

@return [true, false]

# File lib/yoda/parsing/query/current_comment_token_query.rb, line 42
def at_sign?
  inputting_line.at_sign?
end
current_line_comment() click to toggle source

@return [String]

# File lib/yoda/parsing/query/current_comment_token_query.rb, line 18
def current_line_comment
  comment.split("\n")[location_in_comment.row - 1] || ''
end
current_range() click to toggle source

@return [Range, nil]

# File lib/yoda/parsing/query/current_comment_token_query.rb, line 35
def current_range
  return nil if !inputting_line || !inputting_line.current_range
  start, last = inputting_line.current_range
  Range.new(Location.new(row: location_in_comment.row, column: start), Location.new(row: location_in_comment.row, column: last))
end
current_state() click to toggle source

@return [Symbol]

# File lib/yoda/parsing/query/current_comment_token_query.rb, line 23
def current_state
  return :none unless inputting_line
  inputting_line.current_state
end
current_word() click to toggle source

@return [String, nil]

# File lib/yoda/parsing/query/current_comment_token_query.rb, line 29
def current_word
  return nil unless inputting_line
  inputting_line.current_token.to_s
end

Private Instance Methods

inputting_line() click to toggle source

@return [InputtingLine, nil]

# File lib/yoda/parsing/query/current_comment_token_query.rb, line 62
def inputting_line
  return nil unless tokenize
  @inputting_line ||= InputtingLine.new(tokenize, location_in_comment.column)
end
line_to_current_position() click to toggle source

@return [String]

# File lib/yoda/parsing/query/current_comment_token_query.rb, line 57
def line_to_current_position
  current_line_comment.slice(0...location_in_comment.column)
end
tokenize() click to toggle source

@return [CommentTokenizer::Sequence, nil]

# File lib/yoda/parsing/query/current_comment_token_query.rb, line 49
def tokenize
  return @tokenize if instance_variable_defined?(:@tokenized)
  @tokenize = CommentTokenizer.new.parse(line_to_current_position)
rescue Parslet::ParseFailed
  @tokenize = nil
end