Skip to content

strings are parsed incorrectly when an unexpected character after a \ is used #12

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

Open
scharf opened this issue Jul 17, 2013 · 0 comments

Comments

@scharf
Copy link

scharf commented Jul 17, 2013

the following strings are valid coffeesctipt (and javascript string):

s="\W"
s="\z"
s="\="

Javascript ignores any \ that is used for characters that are not expected.

Here is my proposal for a better string rule in xtext:

terminal STRING:
    "'''" -> "'''" |
    "'" ( (!("'"|'\\') | ('\\' !('\n' | '\r'))) ('\\' !('\n' | '\r') | !('\\'|"'"))*)? "'" |
    '"""' -> '"""' |
    '"' ( (!('"'|'\\') | ('\\' !('\n' | '\r'))) ('\\' !('\n' | '\r')  | !('\\'|'"'))*)? '"';

It would be nice to get a warning if an unexpected character is used in a string. But is should not fail to parse the rest of the file....

It would be nice to issue an (optional) warning if the character after a \ is not in the list of meaningful characters:

('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\')
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

1 participant