Skip to content

repl: support mult-line string-keyed objects#21775

Closed
rubys wants to merge 0 commit into
nodejs:masterfrom
rubys:repl-json
Closed

repl: support mult-line string-keyed objects#21775
rubys wants to merge 0 commit into
nodejs:masterfrom
rubys:repl-json

Conversation

@rubys

@rubys rubys commented Jul 12, 2018

Copy link
Copy Markdown
Member

fixes #21657

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Jul 12, 2018
@jasnell jasnell requested review from BridgeAR and addaleax July 12, 2018 04:50
Comment thread lib/repl.js Outdated

@antsmartian antsmartian Jul 12, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In version v8.11.3, without this particular check, things works. I'm wondering, now with this code in place, we are sort of re-doing the check (may be?). May be I'm wrong here.

Actually as discussed in the issue, this change broken the partial JSON stuff. The diff is over here:
ebfa8b1#diff-293fefe850253c8c28e2481c0b7f76e2L647

As seen in the comments of PR, looks like partial template literal also broken in latest version. For example:

`io.js ${a
... }`

works in v8/9. But broken in v10x.

@Trott

Trott commented Jul 12, 2018

Copy link
Copy Markdown
Member

@nodejs/repl

@BridgeAR

Copy link
Copy Markdown
Member

@rubys In general, the idea is great. Because this is going in a direction where the code is starting to be properly parsed. I am not sure though if this is the right approach in the current state of the repl. The reason is that the repl itself has so many hacks that it's a nightmare.

It would be really awesome if you would be able to use acorn instead. I am not sure if that would help in this specific moment but I'll have a look into that tomorrow and maybe you could also check that?

@rubys

rubys commented Jul 13, 2018

Copy link
Copy Markdown
Member Author

@BridegeAR: you are being too kind. It clearly is a hack. Ideally, V8 would be implemented as a streaming parser, but that isn't required for the browser. As Acorn isn't a streaming parser, it isn't likely to be able to help us here.

The root problem is that the JavaScript grammar is ambiguous (at least at the tokenization level), and backtracking is sometimes needed.

Examples of valid JavaScript:

a=1
{a*2}
{a, a}
{a, a*2}
label: {a, a}

Only one of the lines above is an object literal.

@devsnek

devsnek commented Jul 13, 2018

Copy link
Copy Markdown
Member

@rubys btw we're working on rewriting the REPL from scratch: https://github.com/nodejs/repl

it might be a good place to experiment with different ways of consuming input, as its still fairly small.

@rubys

rubys commented Jul 13, 2018

Copy link
Copy Markdown
Member Author

I may have been too quick to discount acorn; it will probably need a patch to be landed to support this use case, but it looks doable. I'm traveling for the next four days, so it may not be until next week that I can take a look at this.

Comment thread lib/repl.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we split this out into a separate file in lib/internal/repl/?

@rubys

rubys commented Jul 13, 2018

Copy link
Copy Markdown
Member Author

Update: played with acorn on the first flight leg on this trip. Everything needed can be done with a plugin. Will create a separate pull request either later today or this weekend.

@rubys

rubys commented Jul 13, 2018

Copy link
Copy Markdown
Member Author

See #21805 for an acorn based implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

repl Issues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node REPL says "SyntaxError: unexpected symbol :" when parsing multi-line string-keyed objects (e.g. JSON)

7 participants