Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precedence of otherwise operator #1024

Closed
michaelhkay opened this issue Feb 13, 2024 · 1 comment · Fixed by #1031
Closed

Precedence of otherwise operator #1024

michaelhkay opened this issue Feb 13, 2024 · 1 comment · Fixed by #1031
Labels
Discussion A discussion on a general topic. Tests Added Tests have been added to the test suites XPath An issue related to XPath

Comments

@michaelhkay
Copy link
Contributor

michaelhkay commented Feb 13, 2024

I made a mistake when specifying subsequence-where, caused by misunderstanding the precedence of the otherwise operator: see issue #1001.

In the expression

let $start := index-where($input, $from)[1] 
              otherwise count($input) + 1

I failed to realise that otherwise binds more tightly than +.

I'm opening the issue to solicit views as to whether we have got this right.

One might take the view that the closest thing to otherwise in other familiar language is the ternary conditional operator, which has lower precedence than anything else including and and or; but then, its first operand is a boolean expression while it's relatively unlikely that the operands of otherwise will be boolean. I'm therefore thinking that it might be best to put it between 'eq' and '||`, so

$a eq $b otherwise $c || $d

parses as

$a eq ($b otherwise ($c || $d))

@michaelhkay michaelhkay added XPath An issue related to XPath Discussion A discussion on a general topic. labels Feb 13, 2024
@ChristianGruen
Copy link
Contributor

Yes, that looks like a good choice. I’ve come across a similar problem with the current precedence rules in a project a short while ago.

@michaelhkay michaelhkay added PR Pending A PR has been raised to resolve this issue Tests Needed Tests need to be written or merged Tests Added Tests have been added to the test suites and removed Tests Needed Tests need to be written or merged labels Feb 20, 2024
@ndw ndw closed this as completed in #1031 Feb 27, 2024
@ChristianGruen ChristianGruen removed the PR Pending A PR has been raised to resolve this issue label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion A discussion on a general topic. Tests Added Tests have been added to the test suites XPath An issue related to XPath
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants