class Savi::AST::Relate

Overview

A Relate node has a left Term and right Term, related by an infix Operator. One common example is assignment (op.value == "="):

example = "string" ^~~~~~~ (lhs) ^ (op) ^~~~~~ (rhs) ^~~~~~~~~~~~~~~~~~ (relate)

Another common example is method calls prior to Sugar pass expansion, which have (op.value == "."), and whose #rhs may either be a Qualify (with args) or an Identifier (no args).

Settings.read(content, true) ^~~~~~~~ (lhs) ^ (op) ^~~~~~~~~~~~~~~~~~~ (rhs) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ (relate)

Other examples include binary operators prior to Sugar pass expansion (usually these get converted to method calls in the Sugar pass):

number_1 + number_2 + number_3 ^~~~~~~~ (inner relate lhs) ^ (inner relate op) ^~~~~~~~ (inner relate rhs) ^~~~~~~~~~~~~~~~~~~ (outer relate lhs -> inner relate) ^ (outer relate op) ^~~~~~~~ (outer relate rhs) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (outer relate)

Operator precedence is settled at the parser/builder level, so associativity is decided when first building the AST.

Defined in:

savi/ast.cr

Constructors

Instance Method Summary

Instance methods inherited from class Savi::AST::Node

accept(ctx : Compiler::Context, visitor : Visitor)
accept(ctx : Compiler::Context, visitor : CopyOnMutateVisitor)
accept
, annotations : Array(Annotation) | Nil annotations, annotations=(annotations : Array(Annotation) | Nil) annotations=, children_accept(ctx : Compiler::Context, visitor : Visitor)
children_accept(ctx : Compiler::Context, visitor : CopyOnMutateVisitor)
children_accept
, from(other : Node) from, pos pos, pos? : Savi::Source::Pos? pos?, span_pos(source) span_pos, with_pos(pos : Source::Pos) with_pos

Constructor Detail

def self.new(lhs : Term, op : Operator, rhs : Term) #

[View source]

Instance Method Detail

def children_accept(ctx : Compiler::Context, visitor : Visitor) #

[View source]
def children_accept(ctx : Compiler::Context, visitor : CopyOnMutateVisitor) #

[View source]
def is_assign : Bool #

[View source]
def is_assign=(is_assign : Bool) #

[View source]
def lhs : Savi::AST::Node #

[View source]
def lhs=(lhs : Savi::AST::Node) #

[View source]
def name #

[View source]

[View source]
def op=(op : Savi::AST::Operator) #

[View source]
def rhs : Savi::AST::Node #

[View source]
def rhs=(rhs : Savi::AST::Node) #

[View source]
def span_pos(source) #

[View source]
def to_a : Array(A) #

[View source]
def with_assign_flag #

[View source]