Browse Source

fix some output formatting

master
Brett Langdon 10 years ago
parent
commit
5d1af588b7
2 changed files with 13 additions and 4 deletions
  1. +7
    -2
      ast/nodes.go
  2. +6
    -2
      main.go

+ 7
- 2
ast/nodes.go View File

@ -1,6 +1,10 @@
package ast
import "github.com/brettlangdon/gython/token"
import (
"fmt"
"github.com/brettlangdon/gython/token"
)
type Node interface {
Name() string
@ -29,7 +33,8 @@ func (node *TokenNode) Name() string { return token.TokenNames[node
func (node *TokenNode) Repr() []interface{} {
parts := make([]interface{}, 0)
parts = append(parts, node.Name())
return append(parts, node.Token.Literal)
literal := fmt.Sprintf("%#v", node.Token.Literal)
return append(parts, literal)
}
type BaseNode struct {


+ 6
- 2
main.go View File

@ -15,15 +15,19 @@ func tokenize() {
tok := tokenizer.NextToken()
tokenRange := fmt.Sprintf("%d,%d-%d,%d:", tok.LineStart, tok.ColumnStart, tok.LineEnd, tok.ColumnEnd)
literalRep := fmt.Sprintf("%#v", tok.Literal)
fmt.Printf("%-20s%-15s%15s\n", tokenRange, tok.String(), literalRep)
fmt.Printf("%-20s%-15s%-15s\n", tokenRange, tok.String(), literalRep)
if tok.ID == token.ENDMARKER || tok.ID == token.ERRORTOKEN {
break
}
}
}
func main() {
func parse() {
root, p := parser.ParseReader(os.Stdin)
fmt.Println(p)
fmt.Println(root.Repr())
}
func main() {
parse()
}

Loading…
Cancel
Save