Class: SyntaxTreeAsDotGraph
- Inherits:
-
DotGraphPrinter
- Object
- DotGraphPrinter
- SyntaxTreeAsDotGraph
- Defined in:
- lib/rpdf2txt-rockit/graphdrawing.rb
Instance Method Summary collapse
- #add_parent_link(parent, child, label = nil, weight = nil) ⇒ Object
- #eval_to_dot(ast, parent = nil, linkname = nil, weight = nil) ⇒ Object
Methods inherited from DotGraphPrinter
Constructor Details
This class inherits a constructor from DotGraphPrinter
Instance Method Details
#add_parent_link(parent, child, label = nil, weight = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rpdf2txt-rockit/graphdrawing.rb', line 54 def add_parent_link(parent, child, label = nil, weight = nil) if parent @links[[parent, child]] = "#{parent.id} -> #{child.id}" if label or weight @links[[parent, child]] += " [" + (label ? "label=#{label.inspect}" : "") + ((label and weight) ? "," : "") + (weight ? "weight=#{weight.inspect}" : "") + "]" end end end |
#eval_to_dot(ast, parent = nil, linkname = nil, weight = nil) ⇒ Object
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 96 97 98 99 |
# File 'lib/rpdf2txt-rockit/graphdrawing.rb', line 68 def eval_to_dot(ast, parent = nil, linkname = nil, weight = nil) if ast if ast.kind_of?(SyntaxTree) case ast.name when "_ArrayNode" add_parent_link(parent, ast, linkname, weight) @nodes[ast] = "#{ast.id} [label=" + '"[]"]' ast.each_with_index {|c,i| eval_to_dot(c, ast, i.inspect)} else if parent end # Special handling of Token nodes since we only want to print # the lexeme if ast.children_names.sort == ["lexeme", "value"].sort @nodes[ast] = "#{ast.id} [shape=box,label=#{ast.lexeme.inspect}]" add_parent_link(parent, ast, linkname, weight) else add_parent_link(parent, ast, linkname, weight) @nodes[ast] = "#{ast.id} [label=#{ast.name.inspect}]" ast.childrens.each_with_index {|c,i| eval_to_dot(c, ast, ast.children_names[i]) } end end elsif ast.class == Array # Or nodes return array but they should return ArrayNodes... add_parent_link(parent, ast, linkname, weight) @nodes[ast] = "#{ast.id} [label=\"[]\"]" ast.each_with_index {|c,i| eval_to_dot(c, ast, i)} end end end |