fontoxpath icon indicating copy to clipboard operation
fontoxpath copied to clipboard

Implement the `switch` statement

Open line-o opened this issue 2 years ago • 5 comments
trafficstars

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.

line-o avatar Nov 14 '23 17:11 line-o

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

DrRataplan avatar Nov 20 '23 14:11 DrRataplan

Let me know, if I can help.

line-o avatar Nov 20 '23 18:11 line-o

PR is in: #620

DrRataplan avatar Nov 21 '23 10:11 DrRataplan

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. :wink:
  • 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 :wink:

Kind regards,

Martin

DrRataplan avatar Nov 21 '23 12:11 DrRataplan

@DrRataplan awesome news! :rocket: 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.

line-o avatar Nov 22 '23 10:11 line-o

Switches landed in #620 ! closing!

DrRataplan avatar May 28 '24 15:05 DrRataplan