Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fea3186

Browse files
NikitOS94NikitOS94
NikitOS94
authored and
NikitOS94
committed
Update error message
1 parent 4308010 commit fea3186

File tree

2 files changed

+76
-70
lines changed

2 files changed

+76
-70
lines changed

monq_gram.y

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,21 @@
99

1010
typedef struct yy_buffer_state *YY_BUFFER_STATE;
1111
extern int yylex();
12-
extern void yyerror(char *s);
1312
extern int yyparse();
13+
extern void yyerror(char *s);
1414
extern YY_BUFFER_STATE yy_scan_string(char * str);
1515
extern void yy_delete_buffer(YY_BUFFER_STATE buffer);
1616

17-
void
18-
yyerror(char *s)
19-
{
20-
elog(ERROR,"%s",s);
21-
exit(0);
22-
}
23-
17+
char *inputString;
18+
int position;
2419
MQuery*
2520
parse(char *str)
2621
{
27-
YY_BUFFER_STATE buffer = yy_scan_string(str);
28-
22+
YY_BUFFER_STATE buffer = yy_scan_string(str);
23+
inputString = str;
2924
yyparse();
3025
yy_delete_buffer(buffer);
31-
26+
position = 1;
3227
return RET;
3328
}
3429
%}

monq_scan.l

Lines changed: 70 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
%{
22
#include <stdlib.h>
33
#include <stdio.h>
4-
#include "monq.h"
4+
#include "monq.h"
55
#include "monq_gram.h"
66
#include <string.h>
77

8-
98
extern int yylex();
9+
extern void yyerror(char *s);
1010

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+
}
1129
%}
1230

1331
%option yylineno
@@ -19,78 +37,71 @@
1937

2038
[/][/].*\n ; // comment
2139

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; }
3043

31-
\, { return COMMA; }
44+
\{ { position += yyleng; return LSCOPE; }
45+
\} { position += yyleng; return RSCOPE; }
46+
\[ { position += yyleng; return LSQBRACKET; }
47+
\] { position += yyleng; return RSQBRACKET; }
3248

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; }
4350

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; }
4761

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; }
4965

50-
\$where { return WHERE_OPERATOR; }
66+
\$not { position += yyleng; return NOT;}
5167

52-
\$elemMatch { return ELEMMATCH; }
68+
\$where { position += yyleng; return WHERE_OPERATOR; }
5369

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; }
5771

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; }
6375

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; }
6581

66-
\$mod { return MOD_OPERATOR; }
82+
\$comment { position += yyleng; return COMMENT_OPERATOR; }
6783

68-
\"\" { yylval.strval=strdup(yytext); return STRING; }
84+
\$mod { position += yyleng; return MOD_OPERATOR; }
6985

70-
[0-9a-zA-Z]+ { yylval.strval=strdup(yytext); return KEY_STRING; }
86+
\"\" { position += yyleng; yylval.strval=strdup(yytext); return STRING; }
7187

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; }
7889

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+
}
8097

81-
[ \t\r\n] ; // whitespace
98+
\"[(\\\")(\\0)\;\!\@\#\$\%\^\&\*\(\)\.\, 0-9a-zA-Z]*\" {
99+
position += yyleng;
100+
yylval.strval=strdup(yytext);
101+
return STRING;
102+
}
82103

104+
[ \t\r\n] ; { position += yyleng; } // whitespace
83105

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);
93106

94-
return RET;
95-
}
96-
*/
107+
%%

0 commit comments

Comments
 (0)