Class: Xumlidot::Parsers::Generic

Inherits:
MethodBasedSexpProcessor
  • Object
show all
Defined in:
lib/xumlidot/parsers/generic.rb

Overview

We need a level of indirection between the actual parser and MethodBasedSexpProcessor since we will probably end up inheriting from SexpProcessor directly eventually

The File processor was getting too busy and its obvious we want to share some bits of the processing

Direct Known Subclasses

File

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, constants = Stack::Constants.new) ⇒ Generic

Returns a new instance of Generic.



17
18
19
20
21
# File 'lib/xumlidot/parsers/generic.rb', line 17

def initialize(string, constants = Stack::Constants.new)
  @parsed = RubyParser.new.parse(string)
  @constants = constants
  super()
end

Instance Attribute Details

#constantsObject (readonly)

Returns the value of attribute constants.



15
16
17
# File 'lib/xumlidot/parsers/generic.rb', line 15

def constants
  @constants
end

Instance Method Details

#parseObject



23
24
25
# File 'lib/xumlidot/parsers/generic.rb', line 23

def parse
  process(@parsed)
end

#process_call(exp) ⇒ Object

CALLS



83
84
85
86
87
88
# File 'lib/xumlidot/parsers/generic.rb', line 83

def process_call(exp)
  ::Xumlidot::Parsers::Call.new(exp, @constants.last_added)
  s()
rescue StandardError => e
  sdebug('#process_call', e)
end

#process_class(exp, definition_parser: ::Xumlidot::Parsers::KlassDefinition, type: Xumlidot::Types::Klass) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/xumlidot/parsers/generic.rb', line 46

def process_class(exp,
                  definition_parser: ::Xumlidot::Parsers::KlassDefinition,
                  type: Xumlidot::Types::Klass)

  Scope.set_visibility
  definition = definition_parser.new(Sexp.new.concat(exp[0..2]), @class_stack).definition

  warn definition.to_s if ::Xumlidot::Options.debug == true
  super(exp) do
    Scope.public do
      klass_or_module = type.new(definition)
      @constants.add(klass_or_module)
      process_until_empty(exp)
      @constants.pop_last_added
    end
  end
rescue StandardError => e
  sdebug('#process_class', e)
  exp
end

#process_defn(exp, superclass_method: false) ⇒ Object

METHODS & METHOD SIGNATURES



68
69
70
71
72
73
74
75
76
# File 'lib/xumlidot/parsers/generic.rb', line 68

def process_defn(exp, superclass_method: false)
  method = ::Xumlidot::Parsers::MethodSignature.new(exp, superclass_method: superclass_method || @sclass.last)
  @constants.last_added.add_method(method)
  warn method.to_s if ::Xumlidot::Options.debug == true
  # super(exp) { process_until_empty(exp) } # DISABLING since parsing the method is crashing
  s()
rescue StandardError => e
  sdebug("#process_def#{superclass_method ? 's' : 'n'}", e)
end

#process_defs(exp) ⇒ Object



78
79
80
# File 'lib/xumlidot/parsers/generic.rb', line 78

def process_defs(exp)
  process_defn(exp, superclass_method: true)
end

#process_module(exp) ⇒ Object



40
41
42
43
44
# File 'lib/xumlidot/parsers/generic.rb', line 40

def process_module(exp)
  process_class(exp,
                definition_parser: ::Xumlidot::Parsers::ModuleDefinition,
                type: Xumlidot::Types::Module)
end

#process_sclass(exp) ⇒ Object

CLASSES, MODULES AND DEFINITIONS

We process the superclass differently since we dont want an actual superclass node adding - just the methods



31
32
33
34
35
36
37
38
# File 'lib/xumlidot/parsers/generic.rb', line 31

def process_sclass(exp)
  super(exp) do
    Scope.public { process_until_empty(exp) } # Process the superclass with public visibility
  end
rescue StandardError => e
  sdebug('#process_sclass', e)
  exp
end

#sdebug(name, error) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/xumlidot/parsers/generic.rb', line 90

def sdebug(name, error)
  return s() unless ENV['XUMLIDOT_DEBUG']

  warn error.backtrace.reverse
  warn "ERROR (#{name}) #{error.message}"
  s()
end