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(context) ⇒ RosConditionParser
constructor
A new instance of RosConditionParser.
- #quoted_literal(quote) ⇒ Object
Constructor Details
#initialize(context) ⇒ RosConditionParser
Returns a new instance of RosConditionParser.
11 12 13 14 |
# File 'lib/autoproj/ros_condition_parser.rb', line 11 def initialize(context) @context = context super() end |
Instance Method Details
#any_of(strings) ⇒ Object
37 38 39 40 |
# File 'lib/autoproj/ros_condition_parser.rb', line 37 def any_of(strings) strings = strings.dup strings.reduce(str(strings.shift)) { |acc, s| acc | str(s) } end |
#chain(lhs, operator, operation) ⇒ Object
48 49 50 |
# File 'lib/autoproj/ros_condition_parser.rb', line 48 def chain(lhs, operator, operation) (lhs.as(:lhs) >> operator >> operation.as(:rhs)) | lhs end |
#evaluate(expr) ⇒ Object
31 32 33 34 35 |
# File 'lib/autoproj/ros_condition_parser.rb', line 31 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 19 20 |
# File 'lib/autoproj/ros_condition_parser.rb', line 16 def (var) Autoproj.(var, @context) rescue StandardError "" end |
#quoted_literal(quote) ⇒ Object
42 43 44 45 46 |
# File 'lib/autoproj/ros_condition_parser.rb', line 42 def quoted_literal(quote) str(quote) >> ( str(quote).absent? >> any ).repeat.maybe.as(:literal) >> str(quote) end |