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

Implement the switch statement #619

Closed
line-o opened this issue Nov 14, 2023 · 6 comments
Closed

Implement the switch statement #619

line-o opened this issue Nov 14, 2023 · 6 comments

Comments

@line-o
Copy link

line-o commented Nov 14, 2023

Please implement the switch statement in fontoXPath

Running following with the recent version 3.30.2

console.log(
  evaluateXPath(
    "switch (1) case 1 return 1 default return 0",
    null, null, null, null,
    { debug: true, language: 'XQuery3.1'}
  )
)

Fails with

Error: No selector counterpart for: switchExpr.
@DrRataplan
Copy link
Collaborator

Hey Juri,

That's a high one on the wish list for me as well. I'll see when I get to it!

KR,

Martin

@line-o
Copy link
Author

line-o commented Nov 20, 2023

Let me know, if I can help.

@DrRataplan
Copy link
Collaborator

PR is in: #620

@DrRataplan
Copy link
Collaborator

DrRataplan commented Nov 21, 2023

Hey Juri,

You can actually help out with some parts! I tried making your wonderful L-systems work with FontoXPath, and it got close. Very close. https://github.com/DrRataplan/linsy/tree/main.

The only things I had to remove/change were:

  • linsy.xqm: move the empty-sequence test to the default case: we don't have empty-sequence test yet. This is annoying to add since the whole TypeSwitchExpression assumes it can pass single items to the cases. We might have to special case voidSequenceType in typeSwitch instead of making it an AbstractTestExpression like I did with NameTest for example.
  • prob.xqm: for-each-pair is not implemented yet. This should not be too hard to implement actually. It should be roughly the same as for-each. Just a copy-paste-edit of it. 😉
  • read.xqm: FontoXPath does not allow dynamic module loading. Implementing this in all its might will be difficult: in the browser there's no way to dynamically download things synchronously. Nor do we want to. In NodeJS it's technically possible, but annoying nonetheless. If we dumb this function down to assuming the module is actually registered already with registerXQueryModule we can make this work. Just look up the module in the global registry and return it as a map.

What are your thoughts? How serious were you offering help 😉

Kind regards,

Martin

@line-o
Copy link
Author

line-o commented Nov 22, 2023

@DrRataplan awesome news! 🚀
The dynamic module import was introduced in one of the last commits and there is a number of ways to tackle this.
I would also be interested in looking at the for-each implementation and see if I can copy-paste code myself to make for-each-pair a reality.
Unfortunately, until mid-december at least, I have no time to work on any of this. The last days of this year and beginning of 2024 I see an opportunity to take some of this on.

@DrRataplan
Copy link
Collaborator

Switches landed in #620 ! closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants