Class: Autoproj::RosConditionParser
- Inherits:
-
Parslet::Parser
- Object
- Parslet::Parser
- Autoproj::RosConditionParser
- Defined in:
- lib/autoproj/ros_condition_parser.rb
Overview
Parses a conditional expression Syntax and rules as defined in www.ros.org/reps/rep-0149.html#id20
Defined Under Namespace
Classes: Transform
Constant Summary collapse
- RESERVED =
%w[and or].freeze
Instance Method Summary collapse
- #any_of(strings) ⇒ Object
- #chain(lhs, operator, operation) ⇒ Object
- #evaluate(expr) ⇒ Object
- #expand(var) ⇒ Object
-
#initialize(&expander) ⇒ RosConditionParser
constructor
A new instance of RosConditionParser.
- #quoted_literal(quote) ⇒ Object
Constructor Details
#initialize(&expander) ⇒ RosConditionParser
Returns a new instance of RosConditionParser.
11 12 13 14 |
# File 'lib/autoproj/ros_condition_parser.rb', line 11 def initialize(&) @expander = super() end |
Instance Method Details
#any_of(strings) ⇒ Object
35 36 37 38 |
# File 'lib/autoproj/ros_condition_parser.rb', line 35 def any_of(strings) strings = strings.dup strings.reduce(str(strings.shift)) { |acc, s| acc | str(s) } end |
#chain(lhs, operator, operation) ⇒ Object
46 47 48 |
# File 'lib/autoproj/ros_condition_parser.rb', line 46 def chain(lhs, operator, operation) (lhs.as(:lhs) >> operator >> operation.as(:rhs)) | lhs end |
#evaluate(expr) ⇒ Object
29 30 31 32 33 |
# File 'lib/autoproj/ros_condition_parser.rb', line 29 def evaluate(expr) Transform.new.apply(parse(expr.strip), expander: method(:expand)) rescue Parslet::ParseFailed => e raise Autoproj::ConfigError, e. end |
#expand(var) ⇒ Object
16 17 18 |
# File 'lib/autoproj/ros_condition_parser.rb', line 16 def (var) @expander.call(var) end |
#quoted_literal(quote) ⇒ Object
40 41 42 43 44 |
# File 'lib/autoproj/ros_condition_parser.rb', line 40 def quoted_literal(quote) str(quote) >> ( str(quote).absent? >> any ).repeat.maybe.as(:literal) >> str(quote) end |