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

Escape unescaped characters #170

Open
rizengie opened this issue Apr 2, 2021 · 1 comment
Open

Escape unescaped characters #170

rizengie opened this issue Apr 2, 2021 · 1 comment

Comments

@rizengie
Copy link

rizengie commented Apr 2, 2021

I've found this article on Stack Overflow which doesn't seem to help enable escaping non-escaped characters, in particular, parenthesis. The case I'm looking for here is to be able to parse Any Character until a set of characters (such as parenthesis and comma "),", and/or parenthesis and end of string.

My test case:

where=and(eq(someString,Call Trace (*54)),eq(someString,Call Trace (*54)))

The way our parser currently works, we use Parse.AnyChar.Except( '(', ')' ) I think it'd be more helpful to be able to say Until( "),").Or(")" + EndOfString)

Is there a current implementation on how to do this, or can this be added?

@nblumhardt
Copy link
Member

Hi! I haven't used Sprache in a long time, but I think:

Parse.AnyChar.Until(Parse.String("),").Or(Parse.String(")").AtEnd()))

is roughly the kind of thing you're looking for. There's something a bit awkward about constructing the grammar this way, though - it's rare for a parser to have to "care" about what comes after its matched input. In particular, an expression parser should usually take care of matching parentheses etc. --- Is the grammar something you have control over, or are you parsing the output of some other system that produces irregular strings?

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