summaryrefslogtreecommitdiff
path: root/storage/mroonga/vendor/groonga/lib/grn_ecmascript.lemon
blob: 1d812655d70178c6f8180a844757b229fb3feeee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/* -*- mode: c; c-basic-offset: 2 -*- */
%name grn_expr_parser
%token_prefix GRN_EXPR_TOKEN_
%include {
#define assert GRN_ASSERT
}

%token_type { int }

%type suppress_unused_variable_warning { void * }
%destructor suppress_unused_variable_warning {
  (void)efsi;
}

%extra_argument { efs_info *efsi }

%syntax_error {
  {
    grn_ctx *ctx = efsi->ctx;
    if (ctx->rc == GRN_SUCCESS) {
      grn_obj message;
      GRN_TEXT_INIT(&message, 0);
      GRN_TEXT_PUT(ctx, &message, efsi->str, efsi->cur - efsi->str);
      GRN_TEXT_PUTC(ctx, &message, '|');
      if (efsi->cur < efsi->str_end) {
        GRN_TEXT_PUTC(ctx, &message, efsi->cur[0]);
        GRN_TEXT_PUTC(ctx, &message, '|');
        GRN_TEXT_PUT(ctx, &message,
                     efsi->cur + 1, efsi->str_end - (efsi->cur + 1));
      } else {
        GRN_TEXT_PUTC(ctx, &message, '|');
      }
      ERR(GRN_SYNTAX_ERROR, "Syntax error: <%.*s>",
          (int)GRN_TEXT_LEN(&message), GRN_TEXT_VALUE(&message));
      GRN_OBJ_FIN(ctx, &message);
    }
  }
}

input ::= query.
input ::= expression.
input ::= START_OUTPUT_COLUMNS output_columns.
input ::= START_ADJUSTER adjuster.

query ::= query_element.
query ::= query query_element. {
  grn_expr_append_op(efsi->ctx, efsi->e, grn_int32_value_at(&efsi->op_stack, -1), 2);
}
query ::= query LOGICAL_AND query_element. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_AND, 2);
}
query ::= query LOGICAL_AND_NOT query_element.{
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_AND_NOT, 2);
}
query ::= query LOGICAL_OR query_element.{
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_OR, 2);
}

query_element ::= QSTRING.
query_element ::= PARENL query PARENR.

query_element ::= RELATIVE_OP query_element.{
  int mode;
  GRN_INT32_POP(&efsi->mode_stack, mode);
}
query_element ::= IDENTIFIER RELATIVE_OP query_element. {
  int mode;
  grn_obj *c;
  GRN_PTR_POP(&efsi->column_stack, c);
  GRN_INT32_POP(&efsi->mode_stack, mode);
  switch (mode) {
  case GRN_OP_NEAR :
  case GRN_OP_NEAR2 :
    {
      int max_interval;
      GRN_INT32_POP(&efsi->max_interval_stack, max_interval);
    }
    break;
  case GRN_OP_SIMILAR :
    {
      int similarity_threshold;
      GRN_INT32_POP(&efsi->similarity_threshold_stack, similarity_threshold);
    }
    break;
  default :
    break;
  }
}
query_element ::= BRACEL expression BRACER. {
  efsi->flags = efsi->default_flags;
}
query_element ::= EVAL primary_expression. {
  efsi->flags = efsi->default_flags;
}

expression ::= assignment_expression.
expression ::= expression COMMA assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_COMMA, 2);
}

assignment_expression ::= conditional_expression.
assignment_expression ::= lefthand_side_expression ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression STAR_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_STAR_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression SLASH_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SLASH_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression MOD_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_MOD_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression PLUS_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_PLUS_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression MINUS_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_MINUS_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression SHIFTL_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SHIFTL_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression SHIFTR_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SHIFTR_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression SHIFTRR_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SHIFTRR_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression AND_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_AND_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression XOR_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_XOR_ASSIGN, 2);
}
assignment_expression ::= lefthand_side_expression OR_ASSIGN assignment_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_OR_ASSIGN, 2);
}

