示例#1
0
文件: parser.go 项目: gsrpc/gslang
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
}
示例#2
0
文件: linker.go 项目: gsrpc/gslang
func (linker *_Linker) linkTableNewObj(script *ast.Script, table *ast.Table, args *ast.ArgsTable) {
	if args.Named {

		for _, arg := range args.Args() {

			namedArg := arg.(*ast.NamedArg)

			_, ok := table.Field(namedArg.Name())

			if !ok {
				linker.errorf(ErrFieldName, arg, "unknown table(%s) field(%s)", table, namedArg)
			}

			//TODO : check if field type match the arg expr
		}

		return
	}

	if len(table.Fields) != args.Count() {
		linker.errorf(ErrNewObj, args, "wrong newobj args num for table(%s) : expect %d but got %d", table, len(table.Fields), args.Count())

		//TODO : check if field type match the arg expr
	}
}
示例#3
0
文件: codegen.go 项目: gsrpc/gsrpc
func (codegen *_CodeGen) Table(compiler *gslang.Compiler, tableType *ast.Table) {

	var buff bytes.Buffer

	if err := codegen.tpl.ExecuteTemplate(&buff, "table", tableType); err != nil {
		gserrors.Panicf(err, "exec template(table) for %s error", tableType)
	}

	if gslang.IsException(tableType) {
		codegen.writeJavaFile(exception(tableType.Name()), tableType, buff.Bytes())
	} else {
		codegen.writeJavaFile(tableType.Name(), tableType, buff.Bytes())
	}

}