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