conditional_expression ::= logical_or_expression.
conditional_expression ::= logical_or_expression QUESTION(A) assignment_expression COLON(B) assignment_expression. {
  grn_expr *e = (grn_expr *)efsi->e;
  e->codes[A].nargs = B - A;
  e->codes[B].nargs = e->codes_curr - B - 1;
}

logical_or_expression ::= logical_and_expression.
logical_or_expression ::= logical_or_expression LOGICAL_OR logical_and_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_OR, 2);
}

logical_and_expression ::= bitwise_or_expression.
logical_and_expression ::= logical_and_expression LOGICAL_AND bitwise_or_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_AND, 2);
}
logical_and_expression ::= logical_and_expression LOGICAL_AND_NOT bitwise_or_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_AND_NOT, 2);
}

bitwise_or_expression ::= bitwise_xor_expression.
bitwise_or_expression ::= bitwise_or_expression BITWISE_OR bitwise_xor_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_BITWISE_OR, 2);
}

bitwise_xor_expression ::= bitwise_and_expression.
bitwise_xor_expression ::= bitwise_xor_expression BITWISE_XOR bitwise_and_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_BITWISE_XOR, 2);
}

bitwise_and_expression ::= equality_expression.
bitwise_and_expression ::= bitwise_and_expression BITWISE_AND equality_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_BITWISE_AND, 2);
}

equality_expression ::= relational_expression.
equality_expression ::= equality_expression EQUAL relational_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_EQUAL, 2);
}
equality_expression ::= equality_expression NOT_EQUAL relational_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_NOT_EQUAL, 2);
}

relational_expression ::= shift_expression.
relational_expression ::= relational_expression LESS shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_LESS, 2);
}
relational_expression ::= relational_expression GREATER shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_GREATER, 2);
}
relational_expression ::= relational_expression LESS_EQUAL shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_LESS_EQUAL, 2);
}
relational_expression ::= relational_expression GREATER_EQUAL shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_GREATER_EQUAL, 2);
}
relational_expression ::= relational_expression IN shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_IN, 2);
}
relational_expression ::= relational_expression MATCH shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_MATCH, 2);
}
relational_expression ::= relational_expression NEAR shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_NEAR, 2);
}
relational_expression ::= relational_expression NEAR2 shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_NEAR2, 2);
}
relational_expression ::= relational_expression SIMILAR shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SIMILAR, 2);
}
relational_expression ::= relational_expression TERM_EXTRACT shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_TERM_EXTRACT, 2);
}
relational_expression ::= relational_expression LCP shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_LCP, 2);
}
relational_expression ::= relational_expression PREFIX shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_PREFIX, 2);
}
relational_expression ::= relational_expression SUFFIX shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SUFFIX, 2);
}
relational_expression ::= relational_expression REGEXP shift_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_REGEXP, 2);
}

shift_expression ::= additive_expression.
shift_expression ::= shift_expression SHIFTL additive_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SHIFTL, 2);
}
shift_expression ::= shift_expression SHIFTR additive_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SHIFTR, 2);
}
shift_expression ::= shift_expression SHIFTRR additive_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SHIFTRR, 2);
}

additive_expression ::= multiplicative_expression.
additive_expression ::= additive_expression PLUS multiplicative_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_PLUS, 2);
}
additive_expression ::= additive_expression MINUS multiplicative_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_MINUS, 2);
}

multiplicative_expression ::= unary_expression.
multiplicative_expression ::= multiplicative_expression STAR unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_STAR, 2);
}
multiplicative_expression ::= multiplicative_expression SLASH unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_SLASH, 2);
}
multiplicative_expression ::= multiplicative_expression MOD unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_MOD, 2);
}

