From 6bb1649e0a175b9736d5ae0fef4b04cbef57b328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20B=C3=A4rtschi?= Date: Thu, 14 Nov 2024 09:12:27 +0100 Subject: [PATCH] remove 2 --- 2 | 109 -------------------------------------------------------------- 1 file changed, 109 deletions(-) delete mode 100644 2 diff --git a/2 b/2 deleted file mode 100644 index 634cfaf..0000000 --- a/2 +++ /dev/null @@ -1,109 +0,0 @@ -package ast - -import ( - "strings" - - "git.robaertschi.xyz/robaertschi/thorgot/token" -) - -type Optional[T any] struct { - HasValue bool - Value T -} - -func (o Optional[T]) OrElse(other T) T { - if o.HasValue { - return o.Value - } - - return other -} - -type Indentation int - -func (i Indentation) indent() string { - return strings.Repeat(" ", int(i*4)) -} - -type Node interface { - TokenLiteral() string - String(Indentation) string -} - -type ExpressionNode interface { - Node - expressionNode() -} - -type StatementNode interface { - Node - statementNode() -} - -type Type string - -func (t Type) String() string { - return string(t) -} - -type Block struct { - Token token.Token // the RBrace token - Statements []StatementNode -} - -func (b *Block) TokenLiteral() string { return b.Token.Literal } -func (b *Block) String(i Indentation) string { - var out strings.Builder - - ind := i.indent() - - out.WriteString(ind + "{\n") - for _, statement := range b.Statements { - out.WriteString(statement.String(i + 1)) - } - out.WriteString(ind + "}\n") - - return out.String() -} -func (b *Block) statementNode() {} - -type FunctionArgument struct { - Name string - Type Type -} - -type Function struct { - Token token.Token // the Fn token - Name string - Arguments []FunctionArgument - ReturnType Type - HasReturnType bool - Block Block -} - -func (f *Function) TokenLiteral() string { return f.Token.Literal } -func (f *Function) String(i Indentation) string { - var out strings.Builder - - ind := i.indent() - out.WriteString(ind + "fn " + f.Name + "(") - for i, arg := range f.Arguments { - out.WriteString(arg.Name + " " + arg.Type.String()) - if i != len(f.Arguments)-1 { - out.WriteString(", ") - } - } - out.WriteString(") ") - - if f.HasReturnType { - out.WriteString(f.ReturnType.String() + " ") - } - - out.WriteString(f.Block.String(i)) - - return out.String() -} -func (f *Function) statementNode() {} - -type VariableDefiniton struct { -}