Class: XDry::PInterfaceFields

Inherits:
Parser
  • Object
show all
Defined in:
lib/xdry/parsing/parsers.rb

Instance Attribute Summary

Attributes inherited from Parser

#scope

Instance Method Summary collapse

Methods inherited from Parser

#to_s

Constructor Details

#initialize(scope) ⇒ PInterfaceFields

Returns a new instance of PInterfaceFields.



50
51
52
53
# File 'lib/xdry/parsing/parsers.rb', line 50

def initialize scope
  super
  @tags = Set.new
end

Instance Method Details

#parse_line!(line, eol_comments, indent) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/xdry/parsing/parsers.rb', line 55

def parse_line! line, eol_comments, indent
  @this_line_tags = Set.new
  [[/!p\b/, 'wants-property'], [/!c\b/, 'wants-constructor']].each do |regexp, tag|
    if line =~ regexp
      marker = $&
      is_full_line = line.gsub(marker, '').strip.empty?
      klass = is_full_line ? NFullLineMarker : NPartLineMarker
      yield klass.new(marker)
      (is_full_line ? @tags : @this_line_tags) << tag
      return if is_full_line
    end
  end
  case line
  when /\}/
    yield NInterfaceFieldsEnd.new
  when %r~^//\s*persistent$~
    @tags << 'persistent'
  when ''
    @tags.clear
  when /^(.*[\s\W])(\w+)\s*;/
    type_name, field_name = $1.strip, $2
    yield process_type_hint(NFieldDef.new(field_name, VarType.parse(type_name)), eol_comments)
  end
end