unary_expression ::= postfix_expression.
unary_expression ::= DELETE unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_DELETE, 1);
}
unary_expression ::= INCR unary_expression. {
  grn_ctx *ctx = efsi->ctx;
  grn_expr *e = (grn_expr *)(efsi->e);
  grn_expr_dfi *dfi_;
  unsigned int const_p;

  DFI_POP(e, dfi_);
  const_p = CONSTP(dfi_->code->value);
  DFI_PUT(e, dfi_->type, dfi_->domain, dfi_->code);
  if (const_p) {
    ERR(GRN_SYNTAX_ERROR,
        "constant can't be incremented (%.*s)",
        (int)(efsi->str_end - efsi->str), efsi->str);
  } else {
    grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_INCR, 1);
  }
}
unary_expression ::= DECR unary_expression. {
  grn_ctx *ctx = efsi->ctx;
  grn_expr *e = (grn_expr *)(efsi->e);
  grn_expr_dfi *dfi_;
  unsigned int const_p;

  DFI_POP(e, dfi_);
  const_p = CONSTP(dfi_->code->value);
  DFI_PUT(e, dfi_->type, dfi_->domain, dfi_->code);
  if (const_p) {
    ERR(GRN_SYNTAX_ERROR,
        "constant can't be decremented (%.*s)",
        (int)(efsi->str_end - efsi->str), efsi->str);
  } else {
    grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_DECR, 1);
  }
}
unary_expression ::= PLUS unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_PLUS, 1);
}
unary_expression ::= MINUS unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_MINUS, 1);
}
unary_expression ::= NOT unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_NOT, 1);
}
unary_expression ::= BITWISE_NOT unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_BITWISE_NOT, 1);
}
unary_expression ::= ADJUST unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_ADJUST, 1);
}
unary_expression ::= EXACT unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_EXACT, 1);
}
unary_expression ::= PARTIAL unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_PARTIAL, 1);
}
unary_expression ::= UNSPLIT unary_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_UNSPLIT, 1);
}

postfix_expression ::= lefthand_side_expression.
postfix_expression ::= lefthand_side_expression INCR. {
  grn_ctx *ctx = efsi->ctx;
  grn_expr *e = (grn_expr *)(efsi->e);
  grn_expr_dfi *dfi_;
  unsigned int const_p;

  DFI_POP(e, dfi_);
  const_p = CONSTP(dfi_->code->value);
  DFI_PUT(e, dfi_->type, dfi_->domain, dfi_->code);
  if (const_p) {
    ERR(GRN_SYNTAX_ERROR,
        "constant can't be incremented (%.*s)",
        (int)(efsi->str_end - efsi->str), efsi->str);
  } else {
    grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_INCR_POST, 1);
  }
}
postfix_expression ::= lefthand_side_expression DECR. {
  grn_ctx *ctx = efsi->ctx;
  grn_expr *e = (grn_expr *)(efsi->e);
  grn_expr_dfi *dfi_;
  unsigned int const_p;

  DFI_POP(e, dfi_);
  const_p = CONSTP(dfi_->code->value);
  DFI_PUT(e, dfi_->type, dfi_->domain, dfi_->code);
  if (const_p) {
    ERR(GRN_SYNTAX_ERROR,
        "constant can't be decremented (%.*s)",
        (int)(efsi->str_end - efsi->str), efsi->str);
  } else {
    grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_DECR_POST, 1);
  }
}

lefthand_side_expression ::= call_expression.
lefthand_side_expression ::= member_expression.

call_expression ::= member_expression arguments(A). {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_CALL, A);
}

member_expression ::= primary_expression.
member_expression ::= member_expression member_expression_part.

primary_expression ::= object_literal.
primary_expression ::= PARENL expression PARENR.
primary_expression ::= IDENTIFIER.
primary_expression ::= array_literal.
primary_expression ::= DECIMAL.
primary_expression ::= HEX_INTEGER.
primary_expression ::= STRING.
primary_expression ::= BOOLEAN.
primary_expression ::= NULL.

