diff options
author | Mark Wielaard <mark@klomp.org> | 2021-07-25 15:31:10 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2021-07-25 15:31:19 +0200 |
commit | f2ce41608ae0f55e6910756054cddf08aa3678ff (patch) | |
tree | c4968ed914f23bd613ebb1ef644f71cf571d924b /gcc/tree-iterator.c | |
parent | 314b62ec787abdf320fcca8ceb09b8c9bcf72512 (diff) | |
download | gcc-f2ce41608ae0f55e6910756054cddf08aa3678ff.zip gcc-f2ce41608ae0f55e6910756054cddf08aa3678ff.tar.gz gcc-f2ce41608ae0f55e6910756054cddf08aa3678ff.tar.bz2 |
Support RangeFrom ([x..]) and RangeFromTo ([x..y]) in the parser
Parsing the .. (DOT_DOT) operator to get a range had two
issues. Trying to compile:
let block = [1,2,3,4,5];
let _rf = &block[1..];
let _rt = &block[..3];
let _rft = &block[2..4];
range.rs:4:23: error: found unexpected token ‘]’ in null denotation
4 | let _rf = &block[1..];
| ^
range.rs:4:24: error: expecting ‘]’ but ‘;’ found
4 | let _rf = &block[1..];
| ^
Since .. can represent either a range from or a range from-to it can
be followed by an expression or not. We do have a hack in our
pratt-parser so that it is allowed to return a nullptr. But even in
that case it will have swallowed the next token. Add another hack to
the pratt-parser so that if the next token is one that cannot start an
expression and the caller allows a nullptr return then don't skip the
token and return immediately.
After this patch we can parse the above range expressions, but we
still don't handle them fully:
range.rs:4:20: fatal error: Failed to lower expr: [1..]
4 | let _rf = &block[1..];
| ^
Ranges are actually syntactic sugar for std::ops::Range[From|To].
Diffstat (limited to 'gcc/tree-iterator.c')
0 files changed, 0 insertions, 0 deletions