Skip to content

Commit 37b954a

Browse files
peterpeter
authored andcommitted
had to make Op a higher-precedence operator
1 parent 0a31199 commit 37b954a

File tree

4 files changed

+27968
-27699
lines changed

4 files changed

+27968
-27699
lines changed

third_party/libpg_query/grammar/grammar.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
*/
146146
%nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
147147
%nonassoc IDENT GENERATED NULL_P PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP ENUM_P
148-
%left Op OPERATOR /* multi-character ops and user-defined operators */
149148
%left '+' '-'
149+
%left Op OPERATOR /* multi-character ops and user-defined operators */
150150
%left '*' '/' '%' INTEGER_DIVISION
151151
%left '^' POWER_OF
152152
/* Unary Operators */

third_party/libpg_query/grammar/statements/pgq.y

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ StickyArrowHead:
753753
{ /* DDB lexer may concatenate an > with + or * into an "operator" */
754754
char *op = $1;
755755
if (op[0] ='>' && (op[1] == '+' || op[1] == '*') && op[2] == 0) {
756-
$$ = (op[1] == '*') ? "->*" : "->+";
756+
$$ = (char*) ((op[1] == '*') ? "->*" : "->+");
757757
} else {
758758
char msg[128];
759759
snprintf(msg, 128, "PGQ does not allow - followed by %s here.", op);
@@ -762,6 +762,7 @@ StickyArrowHead:
762762
}
763763
;
764764

765+
765766
StickyDash:
766767
Op
767768
{ /* DDB lexer may concatenate an arrow with + or * into an "operator" */
@@ -783,45 +784,44 @@ StickyDash:
783784

784785
/* we allow spaces inside the arrows */
785786
Arrow:
786-
'-'
787-
{ $$ = "-"; }
788-
|
789-
'<' '-'
790-
{ $$ = "<-"; }
791-
|
792-
LAMBDA_ARROW
793-
{ $$ = "->"; }
787+
'-' StickyArrowHead
788+
{ $$ = $2; }
794789
|
795790
'-' '>'
796791
{ $$ = "->"; }
792+
|
793+
'-'
794+
{ $$ = "-"; }
795+
|
796+
StickyDash
797+
{ $$ = $1; }
797798
|
798799
'<' LAMBDA_ARROW
799800
{ $$ = "<->"; }
801+
|
802+
'<' '-' StickyArrowHead
803+
{ $$ = (char*) (($3 == "->*") ? "<->*" : "<->+"); }
800804
|
801805
'<' '-' '>'
802806
{ $$ = "<->"; }
803-
|
804-
StickyDash
805-
{ $$ = $1; }
806807
|
807808
'<' StickyDash
808809
{ char *op = $2;
809810
if (op[0] == '<') {
810-
parse_yyerror("PGQ does not allow < followed by < as edge operator");
811+
parser_yyerror("PGQ does not allow < followed by < as edge operator");
811812
}
812-
$$ = (op[1] == 0) ? "<-" :
813-
(op[1] == '*') ? "<-*" :
814-
(op[1] == '+') ? "<-+" :
815-
(op[2] == '*') ? "<->*" :
816-
(op[2] == '+') ? "<->+" : "<->";
813+
$$ = (char*) ((op[1] == 0) ? "<-" :
814+
(op[1] == '*') ? "<-*" :
815+
(op[1] == '+') ? "<-+" :
816+
(op[2] == '*') ? "<->*" :
817+
(op[2] == '+') ? "<->+" : "<->");
817818
}
818819
|
819-
'<' '-' StickyArrowHead
820-
{ $$ = ($3 == "->*") ? "<->*" : "<->+"; }
821-
;
820+
'<' '-'
821+
{ $$ = "<-"; }
822822
|
823-
'-' StickyArrowHead
824-
{ $$ = $2 }
823+
LAMBDA_ARROW
824+
{ $$ = "->"; }
825825
;
826826

827827
ArrowLeft:

0 commit comments

Comments
 (0)