48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package parser
|
|
|
|
import "git.tebibyte.media/arf/arf/lexer"
|
|
import "git.tebibyte.media/arf/arf/infoerr"
|
|
|
|
// parseMeta parsese the metadata header at the top of an arf file.
|
|
func (parser *ParsingOperation) parseMeta () (err error) {
|
|
for {
|
|
err = parser.expect (
|
|
lexer.TokenKindName,
|
|
lexer.TokenKindSeparator)
|
|
if err != nil { return }
|
|
|
|
if parser.token.Is(lexer.TokenKindSeparator) {
|
|
err = parser.nextToken(lexer.TokenKindNewline)
|
|
if err != nil { return }
|
|
|
|
err = parser.nextToken()
|
|
return
|
|
}
|
|
|
|
field := parser.token.Value().(string)
|
|
|
|
err = parser.nextToken(lexer.TokenKindString)
|
|
if err != nil { return }
|
|
value := parser.token.Value().(string)
|
|
|
|
switch field {
|
|
case "author":
|
|
parser.tree.author = value
|
|
case "license":
|
|
parser.tree.license = value
|
|
case "require":
|
|
parser.tree.requires = append(parser.tree.requires, value)
|
|
default:
|
|
parser.token.NewError (
|
|
"unrecognized metadata field: " + field,
|
|
infoerr.ErrorKindError)
|
|
}
|
|
|
|
err = parser.nextToken(lexer.TokenKindNewline)
|
|
if err != nil { return }
|
|
|
|
err = parser.nextToken()
|
|
if err != nil { return }
|
|
}
|
|
}
|