array types can now use an expression to define the array size
this was surprisingly non-trivial
This commit is contained in:
parent
4f70fa2246
commit
cbbbb7989a
|
@ -3350,23 +3350,24 @@ pub mod ast_gen {
|
|||
fn parse_array_type(&mut self, tokens: &mut TokenIterator) -> ParseResult<Index> {
|
||||
let loc = tokens.current_source_location();
|
||||
let length_expr = self.parse_bracketed(tokens, |this, tokens| {
|
||||
let next = tokens.peek_token().ok_or(ErrorInfo {
|
||||
error: ParseError::UnexpectedEndOfTokens,
|
||||
loc: tokens.current_source_location(),
|
||||
})?;
|
||||
match next.token() {
|
||||
Token::IntegerBinConstant
|
||||
| Token::IntegerHexConstant
|
||||
| Token::IntegerOctConstant
|
||||
| Token::IntegerConstant => {
|
||||
_ = tokens.next();
|
||||
Ok(this.parse_integral_constant(&next, next.source_location()))
|
||||
}
|
||||
_ => Err(ErrorInfo {
|
||||
error: ParseError::ExpectedConstantLiteral,
|
||||
loc: tokens.current_source_location(),
|
||||
}),
|
||||
}
|
||||
this.parse_expr(tokens)
|
||||
// let next = tokens.peek_token().ok_or(ErrorInfo {
|
||||
// error: ParseError::UnexpectedEndOfTokens,
|
||||
// loc: tokens.current_source_location(),
|
||||
// })?;
|
||||
// match next.token() {
|
||||
// Token::IntegerBinConstant
|
||||
// | Token::IntegerHexConstant
|
||||
// | Token::IntegerOctConstant
|
||||
// | Token::IntegerConstant => {
|
||||
// _ = tokens.next();
|
||||
// Ok(this.parse_integral_constant(&next, next.source_location()))
|
||||
// }
|
||||
// _ => Err(ErrorInfo {
|
||||
// error: ParseError::ExpectedConstantLiteral,
|
||||
// loc: tokens.current_source_location(),
|
||||
// }),
|
||||
// }
|
||||
})?;
|
||||
|
||||
let &[cnst, vol, noalias] =
|
||||
|
|
6
tests/legal/array_complex.sea
Normal file
6
tests/legal/array_complex.sea
Normal file
|
@ -0,0 +1,6 @@
|
|||
const ARRAY_SIZE: usize = 16;
|
||||
|
||||
fn main() {
|
||||
var arr: [ARRAY_SIZE << 1] u8;
|
||||
arr[0] = 1;
|
||||
}
|
6
tests/legal/comptime.sea
Normal file
6
tests/legal/comptime.sea
Normal file
|
@ -0,0 +1,6 @@
|
|||
const RANDOM: u32 = (3 + 54*5) >> 3;
|
||||
|
||||
fn main() -> u32 {
|
||||
let a: u32 = (3 + 54*5) >> 3;
|
||||
RANDOM
|
||||
}
|
Loading…
Reference in a new issue