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

Support octal escape sequences in string literals (fixes #70) #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/slimit/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,15 @@ def t_regex_error(self, token):
| \\[a-zA-Z!-\/:-@\[-`{-~] # or escaped characters
| \\x[0-9a-fA-F]{2} # or hex_escape_sequence
| \\u[0-9a-fA-F]{4} # or unicode_escape_sequence
| \\(?:[1-7][0-7]{0,2}|[0-7]{2,3}) # or octal_escape_sequence (spec B.1.2)
)*? # zero or many times
(?: \\\n # multiline ?
(?:
[^"\\\n\r] # no \, line terminators or "
| \\[a-zA-Z!-\/:-@\[-`{-~] # or escaped characters
| \\x[0-9a-fA-F]{2} # or hex_escape_sequence
| \\u[0-9a-fA-F]{4} # or unicode_escape_sequence
| \\(?:[1-7][0-7]{0,2}|[0-7]{2,3}) # or octal_escape_sequence (spec B.1.2)
)*? # zero or many times
)*
") # closing double quote
Expand All @@ -388,13 +390,15 @@ def t_regex_error(self, token):
| \\[a-zA-Z!-\/:-@\[-`{-~] # or escaped characters
| \\x[0-9a-fA-F]{2} # or hex_escape_sequence
| \\u[0-9a-fA-F]{4} # or unicode_escape_sequence
| \\(?:[1-7][0-7]{0,2}|[0-7]{2,3}) # or octal_escape_sequence (spec B.1.2)
)*? # zero or many times
(?: \\\n # multiline ?
(?:
[^'\\\n\r] # no \, line terminators or '
| \\[a-zA-Z!-\/:-@\[-`{-~] # or escaped characters
| \\x[0-9a-fA-F]{2} # or hex_escape_sequence
| \\u[0-9a-fA-F]{4} # or unicode_escape_sequence
| \\(?:[1-7][0-7]{0,2}|[0-7]{2,3}) # or octal_escape_sequence (spec B.1.2)
)*? # zero or many times
)*
') # closing single quote
Expand Down
4 changes: 2 additions & 2 deletions src/slimit/lextab.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/slimit/tests/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def test_illegal_unicode_char_in_identifier(self):
[r"STRING '\u0001'", r'STRING "\uFCEF"', r"STRING 'a\\\b\n'"]
),
(ur'"тест строки\""', [ur'STRING "тест строки\""']),
# octal escape sequences (non-strict mode)
(r"""'\251'""", [r"""STRING '\251'"""]),
# Bug - https://github.com/rspivak/slimit/issues/5
(r"var tagRegExp = new RegExp('<(\/*)(FooBar)', 'gi');",
['VAR var', 'ID tagRegExp', 'EQ =',
Expand Down
604 changes: 302 additions & 302 deletions src/slimit/yacctab.py

Large diffs are not rendered by default.