Fixed lexing to deal with multiple attributes in a row
This commit is contained in:
parent
a01ca88089
commit
bd5b41ff96
|
@ -1 +1,6 @@
|
|||
*.sgf
|
||||
sgf2gopher
|
||||
sgf2gemini
|
||||
*.map
|
||||
gophermap
|
||||
.DS_Store
|
||||
|
|
25
lex.go
25
lex.go
|
@ -111,6 +111,21 @@ func (l *lexed) eatSubTree() {
|
|||
}
|
||||
}
|
||||
|
||||
func (l *lexed) eatVal() {
|
||||
eatvalLoop:
|
||||
for {
|
||||
switch l.ts[l.curs].kind {
|
||||
case CVAL:
|
||||
break eatvalLoop
|
||||
default:
|
||||
err := l.next()
|
||||
if err != nil {
|
||||
break eatvalLoop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *lexed) parseNode() (node, error) {
|
||||
n := make(node, 0, 5)
|
||||
nodeloop:
|
||||
|
@ -128,6 +143,8 @@ nodeloop:
|
|||
break nodeloop
|
||||
}
|
||||
n = append(n, p)
|
||||
case OVAL:
|
||||
l.eatVal()
|
||||
}
|
||||
err := l.next()
|
||||
if err != nil {
|
||||
|
@ -163,8 +180,12 @@ proploop:
|
|||
p.value = b.String()
|
||||
break proploop
|
||||
case OPAREN, CPAREN:
|
||||
l.prev()
|
||||
return p, fmt.Errorf("Unexpected paren, tossing up the chain")
|
||||
if k {
|
||||
b.WriteRune(l.ts[l.curs].val)
|
||||
} else {
|
||||
l.prev()
|
||||
return p, fmt.Errorf("Unexpected paren, tossing up the chain")
|
||||
}
|
||||
case TEXT:
|
||||
b.WriteRune(l.ts[l.curs].val)
|
||||
}
|
||||
|
|
1
main.go
1
main.go
|
@ -503,6 +503,7 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
ast := generateAST(flag.Args()[0])
|
||||
fmt.Println(ast)
|
||||
game := gameStruct(ast)
|
||||
numMoves := len(ast) - 1
|
||||
if numMoves > 0 {
|
||||
|
|
BIN
sgf2gemini
BIN
sgf2gemini
Binary file not shown.
Loading…
Reference in New Issue