naoa
null+****@clear*****
Thu Feb 18 00:50:43 JST 2016
naoa 2016-02-18 00:50:43 +0900 (Thu, 18 Feb 2016) New Revision: 0c664e103aceacc4de1aaf11279a5c51e9c71002 https://github.com/groonga/groonga/commit/0c664e103aceacc4de1aaf11279a5c51e9c71002 Merged 4d60980: Merge pull request #480 from naoa/support-object-literal Message: expr: support object literal argument Modified files: include/groonga/expr.h lib/expr.c lib/grn_ecmascript.lemon Modified: include/groonga/expr.h (+2 -0) =================================================================== --- include/groonga/expr.h 2016-02-16 15:27:07 +0900 (b1376db) +++ include/groonga/expr.h 2016-02-18 00:50:43 +0900 (c1c3bf9) @@ -52,6 +52,8 @@ GRN_API grn_obj *grn_expr_append_const_str(grn_ctx *ctx, grn_obj *expr, grn_operator op, int nargs); GRN_API grn_obj *grn_expr_append_const_int(grn_ctx *ctx, grn_obj *expr, int i, grn_operator op, int nargs); +GRN_API grn_obj *grn_expr_append_const_ptr(grn_ctx *ctx, grn_obj *expr, grn_obj *ptr, + grn_operator op, int nargs); GRN_API grn_rc grn_expr_append_op(grn_ctx *ctx, grn_obj *expr, grn_operator op, int nargs); GRN_API grn_rc grn_expr_get_keywords(grn_ctx *ctx, grn_obj *expr, grn_obj *keywords); Modified: lib/expr.c (+17 -0) =================================================================== --- lib/expr.c 2016-02-16 15:27:07 +0900 (7548bf9) +++ lib/expr.c 2016-02-18 00:50:43 +0900 (f7da12a) @@ -1246,6 +1246,21 @@ grn_expr_append_const_int(grn_ctx *ctx, grn_obj *expr, int i, GRN_API_RETURN(res); } +grn_obj * +grn_expr_append_const_ptr(grn_ctx *ctx, grn_obj *expr, grn_obj *ptr, + grn_operator op, int nargs) +{ + grn_obj *res = NULL; + GRN_API_ENTER; + if ((res = grn_expr_alloc_const(ctx, expr))) { + GRN_PTR_INIT(res, GRN_OBJ_OWN, GRN_DB_OBJECT); + GRN_PTR_SET(ctx, res, ptr); + res->header.impl_flags |= GRN_OBJ_EXPRCONST; + } + grn_expr_append_obj(ctx, expr, res, op, nargs); + GRN_API_RETURN(res); +} + grn_rc grn_expr_append_op(grn_ctx *ctx, grn_obj *expr, grn_operator op, int nargs) { @@ -6283,6 +6298,7 @@ typedef struct { int weight_offset; grn_hash *weight_set; snip_cond *snip_conds; + grn_hash *hash_args; } efs_info; typedef struct { @@ -7497,6 +7513,7 @@ grn_expr_parse(grn_ctx *ctx, grn_obj *expr, efsi.weight_offset = 0; efsi.opt.weight_vector = NULL; efsi.weight_set = NULL; + efsi.hash_args = NULL; if (flags & (GRN_EXPR_SYNTAX_SCRIPT | GRN_EXPR_SYNTAX_OUTPUT_COLUMNS | Modified: lib/grn_ecmascript.lemon (+40 -3) =================================================================== --- lib/grn_ecmascript.lemon 2016-02-16 15:27:07 +0900 (1d81265) +++ lib/grn_ecmascript.lemon 2016-02-18 00:50:43 +0900 (e76261d) @@ -30,6 +30,9 @@ } else { GRN_TEXT_PUTC(ctx, &message, '|'); } + if (efsi->hash_args) { + grn_hash_close(efsi->ctx, efsi->hash_args); + } ERR(GRN_SYNTAX_ERROR, "Syntax error: <%.*s>", (int)GRN_TEXT_LEN(&message), GRN_TEXT_VALUE(&message)); GRN_OBJ_FIN(ctx, &message); @@ -383,13 +386,47 @@ element_list ::= assignment_expression. element_list ::= elision assignment_expression. element_list ::= element_list elision assignment_expression. -object_literal ::= BRACEL property_name_and_value_list BRACER. +object_literal ::= BRACEL property_name_and_value_list BRACER. { + grn_ctx *ctx = efsi->ctx; + grn_expr *e = (grn_expr *)(efsi->e); + grn_expr_append_const_ptr(ctx, (grn_obj *)e, (grn_obj *)efsi->hash_args, + GRN_OP_PUSH, 1); +} property_name_and_value_list ::= . +property_name_and_value_list ::= property_name_and_value. property_name_and_value_list ::= property_name_and_value_list COMMA property_name_and_value. -property_name_and_value ::= property_name COLON assignment_expression. -property_name ::= IDENTIFIER|STRING|DECIMAL. +property_name_and_value ::= property_name COLON assignment_expression. { + grn_ctx *ctx = efsi->ctx; + grn_expr *e = (grn_expr *)(efsi->e); + grn_obj *property = e->codes[e->codes_curr - 3].value; + grn_obj *value = e->codes[e->codes_curr - 1].value; + + if (!efsi->hash_args) { + efsi->hash_args = + grn_hash_create(ctx, NULL, GRN_TABLE_MAX_KEY_SIZE, sizeof(grn_obj), + GRN_OBJ_KEY_VAR_SIZE|GRN_OBJ_TEMPORARY|GRN_HASH_TINY); + } + + if (!efsi->hash_args) { + ERR(GRN_NO_MEMORY_AVAILABLE, + "couldn't create hash table for parsing object literal arguments (%.*s)", + (int)(efsi->str_end - efsi->str), efsi->str); + } else { + void *buf; + if (grn_hash_add(ctx, efsi->hash_args, + GRN_BULK_HEAD(property), GRN_BULK_VSIZE(property), + (void **)&buf, NULL)) { + grn_memcpy(buf, GRN_BULK_HEAD(value), GRN_BULK_VSIZE(value)); + } + e->codes_curr -= 3; + } +} + +property_name ::= IDENTIFIER. +property_name ::= STRING. +property_name ::= DECIMAL. member_expression_part ::= BRACKETL expression BRACKETR. { grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_GET_MEMBER, 2); -------------- next part -------------- HTML����������������������������... ダウンロード