Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compliance/expressions/valid.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ ROUND(x, 2)

# Operators and predicates
first_name || ' ' || last_name
'Total: ' || qty * price || ' EUR'
a || b + c - d || e
x % 2
-x + +y * (z - 1) / 2
a <> b AND a != b AND a <= b AND a >= b
Expand Down
7 changes: 4 additions & 3 deletions core-spec/grammar/OssieExpression.g4
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ options { caseInsensitive = true; }
//
// Operands of comparisons and predicates are arithmetic expressions: `a = b = c` needs parentheses.
//
// Precedence follows the list in the spec. The spec does not say where `||` sits: it is parsed at
// the level of + and -.
// Precedence follows the list in the spec. The spec does not say where `||` sits: it is parsed at a
// level of its own below + and -, as in sqlglot and PostgreSQL: `a || b + c` is `a || (b + c)`.

expression
: expr EOF
Expand All @@ -58,7 +58,8 @@ valueExpr
: primary # primaryValue
| op=(PLUS | MINUS) valueExpr # unaryValue
| valueExpr op=(STAR | SLASH | PERCENT) valueExpr # multiplicativeValue
| valueExpr op=(PLUS | MINUS | CONCAT) valueExpr # additiveValue
| valueExpr op=(PLUS | MINUS) valueExpr # additiveValue
| valueExpr CONCAT valueExpr # concatValue
;

primary
Expand Down
3 changes: 2 additions & 1 deletion core-spec/grammar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ generated parser is not committed.
The precedence levels follow the list in the spec's "Operator Precedence" section. Two points
are not decided there:

- `||` is accepted, at the level of `+` and `-`. The spec's portable form is `CONCAT(a, b)`;
- `||` is accepted, at a level of its own below `+` and `-` (above comparisons), like sqlglot and
PostgreSQL: `a || b + c` is `a || (b + c)`. The spec's portable form is `CONCAT(a, b)`;
`a || b` only appears as a dialect form.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clause conflicts with expression_language.md, which lists || as a REQUIRED string operator (String Manipulation table). Suggest dropping it, or saying that || is a required operator and CONCAT(a, b) is the other spelling.

- Comparisons do not chain: `a = b = c` needs parentheses.

Expand Down
Loading