diff --git a/src/build/ast/AST.go b/src/build/ast/AST.go index 7def683..1c8f6dd 100644 --- a/src/build/ast/AST.go +++ b/src/build/ast/AST.go @@ -1,63 +1,6 @@ package ast -import ( - "fmt" - - "git.akyoto.dev/cli/q/src/build/expression" - "git.akyoto.dev/cli/q/src/build/token" -) +import "fmt" type Node fmt.Stringer type AST []Node - -type Assign struct { - Value *expression.Expression - Name token.Token - Operator token.Token -} - -func (node *Assign) String() string { - return fmt.Sprintf("(= %s %s)", node.Name.Text(), node.Value) -} - -type Call struct { - Expression *expression.Expression -} - -func (node *Call) String() string { - return node.Expression.String() -} - -type Define struct { - Value *expression.Expression - Name token.Token -} - -func (node *Define) String() string { - return fmt.Sprintf("(= %s %s)", node.Name.Text(), node.Value) -} - -type If struct { - Condition *expression.Expression - Body AST -} - -func (node *If) String() string { - return fmt.Sprintf("(if %s %s)", node.Condition, node.Body) -} - -type Loop struct { - Body AST -} - -func (node *Loop) String() string { - return fmt.Sprintf("(loop %s)", node.Body) -} - -type Return struct { - Value *expression.Expression -} - -func (node *Return) String() string { - return fmt.Sprintf("(return %s)", node.Value) -} diff --git a/src/build/ast/Assign.go b/src/build/ast/Assign.go new file mode 100644 index 0000000..daee95d --- /dev/null +++ b/src/build/ast/Assign.go @@ -0,0 +1,19 @@ +package ast + +import ( + "fmt" + + "git.akyoto.dev/cli/q/src/build/expression" + "git.akyoto.dev/cli/q/src/build/token" +) + +// Assign represents an assignment to an existing variable or memory location. +type Assign struct { + Value *expression.Expression + Name token.Token + Operator token.Token +} + +func (node *Assign) String() string { + return fmt.Sprintf("(= %s %s)", node.Name.Text(), node.Value) +} diff --git a/src/build/ast/Call.go b/src/build/ast/Call.go new file mode 100644 index 0000000..d7825b3 --- /dev/null +++ b/src/build/ast/Call.go @@ -0,0 +1,12 @@ +package ast + +import "git.akyoto.dev/cli/q/src/build/expression" + +// Call represents a function call. +type Call struct { + Expression *expression.Expression +} + +func (node *Call) String() string { + return node.Expression.String() +} diff --git a/src/build/ast/Define.go b/src/build/ast/Define.go new file mode 100644 index 0000000..6751491 --- /dev/null +++ b/src/build/ast/Define.go @@ -0,0 +1,18 @@ +package ast + +import ( + "fmt" + + "git.akyoto.dev/cli/q/src/build/expression" + "git.akyoto.dev/cli/q/src/build/token" +) + +// Define represents a variable definition. +type Define struct { + Value *expression.Expression + Name token.Token +} + +func (node *Define) String() string { + return fmt.Sprintf("(= %s %s)", node.Name.Text(), node.Value) +} diff --git a/src/build/ast/If.go b/src/build/ast/If.go new file mode 100644 index 0000000..47d98d4 --- /dev/null +++ b/src/build/ast/If.go @@ -0,0 +1,17 @@ +package ast + +import ( + "fmt" + + "git.akyoto.dev/cli/q/src/build/expression" +) + +// If represents an if statement. +type If struct { + Condition *expression.Expression + Body AST +} + +func (node *If) String() string { + return fmt.Sprintf("(if %s %s)", node.Condition, node.Body) +} diff --git a/src/build/ast/Loop.go b/src/build/ast/Loop.go new file mode 100644 index 0000000..5b0dc33 --- /dev/null +++ b/src/build/ast/Loop.go @@ -0,0 +1,12 @@ +package ast + +import "fmt" + +// Loop represents a block of repeatable statements. +type Loop struct { + Body AST +} + +func (node *Loop) String() string { + return fmt.Sprintf("(loop %s)", node.Body) +} diff --git a/src/build/ast/Return.go b/src/build/ast/Return.go new file mode 100644 index 0000000..a56520f --- /dev/null +++ b/src/build/ast/Return.go @@ -0,0 +1,16 @@ +package ast + +import ( + "fmt" + + "git.akyoto.dev/cli/q/src/build/expression" +) + +// Return represents a return statement. +type Return struct { + Value *expression.Expression +} + +func (node *Return) String() string { + return fmt.Sprintf("(return %s)", node.Value) +}