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 escaped CR and CRLF in strings #58
Support escaped CR and CRLF in strings #58
Conversation
The multi-string test cases were failing on Windows due to CRLF line endings. |
@jordanbtucker: you are totally awesome! Thanks for so many great suggestions and pull requests. I'm glad @aeisenberg stepped in for one, but he's on vacation, and I'm super busy with work right now. Given your awesome contributions so far, I'm going to make you a collaborator and give you push rights to this repo. Please do keep on opening pull requests and giving others a chance to review your changes, but you can now make the call to merge yourself. (E.g. for minor changes, or if no one has reviewed your code after some time.) Welcome to the team! =) |
} else if (ch === '\r') { | ||
if (peek() === '\n') { | ||
next(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions about this:
- Why do you need to see whether a
\n
is the next character? Is\r
by itself not enough to ignore? - Why is this within the
if (ch === '\\')
block? Isn't this looking at carriage returns only after an escaped backslash? Why not put this further down, next to the regularch === '\n'
check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ignore the second question; I understand. I forgot that our multi-line strings require a backslash escape, so this needs to come after that. =)
Still curious about the first q.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And btw, if \r
by itself should be accepted too, then you might not need this block of code at all (nor peek
of course). See the escapee
dictionary up top (if you haven't already) where \n
is handled.
The reason I'm handling
Therefore, any of the following combinations constitute an escaped new line:
This conforms to the LineContinuation production, which uses the LineTerminatorSequence production. There's no need to add |
I'm thinking I should create test cases for these before merging. Working on that now. |
I didn't mean why |
I don't think that will work. Supposed we added
When the parser hits the Now I ran some tests to confirm this too. |
Oh, got it! Duh, sorry about that. Thanks for explaining. =) |
# Since we're testing different representations of new lines, | ||
# treat all tests in this folder as binary files. | ||
|
||
* binary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, both this and the editorconfig.
Great test cases! 🚢 |
Support escaped CR and CRLF in strings. Add new peek method to facilitate look-aheads.
Support escaped CR and CRLF in strings
Support escaped CR and CRLF in strings.
Add new peek method to facilitate look-aheads.