10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/ibex/codegen/mermaid.rb', line 10
def render(automaton)
labels = SymbolLabels.build(automaton.grammar)
lines = ["flowchart LR"]
automaton.states.each do |state|
lines << %( state_#{state.id}["State #{state.id}"])
state.transitions.each do |symbol_id, target|
label = escape(labels.fetch(symbol_id) { raise Ibex::Error, "missing grammar symbol id #{symbol_id}" })
lines << " state_#{state.id} -->|#{label}| state_#{target}"
end
end
conflicting = automaton.states.reject { |state| state.conflicts.empty? }
unless conflicting.empty?
lines << " classDef conflict fill:#fee2e2,stroke:#b91c1c,stroke-width:2px"
conflicting.each { |state| lines << " class state_#{state.id} conflict;" }
end
"#{lines.join("\n")}\n"
end
|