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.



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

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.



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

def constants
  @constants
end

Instance Method Details

#parseObject



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

def parse
  process(@parsed)
end

#process_call(exp) ⇒ Object

CALLS



93
94
95
96
97
98
99
100
101
102
# File 'lib/xumlidot/parsers/generic.rb', line 93

def process_call(exp)
  ::Xumlidot::Parsers::Call.new(exp, @constants.last_added)
  s()
rescue Exception => e
  if ENV["XUMLIDOT_DEBUG"]
    STDERR.puts e.backtrace.reverse
    STDERR.puts "ERROR (#process_call) #{e.message}"
  end
  s()
end

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/xumlidot/parsers/generic.rb', line 50

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

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

  STDERR.puts 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)
    end
  end
rescue Exception => e
  if ENV["XUMLIDOT_DEBUG"]
    STDERR.puts e.backtrace.reverse
    STDERR.puts "ERROR (#process_class) #{e.message}"
  end
  exp
end

#process_defn(exp, superclass_method = false) ⇒ Object

METHODS & METHOD SIGNATURES



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/xumlidot/parsers/generic.rb', line 74

def process_defn(exp, superclass_method = false)
  method = ::Xumlidot::Parsers::MethodSignature.new(exp, superclass_method || @sclass.last)
  @constants.last_added.add_method(method)
  STDERR.puts method.to_s if ::Xumlidot::Options.debug == true
  #super(exp) { process_until_empty(exp) } # DISABLING since parsing the method is crashing
  s()
rescue Exception => e
  if ENV["XUMLIDOT_DEBUG"]
    STDERR.puts e.backtrace.reverse
    STDERR.puts "ERROR (#process_def#{superclass_method ? 's' : 'n'}) #{e.message}"
  end
  s()
end

#process_defs(exp) ⇒ Object



88
89
90
# File 'lib/xumlidot/parsers/generic.rb', line 88

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

#process_module(exp) ⇒ Object



44
45
46
47
48
# File 'lib/xumlidot/parsers/generic.rb', line 44

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



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xumlidot/parsers/generic.rb', line 32

def process_sclass(exp)
  super(exp) do
    Scope.public { process_until_empty(exp) } # Process the superclass with public visibility
  end
rescue Exception => e
  if ENV["XUMLIDOT_DEBUG"]
    STDERR.puts e.backtrace.reverse
    STDERR.puts "ERROR (#process_sclass) #{e.message}"
  end
  exp
end