Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8778387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:31:31+00:00 2026-06-13T19:31:31+00:00

I am using PEG.js to create a parser which includes parsing strings. The strings

  • 0

I am using PEG.js to create a parser which includes parsing strings.
The strings containing any kind of character are wrapped by quotes " and may contain escaped quotes \".
So far I have the following rule:

start
    = ["] string:(( '\\"' {return '"';} / [^"])*) ["]
        {return string.join('');}

It works in the PEG.js Online Version and produces "abc\"def" for the given input "abc\"def".

The parser generated for Node.js version 0.6.21 with PEG.js version 0.7.0 is executed the following way

var result = parser.parse('"abc\"def"');

and produces the following error:

{ name: 'SyntaxError',
  expected: [],
  found: 'd',
  message: 'Expected end of input but "d" found.',
  offset: 5,
  line: 1,
  column: 6 }

However, using \\" instead of \" succeeds with the expected output.

var result = parser.parse('"abc\\"def"'); // parses correctly

Is there an explanation or workaround for this problem?
In particular, it is not possible for me to double escape all quotes in the expected input of the parser.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:31:33+00:00Added an answer on June 13, 2026 at 7:31 pm

    The string literal in this statement…

    var result = parser.parse('"abc\"def"');

    … actually doesn’t contain a backslash. In JavaScript this sequence of symbols – \" – is parsed as a single one – " – no matter what quotation marks are used to delimit a string – double or single ones. JS doesn’t interpolate variable and expressions in strings, and there is basically no difference between those.

    This string – '"abc\\"def"' – however, has a backslash: it’s encoded by that \\ sequence. Note that it’s not necessary to use another backslash to escape the double quote itself (as delimiters are single quotation marks). But you’d have to, if "\"abc\\\"def\"" form were used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
Using Microsoft SQL Server 2005, is there any way to see when a table
I've been building parsers using a Maven Plugin (i.e. calling PEG.js from Java code)
Using MVC2 I have an AJAX form which is posting to a bound model.
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
The question is very straightforward: Is it possible to parse PHP using PEG? I
Using Jenkins or Hudson I would like to create a pipeline of builds with
Using MVVM. I have a DataTemplate which I am using to display an expander
I am writing a lexer for Haskell using JavaScript and Parsing Expression Grammar, the
Using android 2.3.3, I have a background Service which has a socket connection. There's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.