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

Add string escaping according to string regex format #2673

Merged
merged 2 commits into from
Aug 8, 2020

Conversation

thexa4
Copy link
Contributor

@thexa4 thexa4 commented Feb 20, 2020

Based on:

STRING -> @"@?\""(\""\""|[^\""])*\""";

Fixes #2672

(Warning: has not been tested yet, unable to compile right now)

@Dunbaratu Dunbaratu merged commit 1905d23 into KSP-KOS:develop Aug 8, 2020
@jonnyboyC
Copy link
Contributor

@Dunbaratu Does this now allow certain string escapes? Could you give an example? Mostly just trying to keep https://github.com/jonnyboyC/kos-language-server as in sync with master here a possible

@thexa4
Copy link
Contributor Author

thexa4 commented Aug 12, 2020

It makes print "hello""world". output hello"world

@jonnyboyC
Copy link
Contributor

Thanks!

@7ranceaddic7
Copy link

@thexa4 Is that really the desired result?

I would think that output should be hello""world, no?

@thexa4 thexa4 deleted the patch-1 branch August 12, 2020 21:30
@thexa4
Copy link
Contributor Author

thexa4 commented Aug 12, 2020

The advantage of treating a repeated quote as a single quote is that it allows you to represent all strings. If you use it as-is, you would not be able to write down a string literal that only contains ".

The way this is usually solved is by defining an escape character like \. "\"" would then become a " string literal. The other option is escaping by repeating the character. An example of this is printf. It uses the % character to as a field placeholder. This makes it impossible to print a string that contains an actual % character. The solution they use interprets a %% as a single literal %.

The existing parser syntax seems a lot like the printf case which is why I used this behavior.

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

Successfully merging this pull request may close these issues.

Escaped quotes in string literal are not unescaped
4 participants