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

Tagged literal support #304

Merged
merged 5 commits into from
Jul 27, 2019
Merged

Tagged literal support #304

merged 5 commits into from
Jul 27, 2019

Conversation

matter123
Copy link
Collaborator

@matter123 matter123 commented Jul 11, 2019

Implements #236.

This PR adds a generic way of supporting tagged raw string literals. Currently, only regex patterns are supported. The regex grammar comes from embedding MagicPython's regex grammar.

raw_string literals were moved to a separate file to be able to support many different types of tagged literals without cluttering the main grammar.

Example Image:
Screenshot from 2019-07-11 01-30-52

@matter123 matter123 changed the title WIP: tagged literal support Tagged literal support Jul 12, 2019
@matter123
Copy link
Collaborator Author

With the tests passing, I'm removing the WIP status.

@matter123
Copy link
Collaborator Author

When #295 is merged in, we should make a copy of magic pythons regexp and add an early bailout pattern of /(?=\)(?:_r|re|regex)")/

That should prevent the issue described in MagicStack/MagicPython#27 (comment) which is present with the PR as well.

@matter123
Copy link
Collaborator Author

Based on microsoft/vscode#1751 (comment)
support for SQL has been added.
Screenshot from 2019-07-15 19-17-12

@jeff-hykin
Copy link
Owner

So does this require that the string start with "re" for it to be regex and the string start with "SQL" to be sql?

@matter123
Copy link
Collaborator Author

matter123 commented Jul 25, 2019

For regex: _r, re, regex
For sql: SQL, PSQL, DMl and lower case variants

@jeff-hykin
Copy link
Owner

Wouldn't that mess up the regex pattern though?
Here's an example from https://solarianprogrammer.com/2011/10/16/cpp-11-raw-strings-literals-tutorial/

string input;
regex rr(R"(((\+|-)?[[:digit:]]+)(\.(([[:digit:]]+)?))?((e|E)((\+|-)?)[[:digit:]]+)?)");
cout << "Give me a real number!" << endl;
cin >> input;
if ( regex_match(input,rr) )  {
        cout<<"float"<<endl;
} else {
    cout<<"Invalid input"<<endl;
}

@matter123
Copy link
Collaborator Author

Yes, that would not get syntax highlighting because it's not tagged. As discussed in #236 tagging of generic raw strings requires support from vscode.

@jeff-hykin
Copy link
Owner

Wow, I need to do a better job of reading. Thanks for this feature 👍

@jeff-hykin jeff-hykin merged commit eb9b461 into master Jul 27, 2019
@matter123 matter123 deleted the tagged-strings branch August 5, 2019 21:11
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.

2 participants