Reorganized file structure

This commit is contained in:
Eduard Urbach 2024-07-11 12:04:51 +02:00
parent c2401bf826
commit 7b18056006
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
7 changed files with 95 additions and 58 deletions

View File

@ -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)
}

19
src/build/ast/Assign.go Normal file
View File

@ -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)
}

12
src/build/ast/Call.go Normal file
View File

@ -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()
}

18
src/build/ast/Define.go Normal file
View File

@ -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)
}

17
src/build/ast/If.go Normal file
View File

@ -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)
}

12
src/build/ast/Loop.go Normal file
View File

@ -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)
}

16
src/build/ast/Return.go Normal file
View File

@ -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)
}