Added metadata parser
This commit is contained in:
@@ -70,7 +70,7 @@ func (parser *ParsingOperation) parse (sourceFile *file.File) (err error) {
|
||||
// expect takes in a list of allowed token kinds, and returns an error if the
|
||||
// current token isn't one of them. If the length of allowed is zero, this
|
||||
// function will not return an error.
|
||||
func (parser *ParsingOperation) expect (allowed []lexer.TokenKind) (err error) {
|
||||
func (parser *ParsingOperation) expect (allowed ...lexer.TokenKind) (err error) {
|
||||
if len(allowed) == 0 { return }
|
||||
|
||||
for _, kind := range allowed {
|
||||
@@ -78,16 +78,17 @@ func (parser *ParsingOperation) expect (allowed []lexer.TokenKind) (err error) {
|
||||
}
|
||||
|
||||
err = file.NewError (
|
||||
parser.token.Location(), 1,
|
||||
parser.token.Location(),
|
||||
"unexpected token", file.ErrorKindError)
|
||||
return
|
||||
}
|
||||
|
||||
// nextToken is the same as expect, but it advances to the next token first.
|
||||
func (parser *ParsingOperation) nextToken (allowed []lexer.TokenKind) (err error) {
|
||||
func (parser *ParsingOperation) nextToken (allowed ...lexer.TokenKind) (err error) {
|
||||
parser.tokenIndex ++
|
||||
if parser.tokenIndex >= len(parser.tokens) { return io.EOF }
|
||||
parser.token = parser.tokens[parser.tokenIndex]
|
||||
|
||||
|
||||
err = parser.expect(allowed...)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user