Skip to content

Commit

Permalink
chapter 3 + formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-young1 committed Jun 27, 2023
1 parent 8948e2f commit 47120e9
Show file tree
Hide file tree
Showing 13 changed files with 842 additions and 93 deletions.
34 changes: 17 additions & 17 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (i *Identifier) String() string {

type LetStatement struct {
Token token.Token // the token.LET token
Name *Identifier
Name *Identifier
Value Expression
}

Expand All @@ -87,7 +87,7 @@ func (ls *LetStatement) String() string {
}

type ReturnStatement struct {
Token token.Token // the 'return' token
Token token.Token // the 'return' token
ReturnValue Expression
}

Expand All @@ -100,7 +100,7 @@ func (rs *ReturnStatement) String() string {
var out bytes.Buffer

out.WriteString(rs.TokenLiteral() + " ")

if rs.ReturnValue != nil {
out.WriteString(rs.ReturnValue.String())
}
Expand All @@ -111,7 +111,7 @@ func (rs *ReturnStatement) String() string {
}

type ExpressionStatement struct {
Token token.Token // the first token of the expression
Token token.Token // the first token of the expression
Expression Expression
}

Expand Down Expand Up @@ -144,9 +144,9 @@ func (il *IntegerLiteral) String() string {
}

type PrefixExpression struct {
Token token.Token // prefix token, e.g. !
Token token.Token // prefix token, e.g. !
Operator string
Right Expression
Right Expression
}

func (pe *PrefixExpression) expressionNode() {}
Expand All @@ -165,10 +165,10 @@ func (pe *PrefixExpression) String() string {
}

type InfixExpression struct {
Token token.Token // the operator token, e.g. +
Left Expression
Token token.Token // the operator token, e.g. +
Left Expression
Operator string
Right Expression
Right Expression
}

func (ie *InfixExpression) expressionNode() {}
Expand Down Expand Up @@ -201,8 +201,8 @@ func (b *Boolean) String() string {
}

type IfExpression struct {
Token token.Token // the 'if' token
Condition Expression
Token token.Token // the 'if' token
Condition Expression
Consequence *BlockStatement
Alternative *BlockStatement
}
Expand All @@ -228,7 +228,7 @@ func (ie *IfExpression) String() string {
}

type BlockStatement struct {
Token token.Token // the { token
Token token.Token // the { token
Statements []Statement
}

Expand All @@ -247,9 +247,9 @@ func (bs *BlockStatement) String() string {
}

type FunctionLiteral struct {
Token token.Token // the "fn" token
Token token.Token // the "fn" token
Parameters []*Identifier
Body *BlockStatement
Body *BlockStatement
}

func (fl *FunctionLiteral) expressionNode() {}
Expand All @@ -274,8 +274,8 @@ func (fl *FunctionLiteral) String() string {
}

type CallExpression struct {
Token token.Token // The '(' token
Function Expression // Identifer or FunctionLiteral
Token token.Token // The '(' token
Function Expression // Identifer or FunctionLiteral
Arguments []Expression
}

Expand All @@ -297,4 +297,4 @@ func (ce *CallExpression) String() string {
out.WriteString(")")

return out.String()
}
}
2 changes: 1 addition & 1 deletion ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ func TestString(t *testing.T) {
if program.String() != "let myVar = anotherVar;" {
t.Errorf("program.String() wrong. got=%q", program.String())
}
}
}
Loading

0 comments on commit 47120e9

Please sign in to comment.