3
3
+------------------------------------------------------------------------+
4
4
| Phalcon Framework |
5
5
+------------------------------------------------------------------------+
6
- | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) |
6
+ | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) |
7
7
+------------------------------------------------------------------------+
8
8
| This source file is subject to the New BSD License that is bundled |
9
9
| with this package in the file docs/LICENSE.txt. |
28
28
%left EQUALS NOTEQUALS LESS GREATER GREATEREQUAL LESSEQUAL .
29
29
%left AND OR .
30
30
%left LIKE ILIKE .
31
- %left BITWISE_AND BITWISE_OR .
31
+ %left BITWISE_AND BITWISE_OR BITWISE_XOR .
32
32
%left DIVIDE TIMES MOD .
33
33
%left PLUS MINUS .
34
34
%left IS .
35
35
%right IN DISTINCT .
36
- %right NOT .
36
+ %right NOT BITWISE_NOT .
37
37
38
38
%include {
39
39
@@ -82,13 +82,39 @@ static zval *phql_ret_placeholder_zval(int type, phql_parser_token *T)
82
82
return ret;
83
83
}
84
84
85
- static zval *phql_ret_qualified_name(phql_parser_token *A, phql_parser_token *B)
85
+ static zval *phql_ret_qualified_name(phql_parser_token *A, phql_parser_token *B, phql_parser_token *C )
86
86
{
87
87
zval *ret;
88
88
89
89
MAKE_STD_ZVAL(ret);
90
90
array_init(ret);
91
+
91
92
add_assoc_long(ret, "type", PHQL_T_QUALIFIED);
93
+
94
+ if (A != NULL) {
95
+ add_assoc_stringl(ret, "ns-alias", A->token, A->token_len, 0);
96
+ efree(A);
97
+ }
98
+
99
+ if (B != NULL) {
100
+ add_assoc_stringl(ret, "domain", B->token, B->token_len, 0);
101
+ efree(B);
102
+ }
103
+
104
+ add_assoc_stringl(ret, "name", C->token, C->token_len, 0);
105
+ efree(C);
106
+
107
+ return ret;
108
+ }
109
+
110
+ static zval *phql_ret_raw_qualified_name(phql_parser_token *A, phql_parser_token *B)
111
+ {
112
+ zval *ret;
113
+
114
+ MAKE_STD_ZVAL(ret);
115
+ array_init(ret);
116
+
117
+ add_assoc_long(ret, "type", PHQL_T_RAW_QUALIFIED);
92
118
if (B != NULL) {
93
119
add_assoc_stringl(ret, "domain", A->token, A->token_len, 0);
94
120
add_assoc_stringl(ret, "name", B->token, B->token_len, 0);
@@ -448,26 +474,26 @@ static zval *phql_ret_func_call(phql_parser_token *name, zval *arguments)
448
474
token_found = 0;
449
475
}
450
476
451
- status->syntax_error_len = 64 + status->token->len + token_length + near_length;
477
+ status->syntax_error_len = 96 + status->token->len + token_length + near_length + status->phql_length; ;
452
478
status->syntax_error = emalloc(sizeof(char) * status->syntax_error_len);
453
479
454
480
if (near_length > 0) {
455
481
if (status->token->value) {
456
- snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), near to '%s'", token_name, status->token->value, status->scanner_state->start);
482
+ snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), near to '%s', when parsing: %s (%d) ", token_name, status->token->value, status->scanner_state->start, status->phql, status->phql_length );
457
483
} else {
458
- snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, near to '%s'", token_name, status->scanner_state->start);
484
+ snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, near to '%s', when parsing: %s (%d) ", token_name, status->scanner_state->start, status->phql, status->phql_length );
459
485
}
460
486
} else {
461
487
if (active_token != PHQL_T_IGNORE) {
462
488
if (status->token->value) {
463
- snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), at the end of query", token_name, status->token->value);
489
+ snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), at the end of query, when parsing: %s (%d) ", token_name, status->token->value, status->phql, status->phql_length );
464
490
} else {
465
- snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, at the end of query", token_name);
491
+ snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, at the end of query, when parsing: %s (%d) ", token_name, status->phql, status->phql_length );
466
492
}
467
493
} else {
468
494
snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected EOF, at the end of query");
469
495
}
470
- status->syntax_error[status->syntax_error_len- 1] = '\0';
496
+ status->syntax_error[status->syntax_error_len - 1] = '\0';
471
497
}
472
498
473
499
if (!token_found) {
@@ -684,33 +710,33 @@ join_item(R) ::= join_clause(C) . {
684
710
%destructor join_clause { zval_ptr_dtor(&$$); }
685
711
686
712
/** Join - conditions - alias */
687
- join_clause(R) ::= join_type(T) qualified_name (Q) . {
713
+ join_clause(R) ::= join_type(T) aliased_or_qualified_name (Q) . {
688
714
R = phql_ret_join_item(T, Q, NULL, NULL);
689
715
}
690
716
691
717
/** Join - conditions + alias */
692
- join_clause(R) ::= join_type(T) qualified_name (Q) join_associated_name(A) . {
718
+ join_clause(R) ::= join_type(T) aliased_or_qualified_name (Q) join_associated_name(A) . {
693
719
R = phql_ret_join_item(T, Q, A, NULL);
694
720
}
695
721
696
722
/** Join + conditions - alias */
697
- join_clause(R) ::= join_type(T) qualified_name (Q) join_conditions(C) . {
723
+ join_clause(R) ::= join_type(T) aliased_or_qualified_name (Q) join_conditions(C) . {
698
724
R = phql_ret_join_item(T, Q, NULL, C);
699
725
}
700
726
701
727
/** Join + conditions + alias */
702
- join_clause(R) ::= join_type(T) qualified_name (Q) join_associated_name(A) join_conditions(C) . {
728
+ join_clause(R) ::= join_type(T) aliased_or_qualified_name (Q) join_associated_name(A) join_conditions(C) . {
703
729
R = phql_ret_join_item(T, Q, A, C);
704
730
}
705
731
706
732
%destructor join_associated_name { zval_ptr_dtor(&$$); }
707
733
708
734
join_associated_name(R) ::= AS IDENTIFIER(I) . {
709
- R = phql_ret_qualified_name(I , NULL);
735
+ R = phql_ret_qualified_name(NULL , NULL, I );
710
736
}
711
737
712
738
join_associated_name(R) ::= IDENTIFIER(I) . {
713
- R = phql_ret_qualified_name(I , NULL);
739
+ R = phql_ret_qualified_name(NULL , NULL, I );
714
740
}
715
741
716
742
%destructor join_type { zval_ptr_dtor(&$$); }
@@ -760,11 +786,11 @@ join_conditions(R) ::= ON expr(E) . {
760
786
%destructor insert_statement { zval_ptr_dtor(&$$); }
761
787
762
788
/* Insert */
763
- insert_statement(R) ::= INSERT INTO qualified_name (Q) VALUES BRACKET_OPEN values_list(V) BRACKET_CLOSE . {
789
+ insert_statement(R) ::= INSERT INTO aliased_or_qualified_name (Q) VALUES PARENTHESES_OPEN values_list(V) PARENTHESES_CLOSE . {
764
790
R = phql_ret_insert_statement(Q, NULL, V);
765
791
}
766
792
767
- insert_statement(R) ::= INSERT INTO qualified_name (Q) BRACKET_OPEN field_list(F) BRACKET_CLOSE VALUES BRACKET_OPEN values_list(V) BRACKET_CLOSE . {
793
+ insert_statement(R) ::= INSERT INTO aliased_or_qualified_name (Q) PARENTHESES_OPEN field_list(F) PARENTHESES_CLOSE VALUES PARENTHESES_OPEN values_list(V) PARENTHESES_CLOSE . {
768
794
R = phql_ret_insert_statement(Q, F, V);
769
795
}
770
796
@@ -795,7 +821,7 @@ field_list(R) ::= field_item(F) . {
795
821
%destructor field_item { zval_ptr_dtor(&$$); }
796
822
797
823
field_item(R) ::= IDENTIFIER(I) . {
798
- R = phql_ret_qualified_name(I , NULL);
824
+ R = phql_ret_qualified_name(NULL , NULL, I );
799
825
}
800
826
801
827
/* Update */
@@ -872,18 +898,24 @@ delete_clause(R) ::= DELETE FROM associated_name(A) . {
872
898
873
899
%destructor associated_name { zval_ptr_dtor(&$$); }
874
900
875
- associated_name(R) ::= qualified_name (Q) AS IDENTIFIER(I) . {
901
+ associated_name(R) ::= aliased_or_qualified_name (Q) AS IDENTIFIER(I) . {
876
902
R = phql_ret_assoc_name(Q, I);
877
903
}
878
904
879
- associated_name(R) ::= qualified_name (Q) IDENTIFIER(I) . {
905
+ associated_name(R) ::= aliased_or_qualified_name (Q) IDENTIFIER(I) . {
880
906
R = phql_ret_assoc_name(Q, I);
881
907
}
882
908
883
- associated_name(R) ::= qualified_name (Q) . {
909
+ associated_name(R) ::= aliased_or_qualified_name (Q) . {
884
910
R = phql_ret_assoc_name(Q, NULL);
885
911
}
886
912
913
+ %destructor aliased_or_qualified_name { zval_ptr_dtor(&$$); }
914
+
915
+ aliased_or_qualified_name(R) ::= qualified_name(Q) . {
916
+ R = Q;
917
+ }
918
+
887
919
%destructor where_clause { zval_ptr_dtor(&$$); }
888
920
889
921
where_clause(R) ::= WHERE expr(E) . {
@@ -938,12 +970,8 @@ group_list(R) ::= group_item(I) . {
938
970
939
971
%destructor group_item { zval_ptr_dtor(&$$); }
940
972
941
- group_item(R) ::= qualified_name(Q) . {
942
- R = Q;
943
- }
944
-
945
- group_item(R) ::= INTEGER(I) . {
946
- R = phql_ret_literal_zval(PHQL_T_INTEGER, I);
973
+ group_item(R) ::= expr(E) . {
974
+ R = E;
947
975
}
948
976
949
977
%destructor having_clause { zval_ptr_dtor(&$$); }
@@ -1014,6 +1042,10 @@ expr(R) ::= expr(O1) BITWISE_OR expr(O2) . {
1014
1042
R = phql_ret_expr(PHQL_T_BITWISE_OR, O1, O2);
1015
1043
}
1016
1044
1045
+ expr(R) ::= expr(O1) BITWISE_XOR expr(O2) . {
1046
+ R = phql_ret_expr(PHQL_T_BITWISE_XOR, O1, O2);
1047
+ }
1048
+
1017
1049
expr(R) ::= expr(O1) EQUALS expr(O2) . {
1018
1050
R = phql_ret_expr(PHQL_T_EQUALS, O1, O2);
1019
1051
}
@@ -1054,29 +1086,37 @@ expr(R) ::= expr(O1) NOT ILIKE expr(O2) . {
1054
1086
R = phql_ret_expr(PHQL_T_NILIKE, O1, O2);
1055
1087
}
1056
1088
1057
- expr(R) ::= expr(E) IN BRACKET_OPEN argument_list(L) BRACKET_CLOSE . {
1089
+ expr(R) ::= expr(E) IN PARENTHESES_OPEN argument_list(L) PARENTHESES_CLOSE . {
1058
1090
R = phql_ret_expr(PHQL_T_IN, E, L);
1059
1091
}
1060
1092
1061
- expr(R) ::= expr(E) NOT IN BRACKET_OPEN argument_list(L) BRACKET_CLOSE . {
1093
+ expr(R) ::= expr(E) NOT IN PARENTHESES_OPEN argument_list(L) PARENTHESES_CLOSE . {
1062
1094
R = phql_ret_expr(PHQL_T_NOTIN, E, L);
1063
1095
}
1064
1096
1065
1097
expr(R) ::= expr(O1) AGAINST expr(O2) . {
1066
1098
R = phql_ret_expr(PHQL_T_AGAINST, O1, O2);
1067
1099
}
1068
1100
1101
+ expr(R) ::= CAST PARENTHESES_OPEN expr(E) AS IDENTIFIER(I) PARENTHESES_CLOSE . {
1102
+ R = phql_ret_expr(PHQL_T_CAST, E, phql_ret_raw_qualified_name(I, NULL));
1103
+ }
1104
+
1105
+ expr(R) ::= CONVERT PARENTHESES_OPEN expr(E) USING IDENTIFIER(I) PARENTHESES_CLOSE . {
1106
+ R = phql_ret_expr(PHQL_T_CONVERT, E, phql_ret_raw_qualified_name(I, NULL));
1107
+ }
1108
+
1069
1109
%destructor function_call { zval_ptr_dtor(&$$); }
1070
1110
1071
1111
expr(R) ::= function_call(F) . {
1072
1112
R = F;
1073
1113
}
1074
1114
1075
- function_call(R) ::= IDENTIFIER(I) BRACKET_OPEN argument_list(L) BRACKET_CLOSE . {
1115
+ function_call(R) ::= IDENTIFIER(I) PARENTHESES_OPEN argument_list(L) PARENTHESES_CLOSE . {
1076
1116
R = phql_ret_func_call(I, L);
1077
1117
}
1078
1118
1079
- function_call(R) ::= IDENTIFIER(I) BRACKET_OPEN BRACKET_CLOSE . {
1119
+ function_call(R) ::= IDENTIFIER(I) PARENTHESES_OPEN PARENTHESES_CLOSE . {
1080
1120
R = phql_ret_func_call(I, NULL);
1081
1121
}
1082
1122
@@ -1120,7 +1160,11 @@ expr(R) ::= NOT expr(E) . {
1120
1160
R = phql_ret_expr(PHQL_T_NOT, NULL, E);
1121
1161
}
1122
1162
1123
- expr(R) ::= BRACKET_OPEN expr(E) BRACKET_CLOSE . {
1163
+ expr(R) ::= BITWISE_NOT expr(E) . {
1164
+ R = phql_ret_expr(PHQL_T_BITWISE_NOT, NULL, E);
1165
+ }
1166
+
1167
+ expr(R) ::= PARENTHESES_OPEN expr(E) PARENTHESES_CLOSE . {
1124
1168
R = phql_ret_expr(PHQL_T_ENCLOSED, E, NULL);
1125
1169
}
1126
1170
@@ -1144,6 +1188,14 @@ expr(R) ::= NULL . {
1144
1188
R = phql_ret_literal_zval(PHQL_T_NULL, NULL);
1145
1189
}
1146
1190
1191
+ expr(R) ::= TRUE . {
1192
+ R = phql_ret_literal_zval(PHQL_T_TRUE, NULL);
1193
+ }
1194
+
1195
+ expr(R) ::= FALSE . {
1196
+ R = phql_ret_literal_zval(PHQL_T_FALSE, NULL);
1197
+ }
1198
+
1147
1199
expr(R) ::= NPLACEHOLDER(P) . {
1148
1200
R = phql_ret_placeholder_zval(PHQL_T_NPLACEHOLDER, P);
1149
1201
}
@@ -1154,10 +1206,19 @@ expr(R) ::= SPLACEHOLDER(P) . {
1154
1206
1155
1207
%destructor qualified_name { zval_ptr_dtor(&$$); }
1156
1208
1209
+ qualified_name(R) ::= IDENTIFIER(A) COLON IDENTIFIER(B) DOT IDENTIFIER(C) . {
1210
+ R = phql_ret_qualified_name(A, B, C);
1211
+ }
1212
+
1213
+ qualified_name(R) ::= IDENTIFIER(A) COLON IDENTIFIER(B) . {
1214
+ R = phql_ret_qualified_name(A, NULL, B);
1215
+ }
1216
+
1157
1217
qualified_name(R) ::= IDENTIFIER(A) DOT IDENTIFIER(B) . {
1158
- R = phql_ret_qualified_name(A, B);
1218
+ R = phql_ret_qualified_name(NULL, A, B);
1159
1219
}
1160
1220
1161
1221
qualified_name(R) ::= IDENTIFIER(A) . {
1162
- R = phql_ret_qualified_name(A , NULL);
1222
+ R = phql_ret_qualified_name(NULL , NULL, A );
1163
1223
}
1224
+
0 commit comments