In many places in the code we use the idiom:
x < parser->end && *x == 'y'
which is essentially an extension of an existing pattern:
- `peek()` looks at `parser->current.end`
- `peek_at()` looks at `(parser->current.end + offset)`
This commit introduces a new inline function, `peek_addr`, which
accepts a pointer and encapsulates the address value check and
conditional dereferencing. The result is more readable code, and more
ubiquitous safety checks on pointer values, allowing us to rewrite the
above as:
peek_addr(parser, x) == 'y'
Also:
- change the type of `peek_at()`'s offset argument from `size_t` to
`ptrdiff_t` so that it can accept negative offsets.
- use `current_token_starts_line` in one place where the equivalent
code is inline.
- use `peek` or `peek_at` to replace inline code in a few places
These changes simplify the code and make it easier to visually spot
patterns, particularly around line-endings (which will be a subject of
a future pull request).
4c608d53ea
YARP commits were synced out of order. We are doing this reset
commit to ensure that all files are currently correct and we can
proceed with monitoring syncs so this doesn't happen again.
Previously, parsing a snippet like this:
%r\nfoo\n
would result in tracking the second newline twice, resulting in a
failed runtime assertion.
Fixing that issue reveals another bug, which is that the _first_
newline was not being tracked at all. So we introduce a call to
yp_newline_list right when we construct the REGEXP_BEGIN token.
0d5d759091
It makes it more difficult to find all locations where a variable
is written to if they're just read nodes. To keep things consistent
we should make them write nodes.
840e094045
Previously, parsing a snippet like this:
%r\nfoo\n
would result in tracking the second newline twice, resulting in a
failed runtime assertion.
Fixing that issue reveals another bug, which is that the _first_
newline was not being tracked at all. So we introduce a call to
yp_newline_list right when we construct the REGEXP_BEGIN token.
0d5d759091
Set heredoc_end to NULL at the start of lexing a heredoc, to avoid
having state from the previous heredoc confuse the parser's current
location.
21ee304f0e
Prior to this commit, we folded the flags into the type. This created
extra overhead when calculating the type and setting the flags. This
commit separates them.
b783a5678c
* Otherwise it is undefined behavior to access the field of another `.as`.
* Accessing the right `.as` field according mode would be extra overhead.
7dc41ee803