|
1 | 1 | %{ |
2 | 2 | #include<stdlib.h> |
3 | 3 | #include<stdio.h> |
4 | | -#include"monq.h" |
| 4 | +#include"monq.h" |
5 | 5 | #include"monq_gram.h" |
6 | 6 | #include<string.h> |
7 | 7 |
|
8 | | - |
9 | 8 | externintyylex(); |
| 9 | +externvoidyyerror(char *s); |
10 | 10 |
|
| 11 | +int position =1; |
| 12 | +char *inputString; |
| 13 | + |
| 14 | +void |
| 15 | +yyerror(char *s) |
| 16 | + { |
| 17 | +int val; |
| 18 | + position -= yyleng; |
| 19 | + val = position; |
| 20 | + position =1; |
| 21 | +ereport(ERROR, |
| 22 | + (errcode(ERRCODE_SYNTAX_ERROR), |
| 23 | +errmsg("bad MongoDB representation"), |
| 24 | +/* translator: first %s is typically "syntax error" */ |
| 25 | +errdetail("%s\"%s\" on line %d position %d\n%s\n%*c", s, yytext, yylineno, val,inputString,val,'^'))); |
| 26 | + |
| 27 | +exit(0); |
| 28 | + } |
11 | 29 | %} |
12 | 30 |
|
13 | 31 | %optionyylineno |
|
19 | 37 |
|
20 | 38 | [/][/].*\n ;// comment |
21 | 39 |
|
22 | | -[0-9]+{ yylval.strval=strdup(yytext);return INT; } |
23 | | -[0-9]+\.[0-9]+{ yylval.strval=strdup(yytext);return DOUBLE; } |
24 | | -(true|false|TRUE|FALSE){ yylval.boolval=(strcmp(strdup(yytext),"true")==0);return BOOLEAN; } |
25 | | - |
26 | | -\{{return LSCOPE; } |
27 | | -\}{return RSCOPE; } |
28 | | -\[{return LSQBRACKET; } |
29 | | -\]{return RSQBRACKET; } |
| 40 | +[0-9]+{ yylval.strval=strdup(yytext); position += yyleng;return INT; } |
| 41 | +[0-9]+\.[0-9]+{ yylval.strval=strdup(yytext); position += yyleng;return DOUBLE; } |
| 42 | +(true|false|TRUE|FALSE){ yylval.boolval=(strcmp(strdup(yytext),"true")==0); position += yyleng;return BOOLEAN; } |
30 | 43 |
|
31 | | -\,{return COMMA; } |
| 44 | +\{{ position += yyleng;return LSCOPE; } |
| 45 | +\}{ position += yyleng;return RSCOPE; } |
| 46 | +\[{ position += yyleng;return LSQBRACKET; } |
| 47 | +\]{ position += yyleng;return RSQBRACKET; } |
32 | 48 |
|
33 | | -\:{ yylval.valop_type=_EQ;return EQ; } |
34 | | -\$(eq|EQ){ yylval.valop_type=_EQ;return EQ; } |
35 | | -\$(lt|LT){ yylval.valop_type=_LESS;return LESS; } |
36 | | -\$(lte|LTE){ yylval.valop_type=_LESSEQ;return LESSEQ; } |
37 | | -\$(gt|GT){ yylval.valop_type=_GREAT;return GREAT; } |
38 | | -\$(gte|GTE){ yylval.valop_type=_GREATEQ;return GREATEQ; } |
39 | | -\$(ne|NE){ yylval.valop_type=_NOTEQ;return NOTEQ; } |
40 | | -\$type{ yylval.valop_type=_TYPE;return TYPE; } |
41 | | -\$size{ yylval.valop_type=_SIZE;return SIZE; } |
42 | | -\$exists{ yylval.valop_type=_EXISTS;return EXISTS; } |
| 49 | +\,{ position += yyleng;return COMMA; } |
43 | 50 |
|
44 | | -\$in { yylval.aop_type=_IN;return IN; } |
45 | | -\$nin{ yylval.aop_type=_NIN;return NIN; } |
46 | | -\$all{ yylval.aop_type=_ALL;return ALL; } |
| 51 | +\:{ position += yyleng; yylval.valop_type=_EQ;return EQ; } |
| 52 | +\$(eq|EQ){ position += yyleng; yylval.valop_type=_EQ;return EQ; } |
| 53 | +\$(lt|LT){ position += yyleng; yylval.valop_type=_LESS;return LESS; } |
| 54 | +\$(lte|LTE){ position += yyleng; yylval.valop_type=_LESSEQ;return LESSEQ; } |
| 55 | +\$(gt|GT){ position += yyleng; yylval.valop_type=_GREAT;return GREAT; } |
| 56 | +\$(gte|GTE){ position += yyleng; yylval.valop_type=_GREATEQ;return GREATEQ; } |
| 57 | +\$(ne|NE){ position += yyleng; yylval.valop_type=_NOTEQ;return NOTEQ; } |
| 58 | +\$type{ position += yyleng; yylval.valop_type=_TYPE;return TYPE; } |
| 59 | +\$size{ position += yyleng; yylval.valop_type=_SIZE;return SIZE; } |
| 60 | +\$exists{ position += yyleng; yylval.valop_type=_EXISTS;return EXISTS; } |
47 | 61 |
|
48 | | -\$not {return NOT;} |
| 62 | +\$in { position += yyleng; yylval.aop_type=_IN;return IN; } |
| 63 | +\$nin{ position += yyleng; yylval.aop_type=_NIN;return NIN; } |
| 64 | +\$all{ position += yyleng; yylval.aop_type=_ALL;return ALL; } |
49 | 65 |
|
50 | | -\$where{return WHERE_OPERATOR;} |
| 66 | +\$not{position += yyleng;return NOT;} |
51 | 67 |
|
52 | | -\$elemMatch{returnELEMMATCH; } |
| 68 | +\$where{ position += yyleng;returnWHERE_OPERATOR; } |
53 | 69 |
|
54 | | -\$or { yylval.exop_type=_OR;return OR; } |
55 | | -\$nor { yylval.exop_type=_NOR;return NOR; } |
56 | | -\$and{ yylval.exop_type=_AND;return AND; } |
| 70 | +\$elemMatch{ position += yyleng;return ELEMMATCH; } |
57 | 71 |
|
58 | | -\$search{return SEARCH_OPERATOR; } |
59 | | -\$text{return TEXT_OPERATOR; } |
60 | | -\$language{return LANGUAGE_OPERATOR; } |
61 | | -\$caseSensitive{return CASE_SENSITIVE_OPERATOR; } |
62 | | -\$diacriticSensitive{return DIACRITIC_SENSITIVE_OPERATOR; } |
| 72 | +\$or { position += yyleng; yylval.exop_type=_OR;return OR; } |
| 73 | +\$nor { position += yyleng; yylval.exop_type=_NOR;return NOR; } |
| 74 | +\$and{ position += yyleng; yylval.exop_type=_AND;return AND; } |
63 | 75 |
|
64 | | -\$comment{return COMMENT_OPERATOR; } |
| 76 | +\$search{ position += yyleng;return SEARCH_OPERATOR; } |
| 77 | +\$text{ position += yyleng;return TEXT_OPERATOR; } |
| 78 | +\$language{ position += yyleng;return LANGUAGE_OPERATOR; } |
| 79 | +\$caseSensitive{ position += yyleng;return CASE_SENSITIVE_OPERATOR; } |
| 80 | +\$diacriticSensitive{ position += yyleng;return DIACRITIC_SENSITIVE_OPERATOR; } |
65 | 81 |
|
66 | | -\$mod{returnMOD_OPERATOR; } |
| 82 | +\$comment{ position += yyleng;returnCOMMENT_OPERATOR; } |
67 | 83 |
|
68 | | -\"\"{yylval.strval=strdup(yytext);returnSTRING; } |
| 84 | +\$mod{position += yyleng;returnMOD_OPERATOR; } |
69 | 85 |
|
70 | | -[0-9a-zA-Z]+{yylval.strval=strdup(yytext);returnKEY_STRING; } |
| 86 | +\"\"{ position += yyleng;yylval.strval=strdup(yytext);returnSTRING; } |
71 | 87 |
|
72 | | -\"[\.0-9a-zA-Z]*\"{ |
73 | | -char *str =strdup(yytext+1); |
74 | | -str[yyleng-2] ='\0'; |
75 | | -yylval.strval = str; |
76 | | -return KEY_STRING; |
77 | | -} |
| 88 | +[0-9a-zA-Z]+ { position += yyleng; yylval.strval=strdup(yytext);return KEY_STRING; } |
78 | 89 |
|
79 | | -\"[(\\0)\.\, 0-9a-zA-Z]*\"{ yylval.strval=strdup(yytext);return STRING; } |
| 90 | +\"[\.0-9a-zA-Z]*\" { |
| 91 | +char *str =strdup(yytext+1); |
| 92 | + str[yyleng-2] ='\0'; |
| 93 | + yylval.strval = str; |
| 94 | + position += yyleng; |
| 95 | +return KEY_STRING; |
| 96 | + } |
80 | 97 |
|
81 | | -[\t\r\n] ;// whitespace |
| 98 | +\"[(\\\")(\\0)\;\!\@\#\$\%\^\&\*\(\)\.\, 0-9a-zA-Z]*\" { |
| 99 | + position += yyleng; |
| 100 | + yylval.strval=strdup(yytext); |
| 101 | +return STRING; |
| 102 | + } |
82 | 103 |
|
| 104 | +[\t\r\n] ; { position += yyleng; }// whitespace |
83 | 105 |
|
84 | | -%% |
85 | | - |
86 | | -/*MQuery* |
87 | | -parsemquery(const char *str, int len) |
88 | | -{ |
89 | | - YY_BUFFER_STATE buffer = yy_scan_string(str); |
90 | | -
|
91 | | - yyparse(); |
92 | | - yy_delete_buffer(buffer); |
93 | 106 |
|
94 | | - return RET; |
95 | | -} |
96 | | -*/ |
| 107 | +%% |