Module: Kumi::Core::RubyParser::Sugar
- Includes:
- Syntax
- Defined in:
- lib/kumi/core/ruby_parser/sugar.rb
Defined Under Namespace
Modules: ArrayRefinement, ExpressionRefinement, HashRefinement, ModuleRefinement, NumericRefinement, ProxyRefinement, StringRefinement
Constant Summary collapse
- ARITHMETIC_OPS =
{ :+ => :add, :- => :subtract, :* => :multiply, :/ => :divide, :% => :modulo, :** => :power }.freeze
- COMPARISON_OPS =
%i[< <= > >= == !=].freeze
- LITERAL_TYPES =
[ Integer, String, Symbol, TrueClass, FalseClass, Float, Regexp, NilClass ].freeze
- COLLECTION_METHODS =
Collection methods that can be applied to arrays/syntax nodes
%i[ sum size length first last sort reverse unique min max empty? flatten map_with_index indices ].freeze
Class Method Summary collapse
-
.create_call_expression(fn_name, args) ⇒ Object
Create a call expression with consistent error handling.
- .ensure_literal(obj) ⇒ Object
- .syntax_expression?(obj) ⇒ Boolean
Class Method Details
.create_call_expression(fn_name, args) ⇒ Object
Create a call expression with consistent error handling
39 40 41 |
# File 'lib/kumi/core/ruby_parser/sugar.rb', line 39 def self.create_call_expression(fn_name, args) Kumi::Syntax::CallExpression.new(fn_name, args) end |
.ensure_literal(obj) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/kumi/core/ruby_parser/sugar.rb', line 26 def self.ensure_literal(obj) return Kumi::Syntax::Literal.new(obj) if LITERAL_TYPES.any? { |type| obj.is_a?(type) } return obj if obj.is_a?(Syntax::Node) return obj.to_ast_node if obj.respond_to?(:to_ast_node) Kumi::Syntax::Literal.new(obj) end |