From 70ee349375afd6709855cfb92e69c2343c3e1e90 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Tue, 11 Jun 2024 00:40:19 +0900 Subject: [PATCH] delete editing files --- ast/ast.go~ | 89 ----------------------- parser/parser.go~ | 160 ----------------------------------------- parser/parser_test.go~ | 67 ----------------- 3 files changed, 316 deletions(-) delete mode 100644 ast/ast.go~ delete mode 100644 parser/parser.go~ delete mode 100644 parser/parser_test.go~ diff --git a/ast/ast.go~ b/ast/ast.go~ deleted file mode 100644 index 49118b7..0000000 --- a/ast/ast.go~ +++ /dev/null @@ -1,89 +0,0 @@ -package ast - -import ( - "bytes" - - "github.com/JunNishimura/go-lisp/token" -) - -type Node interface { - TokenLiteral() string - String() string -} - -type Statement interface { - Node - statementNode() -} - -type Expression interface { - Node - expressionNode() -} - -type Program struct { - Statements []Statement -} - -func (p *Program) TokenLiteral() string { - if len(p.Statements) > 0 { - return p.Statements[0].TokenLiteral() - } else { - return "" - } -} - -func (p *Program) String() string { - var out bytes.Buffer - - for _, exp := range p.Statements { - out.WriteString(exp.String()) - } - - return out.String() -} - -type ExpressionStatement struct { - Token token.Token - Expression -} - -func (es *ExpressionStatement) statementNode() {} -func (es *ExpressionStatement) TokenLiteral() string { return es.Token.Literal } -func (es *ExpressionStatement) String() string { - if es.Expression != nil { - return es.Expression.String() - } - return "" -} - -type IntegerLiteral struct { - Token token.Token - Value int64 -} - -func (il *IntegerLiteral) expressionNode() {} -func (il *IntegerLiteral) TokenLiteral() string { return il.Token.Literal } -func (il *IntegerLiteral) String() string { return il.Token.Literal } - -type PrefixExpression struct { - Token token.Token - Operator string - Operands []Expression -} - -func (pe *PrefixExpression) expressionNode() {} -func (pe *PrefixExpression) TokenLiteral() string { return pe.Token.Literal } -func (pe *PrefixExpression) String() string { - var out bytes.Buffer - - out.WriteString("(") - out.WriteString(pe.Operator) - for _, operand := range pe.Operands { - out.WriteString(" ") - out.WriteString(operand.String()) - } - out.WriteString(")") - - return out.String() -} diff --git a/parser/parser.go~ b/parser/parser.go~ deleted file mode 100644 index d97d479..0000000 --- a/parser/parser.go~ +++ /dev/null @@ -1,160 +0,0 @@ -package parser - -// import ( -// "fmt" -// "strconv" - -// "github.com/JunNishimura/go-lisp/ast" -// "github.com/JunNishimura/go-lisp/lexer" -// "github.com/JunNishimura/go-lisp/token" -// ) - -// const ( -// _ int = iota -// LOWEST -// SUM // + -// PRODUCT // * -// ) - -// type ( -// prefixParseFn func() ast.Expression -// ) - -// type Parser struct { -// l *lexer.Lexer - -// curToken token.Token -// peekToken token.Token - -// errors []string - -// prefixParseFns map[token.TokenType]prefixParseFn -// } - -// func New(l *lexer.Lexer) *Parser { -// p := &Parser{ -// l: l, -// errors: []string{}, -// } - -// p.nextToken() -// p.nextToken() - -// p.prefixParseFns = make(map[token.TokenType]prefixParseFn) -// p.registerPrefix(token.INT, p.parseIntegerLiteral) -// p.registerPrefix(token.PLUS, p.parsePrefixExpression) -// p.registerPrefix(token.MINUS, p.parsePrefixExpression) -// p.registerPrefix(token.ASTERISK, p.parsePrefixExpression) -// p.registerPrefix(token.SLASH, p.parsePrefixExpression) - -// return p -// } - -// func (p *Parser) Errors() []string { -// return p.errors -// } - -// func (p *Parser) curError(t token.TokenType) { -// msg := fmt.Sprintf("expected current token to be %s, got %s instead", t, p.curToken.Type) -// p.errors = append(p.errors, msg) -// } - -// func (p *Parser) peekError(t token.TokenType) { -// msg := fmt.Sprintf("expected next token to be %s, got %s instead", t, p.peekToken.Type) -// p.errors = append(p.errors, msg) -// } - -// func (p *Parser) nextToken() { -// p.curToken = p.peekToken -// p.peekToken = p.l.NextToken() -// } - -// func (p *Parser) ParseProgram() *ast.Program { -// program := &ast.Program{} -// program.Statements = []ast.Statement{} - -// for p.curToken.Type != token.EOF { -// statement := p.parseStatement() -// if statement != nil { -// program.Statements = append(program.Statements, statement) -// } -// p.nextToken() -// } - -// return program -// } - -// func (p *Parser) parseStatement() ast.Statement { -// return p.parseExpressionStatement() -// } - -// func (p *Parser) parseExpressionStatement() *ast.ExpressionStatement { -// stmt := &ast.ExpressionStatement{Token: p.curToken} - -// if !p.curTokenIs(token.LPAREN) { -// p.curError(token.LPAREN) -// return nil -// } -// p.nextToken() - -// stmt.Expression = p.parseExpression(LOWEST) - -// if !p.curTokenIs(token.RPAREN) { -// p.curError(token.RPAREN) -// return nil -// } - -// p.nextToken() - -// return stmt -// } - -// func (p *Parser) curTokenIs(t token.TokenType) bool { -// return p.curToken.Type == t -// } - -// func (p *Parser) peekTokenIs(t token.TokenType) bool { -// return p.peekToken.Type == t -// } - -// func (p *Parser) parseExpression(precedence int) ast.Expression { -// prefix := p.prefixParseFns[p.curToken.Type] -// if prefix == nil { -// return nil -// } -// leftExp := prefix() - -// return leftExp -// } - -// func (p *Parser) registerPrefix(tokenType token.TokenType, fn prefixParseFn) { -// p.prefixParseFns[tokenType] = fn -// } - -// func (p *Parser) parsePrefixExpression() ast.Expression { -// expression := &ast.PrefixExpression{ -// Token: p.curToken, -// Operator: p.curToken.Literal, -// } - -// p.nextToken() - -// for !p.curTokenIs(token.RPAREN) { -// operand := p.parseExpression -// } -// } - -// func (p *Parser) parseIntegerLiteral() ast.Expression { -// lit := &ast.IntegerLiteral{Token: p.curToken} - -// value, err := strconv.ParseInt(p.curToken.Literal, 0, 64) -// if err != nil { -// msg := fmt.Sprintf("could not parse %q as integer", p.curToken.Literal) -// p.errors = append(p.errors, msg) -// return nil -// } - -// lit.Value = value - -// return lit -// } diff --git a/parser/parser_test.go~ b/parser/parser_test.go~ deleted file mode 100644 index babd171..0000000 --- a/parser/parser_test.go~ +++ /dev/null @@ -1,67 +0,0 @@ -package parser - -// import ( -// "testing" - -// "github.com/JunNishimura/go-lisp/ast" -// "github.com/JunNishimura/go-lisp/lexer" -// ) - -// func checkParserErrors(t *testing.T, p *Parser) { -// errors := p.Errors() -// if len(errors) == 0 { -// return -// } - -// t.Errorf("parser has %d errors", len(errors)) -// for _, msg := range errors { -// t.Errorf("parser error: %q", msg) -// } -// t.FailNow() -// } - -// func TestExpressions(t *testing.T) { -// input := ` -// (+ 1 2) -// (- 3 4) -// (* 5 6) -// (/ 7 8) -// ` -// l := lexer.New(input) -// p := New(l) - -// program := p.ParseProgram() -// if program == nil { -// t.Fatalf("ParseProgram() returned nil") -// } -// if len(program.Statements) != 4 { -// t.Fatalf("program.Statements does not contain 4 statements. got=%d", len(program.Statements)) -// } -// } - -// func TestIntegerLiteralExpression(t *testing.T) { -// input := "(1)" - -// l := lexer.New(input) -// p := New(l) -// program := p.ParseProgram() - -// if len(program.Statements) != 1 { -// t.Fatalf("program.Statements does not contain 1 statements. got=%d", len(program.Statements)) -// } -// stmt, ok := program.Statements[0].(*ast.ExpressionStatement) -// if !ok { -// t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0]) -// } - -// literal, ok := stmt.Expression.(*ast.IntegerLiteral) -// if !ok { -// t.Fatalf("exp not *ast.IntegerLiteral. got=%T", stmt.Expression) -// } -// if literal.Value != 1 { -// t.Fatalf("literal.Value not %d. got=%d", 1, literal.Value) -// } -// if literal.TokenLiteral() != "1" { -// t.Fatalf("literal.TokenLiteral not %s. got=%s", "1", literal.TokenLiteral()) -// } -// }