Fixed lexing to deal with multiple attributes in a row

This commit is contained in:
Brian Evans 2019-11-07 09:39:04 -08:00
parent a01ca88089
commit bd5b41ff96
4 changed files with 29 additions and 2 deletions

5
.gitignore vendored
View File

@ -1 +1,6 @@
*.sgf
sgf2gopher
sgf2gemini
*.map
gophermap
.DS_Store

25
lex.go
View File

@ -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)
}

View File

@ -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 {

Binary file not shown.