Skip to content

Commit

Permalink
Allow spaces in all combinations with < - > *
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Dec 2, 2024
1 parent 0c82f0e commit 0a31199
Show file tree
Hide file tree
Showing 3 changed files with 14,906 additions and 14,943 deletions.
66 changes: 52 additions & 14 deletions third_party/libpg_query/grammar/statements/pgq.y
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,39 @@ FullElementSpec:
}
;

StickyArrowHead:
Op
{ /* DDB lexer may concatenate an > with + or * into an "operator" */
char *op = $1;
if (op[0] ='>' && (op[1] == '+' || op[1] == '*') && op[2] == 0) {
$$ = (op[1] == '*') ? "->*" : "->+";
} else {
char msg[128];
snprintf(msg, 128, "PGQ does not allow - followed by %s here.", op);
parser_yyerror(msg);
}
}
;

StickyDash:
Op
{ /* DDB lexer may concatenate an arrow with + or * into an "operator" */
char *op = $1, *ok = NULL;
/* only <-, <->, -, -> are ok */
if (op[0] == '<') op++; /* also accept <-> */
if (op[0] == '-') {
ok = op + 1 + (op[1] == '>');
}
/* it may optionally be followed by a single * or + */
if (!ok || (ok[0] && ((ok[0] != '*' && ok[0] != '+') || ok[1]))) {
char msg[128];
snprintf(msg, 128, "PGQ expected an arrow instead of %s operator.", $1);
parser_yyerror(msg);
}
$$ = $1;
}


/* we allow spaces inside the arrows */
Arrow:
'-'
Expand All @@ -768,22 +801,27 @@ Arrow:
'<' '-' '>'
{ $$ = "<->"; }
|
Op
{ /* DDB lexer may concatenate an arrow with + or * into an "operator" */
char *op = $1, *ok = NULL;
/* only <-, <->, -, -> are ok */
if (op[0] == '<') op++; /* also accept <-> */
if (op[0] == '-') {
ok = op + 1 + (op[1] == '>');
}
/* it may optionally be followed by a single * or + */
if (!ok || (ok[0] && ((ok[0] != '*' && ok[0] != '+') || ok[1]))) {
char msg[128];
snprintf(msg, 128, "PGQ expected an arrow instead of %s operator.", $1);
parser_yyerror(msg);
StickyDash
{ $$ = $1; }
|
'<' StickyDash
{ char *op = $2;
if (op[0] == '<') {
parse_yyerror("PGQ does not allow < followed by < as edge operator");
}
$$ = $1;
$$ = (op[1] == 0) ? "<-" :
(op[1] == '*') ? "<-*" :
(op[1] == '+') ? "<-+" :
(op[2] == '*') ? "<->*" :
(op[2] == '+') ? "<->+" : "<->";
}
|
'<' '-' StickyArrowHead
{ $$ = ($3 == "->*") ? "<->*" : "<->+"; }
;
|
'-' StickyArrowHead
{ $$ = $2 }
;

ArrowLeft:
Expand Down
2 changes: 2 additions & 0 deletions third_party/libpg_query/grammar/types/pgq.yh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
%type <node> OrLabelExpression
%type <node> LabelExpressionOptional
%type <str> Arrow
%type <str> StickyArrowHead
%type <str> StickyDash
%type <str> ArrowLeft
%type <node> ArrowKleeneOptional
%type <str> VariableOptional
Expand Down
Loading

0 comments on commit 0a31199

Please sign in to comment.