Module: Ibex::Codegen::Railroad
- Extended by:
- RailroadDocumentation
- Defined in:
- lib/ibex/codegen/railroad.rb,
sig/ibex/codegen/railroad.rbs
Overview
Renders normalized Grammar IR as a self-contained SVG railroad diagram.
Constant Summary collapse
- CHAR_WIDTH =
8- BOX_HEIGHT =
28- BOX_PADDING =
20- TRACK_GAP =
18- ROW_HEIGHT =
46- SECTION_HEADER =
30- SECTION_GAP =
18- PAGE_PADDING =
20- TITLE_HEIGHT =
48- EPSILON_WIDTH =
34- START_RADIUS =
4- END_RADIUS =
6- MIN_RAIL_X =
180- STYLE =
<<~CSS text { fill: #172033; font: 14px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; } .diagram-title { font-size: 18px; font-weight: 700; } .rule-name { font-weight: 700; } .rule-documentation { fill: #4b5565; font: 12px system-ui, sans-serif; } .production-id { fill: #697386; font-size: 11px; text-anchor: end; } .track { fill: none; stroke: #697386; stroke-width: 2; } .start { fill: #172033; } .end { fill: #fff; stroke: #172033; stroke-width: 2; } .end-dot { fill: #172033; } .symbol { stroke: #172033; stroke-width: 1.5; } .terminal { fill: #fff3df; } .nonterminal { fill: #e8f1ff; } .symbol-label { text-anchor: middle; } .epsilon { fill: #697386; font-style: italic; text-anchor: middle; } CSS
Constants included from RailroadDocumentation
Ibex::Codegen::RailroadDocumentation::DOCUMENTATION_COLUMNS, Ibex::Codegen::RailroadDocumentation::DOCUMENTATION_GAP, Ibex::Codegen::RailroadDocumentation::DOCUMENTATION_LINE_HEIGHT
Class Method Summary collapse
Methods included from RailroadDocumentation
append_rule_documentation, documentation_lines, escape, section_header_height, track
Class Method Details
.render(grammar) ⇒ String
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ibex/codegen/railroad.rb', line 45 def render(grammar) labels = SymbolLabels.build(grammar) groups = production_groups(grammar) rail_x = [MIN_RAIL_X, groups.map { |symbol, _| label_width(labels.fetch(symbol.id)) }.max.to_i + 44].max width = document_width(grammar, groups, labels, rail_x) height = document_height(groups) lines = document_start(grammar, width, height) append_sections(lines, grammar, groups, labels, rail_x) lines << "</svg>" "#{lines.join("\n")}\n" end |