Class: Vangrail::Colang::Program
- Inherits:
-
Struct
- Object
- Struct
- Vangrail::Colang::Program
- Defined in:
- lib/vangrail/colang/ast.rb
Overview
The whole grammar this gem executes, as data. Everything the parser can produce is one of these, which is also the honest statement of what a Colang file may contain here: anything else is refused at parse time rather than skipped at run time.
Instance Attribute Summary collapse
-
#bot_messages ⇒ Object
Returns the value of attribute bot_messages.
-
#flows ⇒ Object
Returns the value of attribute flows.
-
#user_messages ⇒ Object
Returns the value of attribute user_messages.
Instance Method Summary collapse
- #bot_message(name) ⇒ Object
-
#check! ⇒ Object
Every
bot <name>in every flow has adefine bot. - #check_body(body, flow_name) ⇒ Object
- #flow(name) ⇒ Object
- #flow_names ⇒ Object
- #merge(other) ⇒ Object
Instance Attribute Details
#bot_messages ⇒ Object
Returns the value of attribute bot_messages
11 12 13 |
# File 'lib/vangrail/colang/ast.rb', line 11 def @bot_messages end |
#flows ⇒ Object
Returns the value of attribute flows
11 12 13 |
# File 'lib/vangrail/colang/ast.rb', line 11 def flows @flows end |
#user_messages ⇒ Object
Returns the value of attribute user_messages
11 12 13 |
# File 'lib/vangrail/colang/ast.rb', line 11 def @user_messages end |
Instance Method Details
#bot_message(name) ⇒ Object
20 21 22 |
# File 'lib/vangrail/colang/ast.rb', line 20 def (name) [name.to_s] end |
#check! ⇒ Object
Every bot <name> in every flow has a define bot. The walk covers
unreached if branches and flows no config names: a half-loaded
guardrail must not load, so a dead-branch bot in a merged .co file
fails the folder. Called after parse/merge, not during parse, so a
bot defined in another file is visible once the programs are joined.
37 38 39 40 |
# File 'lib/vangrail/colang/ast.rb', line 37 def check! flows.each { |name, flow| check_body(flow.body, name) } self end |
#check_body(body, flow_name) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vangrail/colang/ast.rb', line 42 def check_body(body, flow_name) Array(body).each do |node| case node when Bot next if (node.) raise ColangError, "no `define bot #{node.}` for flow #{flow_name.inspect}" when If check_body(node.then_body, flow_name) check_body(node.else_body, flow_name) end end end |
#flow(name) ⇒ Object
12 13 14 |
# File 'lib/vangrail/colang/ast.rb', line 12 def flow(name) flows[name.to_s] end |
#flow_names ⇒ Object
16 17 18 |
# File 'lib/vangrail/colang/ast.rb', line 16 def flow_names flows.keys end |
#merge(other) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/vangrail/colang/ast.rb', line 24 def merge(other) Program.new( flows: flows.merge(other.flows), bot_messages: .merge(other.), user_messages: .merge(other.), ) end |