Class: Astrapi::PrettyPrinter

Inherits:
Object
  • Object
show all
Includes:
Indent
Defined in:
lib/pretty_printer.rb

Constant Summary

Constants included from Indent

Indent::INDENT

Instance Method Summary collapse

Methods included from Indent

#dedent, #indent, #say

Instance Method Details



11
12
13
# File 'lib/pretty_printer.rb', line 11

def print ast
  ast.accept(self)
end

#visitArrayOf(arrayOf, args = nil) ⇒ Object



55
56
57
58
59
60
# File 'lib/pretty_printer.rb', line 55

def visitArrayOf arrayOf,args=nil
  indent "visitArrayOf"
  str="#{arrayOf.type.name}[]"
  dedent
  return str
end

#visitAttr(attr, args = nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/pretty_printer.rb', line 41

def visitAttr attr,args=nil
  indent "visitAttr"
  type=attr.type.accept(self)
  str="attr #{attr.name} => #{type}"
  dedent
  str
end

#visitIdentifier(id, args = nil) ⇒ Object



62
63
64
65
# File 'lib/pretty_printer.rb', line 62

def visitIdentifier id,args=nil
  indent "visitIdentifier"
  dedent
end

#visitKlass(klass, args = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pretty_printer.rb', line 28

def visitKlass klass,args=nil
  indent "visitKlass"
  code = Code.new
  inherit="< #{klass.inheritance}" if klass.inheritance
  code << "class #{klass.name} #{inherit}"
  code.indent=2
  klass.attrs.each{|attr| code << attr.accept(self)}
  code.indent=0
  code << "end"
  dedent
  code
end

#visitModule(modul, args = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pretty_printer.rb', line 15

def visitModule modul,args=nil
  indent "visitModule"
  code=Code.new
  code << "module #{name=modul.name}"
  code.newline
  code.indent=2
  modul.classes.each{|k| code << k.accept(self) ; code.newline}
  code.indent=0
  code << "end"
  dedent
  return code
end

#visitType(type, args = nil) ⇒ Object



49
50
51
52
53
# File 'lib/pretty_printer.rb', line 49

def visitType type,args=nil
  indent "visitType"
  dedent
  return type.name.to_s
end