array_literal ::= BRACKETL elision BRACKETR.
array_literal ::= BRACKETL element_list elision BRACKETR.
array_literal ::= BRACKETL element_list BRACKETR.

elision ::= COMMA.
elision ::= elision COMMA.

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.

property_name_and_value_list ::= .
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.

member_expression_part ::= BRACKETL expression BRACKETR. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_GET_MEMBER, 2);
}
member_expression_part ::= DOT IDENTIFIER.

arguments(A) ::= PARENL argument_list(B) PARENR. { A = B; }
argument_list(A) ::= . { A = 0; }
argument_list(A) ::= assignment_expression. { A = 1; }
argument_list(A) ::= argument_list(B) COMMA assignment_expression. { A = B + 1; }

output_columns(N_STACKED_COLUMNS) ::= . {
  N_STACKED_COLUMNS = 0;
}
output_columns(N_STACKED_COLUMNS) ::= output_column(IGNORED). {
  if (IGNORED) {
    N_STACKED_COLUMNS = 0;
  } else {
    N_STACKED_COLUMNS = 1;
  }
}
output_columns(N_STACKED_COLUMNS) ::=
   output_columns(SUB_N_STACKED_COLUMNS) COMMA output_column(IGNORED). {
  if (IGNORED) {
    N_STACKED_COLUMNS = SUB_N_STACKED_COLUMNS;
  } else {
    if (SUB_N_STACKED_COLUMNS == 1) {
      grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_COMMA, 2);
    }
    N_STACKED_COLUMNS = 1;
  }
}

output_column(IGNORED) ::= STAR. {
  grn_ctx *ctx = efsi->ctx;
  grn_obj *expr = efsi->e;
  grn_expr *e = (grn_expr *)expr;
  grn_obj *variable = grn_expr_get_var_by_offset(ctx, expr, 0);
  if (variable) {
    grn_id table_id = GRN_OBJ_GET_DOMAIN(variable);
    grn_obj *table = grn_ctx_at(ctx, table_id);
    grn_obj columns_buffer;
    grn_obj **columns;
    int i, n_columns;

    GRN_PTR_INIT(&columns_buffer, GRN_OBJ_VECTOR, GRN_ID_NIL);
    grn_obj_columns(ctx, table, "*", strlen("*"), &columns_buffer);
    n_columns = GRN_BULK_VSIZE(&columns_buffer) / sizeof(grn_obj *);
    columns = (grn_obj **)GRN_BULK_HEAD(&columns_buffer);

    for (i = 0; i < n_columns; i++) {
      if (i > 0) {
        grn_expr_append_op(ctx, expr, GRN_OP_COMMA, 2);
      }
      grn_expr_append_const(ctx, expr, columns[i], GRN_OP_GET_VALUE, 1);
      GRN_PTR_PUT(ctx, &e->objs, columns[i]);
    }

    GRN_OBJ_FIN(ctx, &columns_buffer);

    if (n_columns > 0) {
      IGNORED = GRN_FALSE;
    } else {
      IGNORED = GRN_TRUE;
    }
  } else {
    /* TODO: report error */
    IGNORED = GRN_TRUE;
  }
}
output_column(IGNORED) ::= NONEXISTENT_COLUMN. {
  IGNORED = GRN_TRUE;
}
output_column(IGNORED) ::= assignment_expression. {
  IGNORED = GRN_FALSE;
}

adjuster ::= .
adjuster ::= adjust_expression.
adjuster ::= adjuster PLUS adjust_expression. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_PLUS, 2);
}

adjust_expression ::= adjust_match_expression.
adjust_expression ::= adjust_match_expression STAR DECIMAL. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_STAR, 2);
}

adjust_match_expression ::= IDENTIFIER MATCH STRING. {
  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_MATCH, 2);
}