Class: DecisionAgent::Dmn::Feel::SimpleParser
- Inherits:
-
Object
- Object
- DecisionAgent::Dmn::Feel::SimpleParser
- Defined in:
- lib/decision_agent/dmn/feel/simple_parser.rb
Overview
Simple regex-based parser for common FEEL expressions Handles arithmetic, logical operators, and simple comparisons Uses operator precedence climbing for correct evaluation order
Constant Summary collapse
- ARITHMETIC_OPS =
%w[+ - * / ** %].freeze
- LOGICAL_OPS =
%w[and or].freeze
- COMPARISON_OPS =
%w[>= <= != > < =].freeze
- PRECEDENCE =
Operator precedence (higher number = higher precedence)
{ "or" => 1, "and" => 2, "=" => 3, "!=" => 3, "<" => 4, "<=" => 4, ">" => 4, ">=" => 4, "+" => 5, "-" => 5, "*" => 6, "/" => 6, "%" => 6, "**" => 7 }.freeze
Class Method Summary collapse
-
.can_parse?(expression) ⇒ Boolean
Check if expression can be handled by simple parser.
Instance Method Summary collapse
-
#initialize ⇒ SimpleParser
constructor
A new instance of SimpleParser.
-
#parse(expression) ⇒ Object
Parse expression and return AST-like structure.
Constructor Details
#initialize ⇒ SimpleParser
Returns a new instance of SimpleParser.
35 36 37 38 |
# File 'lib/decision_agent/dmn/feel/simple_parser.rb', line 35 def initialize @tokens = [] @position = 0 end |
Class Method Details
.can_parse?(expression) ⇒ Boolean
Check if expression can be handled by simple parser
41 42 43 44 45 46 47 48 49 |
# File 'lib/decision_agent/dmn/feel/simple_parser.rb', line 41 def self.can_parse?(expression) expr = expression.to_s.strip # Can't handle: lists, contexts, functions, quantifiers, for expressions return false if expr.match?(/[\[{]/) # Lists or contexts return false if expr.match?(/\w+\s*\(/) # Function calls return false if expr.match?(/\b(some|every|for|if)\b/) # Complex constructs true end |
Instance Method Details
#parse(expression) ⇒ Object
Parse expression and return AST-like structure
52 53 54 55 56 57 58 59 60 |
# File 'lib/decision_agent/dmn/feel/simple_parser.rb', line 52 def parse(expression) expr = expression.to_s.strip raise DecisionAgent::Dmn::FeelParseError, "Empty expression" if expr.empty? @tokens = tokenize(expr) @position = 0 parse_expression end |