BruceSherwood / vpython-jupyter

This repository has been moved to https://github.com/vpython/vpython-jupyter
64 stars 33 forks source link

Typescript Error: unmatched `)` in `vpython-jupyter/vpython/vpython_libraries/plotly.min.js` #53

Closed KHALAK closed 6 years ago

BruceSherwood commented 6 years ago

I'm baffled. Chrome gives a bit more information than Firefox: Invalid regular expression: /^rgb(['\s([+-]?\d+)\s', '\s([+-]?\d+)\s', '\s([+-]?\d+)\s'])$/: Unmatched ')'

I don't see an unmatched parenthesis in the expression above.

The console points to D = new RegExp("^rgb\(" + [E, E, E] + "\)$"), which doesn't seem to have a parenthesis error, where E = "\s([+-]?\d+)\s" also seems to have no parenthesis error. Moreover, the error is intermittent, at least on Chrome (maybe it's constant on Firefox?). I have no idea how to proceed.

BruceSherwood commented 6 years ago

Good suggestion. I'll try that.

jcoady commented 6 years ago

Try testing it with the following regular expression tester website. Maybe it can help you figure out what the problem is.

https://regex101.com/

Also try google the words "regular expression javascript unmatched" for hints of how others may have solved similar problem with unmatched ')' .

John

From: "BruceSherwood" notifications@github.com To: "BruceSherwood/vpython-jupyter" vpython-jupyter@noreply.github.com Cc: "Subscribed" subscribed@noreply.github.com Sent: Tuesday, August 7, 2018 2:13:22 PM Subject: Re: [BruceSherwood/vpython-jupyter] Typescript Error: unmatched ) in vpython-jupyter/vpython/vpython_libraries/plotly.min.js (#53)

Good suggestion. I'll try that.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .

jcoady commented 6 years ago

I tried the following in the regular expression tester and it matched the parenthesis

^rgb(['\s([+-]?\d+)\s', '\s([+-]?\d+)\s', '\s([+-]?\d+)\s'])$

I replaced the first [ with [ and the closing ] with ] . I don't know if this will solve your problem but you can try it out at to see if it gives you the functionality you want with the regular expression.

John

From: "johncoady" johncoady@shaw.ca To: "BruceSherwood/vpython-jupyter" reply@reply.github.com Cc: "BruceSherwood/vpython-jupyter" vpython-jupyter@noreply.github.com, "Subscribed" subscribed@noreply.github.com Sent: Tuesday, August 7, 2018 2:33:25 PM Subject: Re: [BruceSherwood/vpython-jupyter] Typescript Error: unmatched ) in vpython-jupyter/vpython/vpython_libraries/plotly.min.js (#53)

Try testing it with the following regular expression tester website. Maybe it can help you figure out what the problem is.

https://regex101.com/

Also try google the words "regular expression javascript unmatched" for hints of how others may have solved similar problem with unmatched ')' .

John

From: "BruceSherwood" notifications@github.com To: "BruceSherwood/vpython-jupyter" vpython-jupyter@noreply.github.com Cc: "Subscribed" subscribed@noreply.github.com Sent: Tuesday, August 7, 2018 2:13:22 PM Subject: Re: [BruceSherwood/vpython-jupyter] Typescript Error: unmatched ) in vpython-jupyter/vpython/vpython_libraries/plotly.min.js (#53)

Good suggestion. I'll try that.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .

BruceSherwood commented 6 years ago

This is very strange. Even in the newest Plotly for JavaScript, ignoring the pretty printing of Chrome that converts \ to \, the plotly library contains a large number of structures of the following kind:

E="\s([+-]?\d+)\s" D1=new RegExp("^rgb\("+[E,E,E]+"\)$")

The argument of RegExp looks like this (pretty printed to display \ as ): ^rgb(['\s([+-]?\d+)\s', '\s([+-]?\d+)\s', '\s([+-]?\d+)\s'])$

Since the plotly library expects the form "rgb(r,g,b)", this RegExp expression seems to make no sense, since there are brackets where none would seem to be expected, and there are commas that are not strings. In fact, RegExp gives an error with this argument.

Compare with this argument for RegExp: "^rgb\("+E+','+E+','+E+"\)$")" which would yield "rgb(r,g,b)".

I'm again baffled as to how plotly works at all. I must be missing some arcane property of RegExp.

jcoady commented 6 years ago

I think the problem has to do with the square brackets [ ] in

D1=new RegExp("^rgb("+[E,E,E]+")$")

Try putting \ in front of the opening and closing square bracket. Change the above to

D1=new RegExp("^rgb("+[E,E,E]+")$")

See if this change for the above line of code fixes the problem.

John

From: "BruceSherwood" notifications@github.com To: "BruceSherwood/vpython-jupyter" vpython-jupyter@noreply.github.com Cc: "johncoady" johncoady@shaw.ca, "Comment" comment@noreply.github.com Sent: Tuesday, August 7, 2018 9:16:52 PM Subject: Re: [BruceSherwood/vpython-jupyter] Typescript Error: unmatched ) in vpython-jupyter/vpython/vpython_libraries/plotly.min.js (#53)

This is very strange. Even in the newest Plotly for JavaScript, ignoring the pretty printing of Chrome that converts \ to , the plotly library contains a large number of structures of the following kind:

E="\s([+-]?\d+)\s" D1=new RegExp("^rgb("+[E,E,E]+")$")

The argument of RegExp looks like this (pretty printed to display \ as ): ^rgb(['\s([+-]?\d+)\s', '\s([+-]?\d+)\s', '\s([+-]?\d+)\s'])$

Since the plotly library expects the form "rgb(r,g,b)", this RegExp expression seems to make no sense, since there are brackets where none would seem to be expected, and there are commas that are not strings. In fact, RegExp gives an error with this argument.

Compare with this argument for RegExp: "^rgb("+E+','+E+','+E+")$")" which would yield "rgb(r,g,b)".

I'm again baffled as to how plotly works at all. I must be missing some arcane property of RegExp.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub , or mute the thread .

BruceSherwood commented 6 years ago

Consider the following JavaScript code:

var E="\\s*([+-]?\\d+)\\s*"
var F = "^rgb\\("+E+','+E+','+E+"\\)$"
var G = "^rgb\\("+[E,E,E]+"\\)$"
console.log(F)
console.log(G)
var D=new RegExp(F)
var m = 'rgb(1,2,3)'.match(D)
console.log(m[0])

This is the output, which is correct:

^rgb\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*\)$
^rgb\(['\s*([+-]?\d+)\s*', '\s*([+-]?\d+)\s*', '\s*([+-]?\d+)\s*']\)$
rgb(1,2,3)

If instead I use RegExp(G) I get the error, and I get errors if I put backslashes in front of the brackets, which doesn't surprise me, because no variant of G is a legal JavaScript regular expression.

I'm left baffled as to how the very strange form G shows up in plotly.

BruceSherwood commented 6 years ago

My analysis was correct. When I corrected those strange RegExp statements in plotly.min.js, the error messages went away in Jupyter VPython. I'll ask Matt Craig to build a new installer. Thanks, Khalak, for pointing out the problem.

BruceSherwood commented 6 years ago

Yes, sigh. I made a mistake and didn't update all the things I had to update. I'm working on it.

BruceSherwood commented 6 years ago

Thanks. And I also just now fixed long-standing bugs in the curve and points objects, so we'll make a new release soon.