EOS Feature Request/Bug: Regular Expression support

Post all technical issues and questions here. We'll gladly help you wherever we can.
Post Reply
fapnip
Explorer At Heart
Explorer At Heart
Posts: 430
Joined: Mon Apr 06, 2020 1:54 pm

EOS Feature Request/Bug: Regular Expression support

Post by fapnip »

Regular expressions seem to be broken in EOS's JS interpreter. Any chance of getting them supported?

Code: Select all

var test = 'this is a text';
console.log('test1', test); // this works
var test2 = test.replace(/text/, 'test'); // this apparently doesn't work, but doesn't log an error on the console.  test2 is never set.
console.log('test2', test2); // this does not execute.  Do we never return from the interpreter's async (mode 2) regexp?
Same problem for string.match, .split, .search, etc.

Regular expressions are kinda a big deal in JavaScript. There are a number of things that are much more difficult to do without them.
Last edited by fapnip on Sat Apr 18, 2020 1:51 pm, edited 5 times in total.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 430
Joined: Mon Apr 06, 2020 1:54 pm

Re: Regular Expression support in EOS

Post by fapnip »

Looks like EOS is setting regexp mode 2 (or maybe mode 0, though it seems to be set to default) from here:
https://neil.fraser.name/software/JS-In ... egexp.html

If currently mode 0, could we try mode 2?

If currently mode 2, can that be switched to mode 1? The only real risk here is that a badly written regexp could "crash" the js runtime. There's no real security risk to mode 1. You could create a similar problem with something like while(true){}. (Though a misbehaving regexp could freeze the js runtime running the interpreter, not just the interpreted script. But still no security risk.)
fapnip
Explorer At Heart
Explorer At Heart
Posts: 430
Joined: Mon Apr 06, 2020 1:54 pm

Re: EOS Feature Request/Bug: Regular Expression support

Post by fapnip »

@seraph0x: Is there any chance for functional regexp in EOS?

I have a few things I want to try that'll basically require them. It would be nice to know if I just need to permanently shelve these ideas and move on.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 430
Joined: Mon Apr 06, 2020 1:54 pm

Re: EOS Feature Request/Bug: Regular Expression support

Post by fapnip »

After more experimentation, it looks like the interpreter is indeed using mode 2 (asynchronous), and order of execution is lost when a regexp is used.

While impractical to use, the following does work:

On start page:
1. eval action:

Code: Select all

var regexpResult = ('this is a text').replace(/text/, 'test'); // This will only happen after a timer action has started. We effectively cede control to the next action at this point.
console.log('Regexp complete'); // Regexp is now done
2. Page timer action for any amount of time. This is needed to allow the regexp to run asynchronously
3. Say: <eval>regexpResult</eval> // If we do this before the timer, it will fail.

This will say "This is a test".

Execution of the start pages's eval effectively pauses at the regexp operation until the timer starts. Once the timer starts, the asynchronous regexp operation completes, and the rest of the code in the eval is allowed to continue (the console log in this case.)

So, the easiest fix for this is for EOS to set REGEXP_MODE = 1. The only real issue that could happen here is that a badly written regexp could freeze up the JS runtime in an infinite loop.
undeniable_denial
Explorer
Explorer
Posts: 96
Joined: Sat Aug 24, 2019 11:42 am
Gender: Male
Location: Germany

Re: EOS Feature Request/Bug: Regular Expression support

Post by undeniable_denial »

I endorse this request.

Eval-actions getting interrupted at every RegExp makes them almost unusable. I think mode 2 can be fine, but EOS needs to finish the web workers and the rest of the eval-action before continuing with the next action.
RemiHiyama
Explorer At Heart
Explorer At Heart
Posts: 203
Joined: Thu Feb 28, 2019 3:30 pm
I am a: Switch

Re: EOS Feature Request/Bug: Regular Expression support

Post by RemiHiyama »

Seems like the behavior might be different in different browsers.

I have a project I'd been working on that involved multiple say actions in a row (well, and each was inside an if action, but that shouldn't make a difference), each of which displays text that's been fed through a javascript function that replaces a number of tokens with different values.

Code: Select all

function procline(line) {
	var temp = line;
	console.log("Procline: " + line)
	(A bunch of replace functions go here...)
	console.log("Procline 2: " + temp)
	return temp;
}
In Chrome, the first log message appears when it seems like it should, but the second only appears after clicking on the say -after- that one.

In Firefox, the second log message -never- appears, or at least it hasn't so far before something causes the tease to lock, which was not a problem the last time I worked on this.

And Edge throws a SecurityError, after which no text displays at all. (Unlike the others, which display junk.)

Removing the log lines changes the behavior somewhat... but it's never really correct.

I'm pretty sure this was not how things behaved before.

I tried changing things so the text was assigned to a variable in an eval tag, followed by a timer, and then had it displayed, but this only seemed to work when the text wouldn't actually change, even with a fairly long timer. (And they shouldn't really take a noticeable amount of time to complete to begin with.)
Auto: Replaces selected instances of the word "not" with the word "definitely".
fapnip
Explorer At Heart
Explorer At Heart
Posts: 430
Joined: Mon Apr 06, 2020 1:54 pm

Re: EOS Feature Request/Bug: Regular Expression support

Post by fapnip »

Unfortunately, we're at the mercy of seraph0x's willingness to set REGEXP_MODE = 1.

Because of the way EOS uses the JS interpreter, mode 2 just isn't a workable solution.
seraph0x
Administrator
Administrator
Posts: 2654
Joined: Sun Jul 23, 2006 8:58 am

Re: EOS Feature Request/Bug: Regular Expression support

Post by seraph0x »

Ask and you shall receive - I've enabled REGEXP_MODE=1. Because each tease is running in its own tab, I'm not too concerned with teases locking up.

This update to Eos did include some other changes, too. Hopefully I didn't break anything - didn't have very much time to test.
User avatar
Shattered
Experimentor
Experimentor
Posts: 1242
Joined: Fri Jan 11, 2013 6:41 pm
I am a: Switch
Location: United Kingdom

Re: EOS Feature Request/Bug: Regular Expression support

Post by Shattered »

seraph0x wrote: Sun May 31, 2020 8:33 am Ask and you shall receive - I've enabled REGEXP_MODE=1. Because each tease is running in its own tab, I'm not too concerned with teases locking up.

This update to Eos did include some other changes, too. Hopefully I didn't break anything - didn't have very much time to test.
I fear you may have broke...literally everything, my latest tease is now unplayable and variable inputs don't seem to work at all :unsure:

The 3 places I've tested in my tease the 'prompt' command doesn't proceed to anything once you type something in. It did before.
seraph0x
Administrator
Administrator
Posts: 2654
Joined: Sun Jul 23, 2006 8:58 am

Re: EOS Feature Request/Bug: Regular Expression support

Post by seraph0x »

Shattered wrote: Sun May 31, 2020 11:25 am I fear you may have broke...literally everything, my latest tease is now unplayable and variable inputs don't seem to work at all :unsure:

The 3 places I've tested in my tease the 'prompt' command doesn't proceed to anything once you type something in. It did before.
The prompt bug is fixed now, so please test again and let me know if there are any other issues.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 430
Joined: Mon Apr 06, 2020 1:54 pm

Re: EOS Feature Request/Bug: Regular Expression support

Post by fapnip »

seraph0x wrote: Sun May 31, 2020 8:33 am Ask and you shall receive - I've enabled REGEXP_MODE=1. Because each tease is running in its own tab, I'm not too concerned with teases locking up.

This update to Eos did include some other changes, too. Hopefully I didn't break anything - didn't have very much time to test.
Thank you!
Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests