Exemple #1
0
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
	}
}
Exemple #2
0
func (parser *Parser) parseArgsTable() *ast.ArgsTable {

	token := parser.peek()

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

		return nil
	}

	parser.next()

	token = parser.peek()

	if token.Value == lexer.TokenType(')') {
		return ast.NewArgsTable(true)
	}

	token = parser.peek()

	start := token.Start

	end := token.End

	var args *ast.ArgsTable

	// this is named args table
	if token.Type == lexer.TokenLABEL {
		args = ast.NewArgsTable(true)

		for {

			token := parser.expectf(lexer.TokenLABEL, "expect arg label")

			label := token.Value.(string)

			arg := parser.expectArg("expect label(%s) value", label)

			parser.D("lable:%s", label)

			namedArg := ast.NewNamedArg(label, arg)

			_, end = Pos(arg)

			_setNodePos(namedArg, token.Start, end)

			args.Append(namedArg)

			if parser.peek().Type != lexer.TokenType(',') {
				break
			}

			parser.next()
		}

	} else {

		args = ast.NewArgsTable(false)

		for {

			arg := parser.expectArg("expect arg")

			args.Append(arg)

			if parser.peek().Type != lexer.TokenType(',') {
				break
			}

			parser.next()
		}
	}

	_setNodePos(args, start, end)

	parser.expectf(lexer.TokenType(')'), "arg table must end with ')'")

	return args
}
Exemple #3
0
func (linker *_Linker) linkArgsTable(script *ast.Script, argsTable *ast.ArgsTable) {
	for _, arg := range argsTable.Args() {
		linker.linkExpr(script, arg)
	}
}