Class: SmartTodo::Todo::Compiler

Inherits:
Prism::Compiler
  • Object
show all
Defined in:
lib/smart_todo/todo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata) ⇒ Compiler

Returns a new instance of Compiler.



39
40
41
42
# File 'lib/smart_todo/todo.rb', line 39

def initialize()
  super()
  @metadata = 
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



37
38
39
# File 'lib/smart_todo/todo.rb', line 37

def 
  @metadata
end

Instance Method Details

#visit_call_node(node) ⇒ Object



44
45
46
# File 'lib/smart_todo/todo.rb', line 44

def visit_call_node(node)
  CallNode.new(node.name, visit_all(node.arguments&.arguments || []), node.location)
end

#visit_integer_node(node) ⇒ Object



48
49
50
# File 'lib/smart_todo/todo.rb', line 48

def visit_integer_node(node)
  node.value
end

#visit_keyword_hash_node(node) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/smart_todo/todo.rb', line 52

def visit_keyword_hash_node(node)
  node.elements.each do |element|
    next unless (key = element.key).is_a?(Prism::SymbolNode)

    case key.unescaped.to_sym
    when :on
      value = visit(element.value)

      if value.is_a?(CallNode)
        if value.arguments.all? { |arg| arg.is_a?(Integer) || arg.is_a?(String) }
          .events << value
        else
          .errors << "Incorrect `:on` event format: #{value.location.slice}"
        end
      else
        .errors << "Incorrect `:on` event format: #{value.inspect}"
      end
    when :to
      .assignees << visit(element.value)
    when :context
      value = visit(element.value)

      unless value.is_a?(String)
        .errors << "Incorrect `:context` format: expected string value"
        next
      end

      unless value =~ %r{^([^/]+)/([^#]+)#(\d+)$}
        .errors << "Incorrect `:context` format: expected \"org/repo#issue_number\""
        next
      end

      org = ::Regexp.last_match(1)
      repo = ::Regexp.last_match(2)
      issue_number = ::Regexp.last_match(3)

      if org.empty? || repo.empty?
        .errors << "Incorrect `:context` format: org and repo cannot be empty"
      else
        .context = CallNode.new(:issue, [org, repo, issue_number], element.value.location)
      end
    end
  end
end

#visit_string_node(node) ⇒ Object



97
98
99
# File 'lib/smart_todo/todo.rb', line 97

def visit_string_node(node)
  node.unescaped
end