Class: Yoda::Parsing::Query::CurrentCommentTokenQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/parsing/query/current_comment_token_query.rb

Overview

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

Defined Under Namespace

Classes: InputtingLine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comment, location_in_comment) ⇒ CurrentCommentTokenQuery

Returns a new instance of CurrentCommentTokenQuery.

Parameters:

  • comment (String)
  • location_in_comment (Location)

    represents relative coordinates of the current position from the beginning position of the current comment.



10
11
12
13
14
15
# 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

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



6
7
8
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 6

def comment
  @comment
end

#location_in_commentObject (readonly)

Returns the value of attribute location_in_comment.



6
7
8
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 6

def location_in_comment
  @location_in_comment
end

Instance Method Details

#at_sign?true, false

Returns:

  • (true, false)


42
43
44
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 42

def at_sign?
  inputting_line.at_sign?
end

#current_line_commentString

Returns:

  • (String)


18
19
20
# 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_rangeRange?

Returns:



35
36
37
38
39
# 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_stateSymbol

Returns:

  • (Symbol)


23
24
25
26
# 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_wordString?

Returns:

  • (String, nil)


29
30
31
32
# 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