question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error parsing strings with curly braces in JavaScript blocks

See original GitHub issue

This is example that break the parser:

str.replace(/\$\{/g, '\\${');

it throws:

Expected code block but "\n" found.

In my language playground.

As a workaround I’ve used escaped value:

str.replace(/\$\x7b/g, '\\$\x7b');

Curly braces in strings and regex confuse the parser. I’ve tried to use this on a Website:

{
  function foo(x) {
     return x.replace(/\}/g, '}');
  }
}

and it throws random errors.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Minguncommented, Feb 15, 2022

I plan to make an API that will allow plugins replace source code parsing part of the peggy grammar, so the plugins for other languages can implement a minimal subset to correctly parse braces for their languages. Peggy itself will contain only JS parser subset.

When this will be implemented, I’ll make issues/PRs to known plugins.

0reactions
Minguncommented, Jun 1, 2022

I think, we can leave this open until proposed solution (pluggable CodeBlock parsers) will be implemented. This, however, requires some work to design a way for composing grammars, which is also required for import feature. Of course, we can implement a special mechanism just to support this case, but I think it will be better to use a generic solution

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Splitting a string with curly braces as delimeters?
Split returns an array based on a delimiter, so if the delimiter is ... The value of the curly blocks are every 2...
Read more >
Curly braces in JavaScript code must be balanced #89 - GitHub
Literal string containing curly brace not recognized within code block #398 ... #534 improves the error message for unbalanced braces.
Read more >
SyntaxError: missing } after function body - JavaScript | MDN
The JavaScript exception "missing } after function body" occurs when there is a ... Check if any closing curly brackets or parenthesis are...
Read more >
Airbnb JavaScript Style Guide()
Why? Per the eslint documentation, unary increment and decrement statements are subject to automatic semicolon insertion and can cause silent errors with ...
Read more >
CoffeeScript
Instead of using curly braces { } to surround blocks of code in functions, ... Like JavaScript and many other languages, CoffeeScript supports...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found