Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed compilation with '"' #22

Closed
meh opened this issue May 26, 2012 · 6 comments
Closed

Failed compilation with '"' #22

meh opened this issue May 26, 2012 · 6 comments

Comments

@meh
Copy link
Contributor

meh commented May 26, 2012

It fails compilation if I put '"', using '\"' compiles fine.

@PhilippeSigaud
Copy link
Owner

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?

@meh
Copy link
Contributor Author

meh commented May 27, 2012

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

@PhilippeSigaud
Copy link
Owner

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 ()
{
}

@meh
Copy link
Contributor Author

meh commented May 27, 2012

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

@meh meh closed this as completed May 27, 2012
@PhilippeSigaud
Copy link
Owner

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.

@meh
Copy link
Contributor Author

meh commented May 27, 2012

I should write a wiki page specifically on string escaping.

That would be really useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants