Class: Kumi::Core::RubyParser::ExpressionConverter
- Inherits:
-
Object
- Object
- Kumi::Core::RubyParser::ExpressionConverter
- Includes:
- ErrorReporting, Syntax
- Defined in:
- lib/kumi/core/ruby_parser/expression_converter.rb
Overview
Converts Ruby objects and DSL expressions into AST nodes This is the bridge between Ruby’s native types and Kumi’s syntax tree
Constant Summary collapse
- LITERAL_TYPES =
Use the same literal types as Sugar module to avoid duplication
Sugar::LITERAL_TYPES
Instance Method Summary collapse
-
#ensure_syntax(obj) ⇒ Syntax::Node
Convert any Ruby object into a syntax node.
-
#fn(fn_name, *args) ⇒ Syntax::CallExpression
Create a function call expression.
-
#initialize(context) ⇒ ExpressionConverter
constructor
A new instance of ExpressionConverter.
-
#input ⇒ InputProxy
Access the input proxy for field references.
-
#literal(value) ⇒ Syntax::Literal
Create a literal value node.
-
#raise_error(message, location) ⇒ Object
Raise a syntax error with location information.
-
#ref(name) ⇒ Syntax::DeclarationReference
Create a reference to another declaration.
Methods included from ErrorReporting
#inferred_location, #raise_localized_error, #raise_syntax_error, #raise_type_error, #report_enhanced_error, #report_error, #report_semantic_error, #report_syntax_error, #report_type_error
Constructor Details
#initialize(context) ⇒ ExpressionConverter
Returns a new instance of ExpressionConverter.
15 16 17 |
# File 'lib/kumi/core/ruby_parser/expression_converter.rb', line 15 def initialize(context) @context = context end |
Instance Method Details
#ensure_syntax(obj) ⇒ Syntax::Node
Convert any Ruby object into a syntax node
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kumi/core/ruby_parser/expression_converter.rb', line 22 def ensure_syntax(obj) case obj when *LITERAL_TYPES create_literal(obj) when Array create_list(obj) when Hash create_hash(obj) when Syntax::Node obj else handle_custom_object(obj) end end |
#fn(fn_name, *args) ⇒ Syntax::CallExpression
Create a function call expression
56 57 58 59 60 |
# File 'lib/kumi/core/ruby_parser/expression_converter.rb', line 56 def fn(fn_name, *args) validate_function_name(fn_name) expr_args = convert_arguments(args) Kumi::Syntax::CallExpression.new(fn_name, expr_args, loc: current_location) end |
#input ⇒ InputProxy
Access the input proxy for field references
64 65 66 |
# File 'lib/kumi/core/ruby_parser/expression_converter.rb', line 64 def input InputProxy.new(@context) end |
#literal(value) ⇒ Syntax::Literal
Create a literal value node
48 49 50 |
# File 'lib/kumi/core/ruby_parser/expression_converter.rb', line 48 def literal(value) Kumi::Syntax::Literal.new(value, loc: current_location) end |
#raise_error(message, location) ⇒ Object
Raise a syntax error with location information
71 72 73 |
# File 'lib/kumi/core/ruby_parser/expression_converter.rb', line 71 def raise_error(, location) raise_syntax_error(, location: location) end |
#ref(name) ⇒ Syntax::DeclarationReference
Create a reference to another declaration
40 41 42 43 |
# File 'lib/kumi/core/ruby_parser/expression_converter.rb', line 40 def ref(name) validate_reference_name(name) Kumi::Syntax::DeclarationReference.new(name, loc: current_location) end |