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

Fix lexer to analyze escape characters #1043

Merged
merged 2 commits into from
Jun 22, 2022
Merged

Fix lexer to analyze escape characters #1043

merged 2 commits into from
Jun 22, 2022

Conversation

soutaro
Copy link
Member

@soutaro soutaro commented Jun 22, 2022

  • Make it more explicit in lexer.re
  • Unescape \\ too in unescape.c

Closes #996

* Make it more explicit in `lexer.re`
* Unescape `\\` too in unescape.c
@@ -94,8 +94,8 @@ start:
"untyped" { return next_token(state, kUNTYPED); }
"void" { return next_token(state, kVOID); }

dqstring = ["] ("\\"["] | [^"\x00])* ["];
sqstring = ['] ("\\"['] | [^'\x00])* ['];
dqstring = ["] ("\\"[abefnrstv"\\] | [^"\\\x00])* ["];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in #996 (comment)

@@ -30,6 +30,7 @@ void rbs_unescape_string(VALUE string) {
rb_hash_aset(HASH, rb_str_new_literal("\\t"), rb_str_new_literal("\t"));
rb_hash_aset(HASH, rb_str_new_literal("\\v"), rb_str_new_literal("\v"));
rb_hash_aset(HASH, rb_str_new_literal("\\\""), rb_str_new_literal("\""));
rb_hash_aset(HASH, rb_str_new_literal("\\\\"), rb_str_new_literal("\\"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to unescape two backslashes too.

@soutaro soutaro merged commit a2ed9ff into master Jun 22, 2022
@soutaro soutaro deleted the fix-lexer branch June 22, 2022 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Syntax error when string union with escape
2 participants