Open zatherz opened 7 years ago
Is this what you're looking for?
var body = (-(!('"'._() | @"\") + Peg.Any | @"\\" | @"\""")).Capture();
var pattern = '"' + body + '"';
Console.WriteLine(pattern.Parse("\"abc\"")[body]);
Console.WriteLine(pattern.Parse("\"a\\\"bc\"")[body]);
Prints out:
abc a\"bc
Hey, how do I make that work with this? It still prints the "
s around. Also, how can I make inserting a C# string "\"abc\\\"\""
result in abc"
instead of abc\"
?
public virtual Expression Keyword() {
var alnum = +('A'.To('Z') | 'a'.To('z') | '0'.To('9'));
// https://github.com/kswoll/npeg/issues/2
var quotedbase = (-(!('"'._() | @"\") + Peg.Any | @"\\" | @"\""")).Capture();
return alnum | ('"' + quotedbase + '"');
}
Sorry for all the questions but I'm only somewhat used to lpeg in lua, npeg works a bit differently.
Can you show me the code where you're printing out the result (that still shows the "
s)?
Yes, it's here: https://gitlab.com/Zatherz/eggshell. Relevant file: https://gitlab.com/Zatherz/eggshell/blob/master/EGGShell/EGGGrammar.cs.
Is there any way to parse only when a character is found, but don't return it? For example, with the quoted string example, I'd like to return the actual inner string.
"abc"
would return the stringabc
,"a\"bc"
would return the stringa"bc
, etc.