Giter Site home page Giter Site logo

Comments (6)

PhilippeSigaud avatar PhilippeSigaud commented on July 18, 2024

Yes, quote and double quote escapes is a difficult subject: the double quote is passed as input and transformed into D code, which is itself assembled as a string. So quotes create problems.

It's easier to use predefined parsers to deal with them (you get them when you import pegged.grammar):

  • Quote, that recognizes '
  • DoubleQuote, that recognizes "
  • BackQuote, that recognizes `

See https://github.com/PhilippeSigaud/Pegged/wiki/Predefined-Parsers

There are also predefined parsers for end of lines, slashes, and so on.

Do you have an example of a failed compilation?

from pegged.

meh avatar meh commented on July 18, 2024
import pegged.grammar;

mixin(grammar(`A < '"'`));

void main ()
{

}
lol.d(90): Error: unterminated string constant starting at lol.d(49)
lol.d(90): Error: found 'EOF' when expecting ')' following template argument list
lol.d(90): Error: members expected
lol.d(90): Error: { } expected following aggregate declaration
lol.d(90): Error: } expected following member declarations in aggregate

from pegged.

PhilippeSigaud avatar PhilippeSigaud commented on July 18, 2024

Yeah, that's because it's difficult to propagate a double quote as a string argument to a template, when this template is itself being assembled as a string.

Use DoubleQuote:

import pegged.grammar;

mixin(grammar(`A < DoubleQuote`));

void main ()
{
}

from pegged.

meh avatar meh commented on July 18, 2024

Will do, just checking it wasn't an unknown bug, thanks :)

from pegged.

PhilippeSigaud avatar PhilippeSigaud commented on July 18, 2024

It's a known bug :) I should write a wiki page specifically on string escaping.

IIRC I tried to automatically escape quotes with " and ', but it didn't work at the time.

from pegged.

meh avatar meh commented on July 18, 2024

I should write a wiki page specifically on string escaping.

That would be really useful.

from pegged.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.