Пример #1
0
func (parser *Parser) parseFieldDecl(table *ast.Table) bool {

	token := parser.peek()

	if token.Type != lexer.TokenType('}') {

		for parser.parseAnnotation() {

		}

		typeDecl := parser.expectTypeDecl("expect table(%s) field type declare", table)

		tokenName := parser.expectf(lexer.TokenID, "expect table(%s) field name", table)

		parser.expectf(lexer.TokenType(';'), "expect table(%s) field end tag ;", table)

		name := tokenName.Value.(string)

		field, ok := table.NewField(name, typeDecl)

		if !ok {
			parser.errorf(token.Start, "duplicate table(%s) field(%s)", table, name)
		}

		parser.attachAnnotation(field)

		_setNodePos(field, token.Start, tokenName.End)

		parser.attachComment(field)

		return true
	}

	return false
}