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> {
|
fn parse_array_type(&mut self, tokens: &mut TokenIterator) -> ParseResult<Index> {
|
||||||
let loc = tokens.current_source_location();
|
let loc = tokens.current_source_location();
|
||||||
let length_expr = self.parse_bracketed(tokens, |this, tokens| {
|
let length_expr = self.parse_bracketed(tokens, |this, tokens| {
|
||||||
let next = tokens.peek_token().ok_or(ErrorInfo {
|
this.parse_expr(tokens)
|
||||||
error: ParseError::UnexpectedEndOfTokens,
|
// let next = tokens.peek_token().ok_or(ErrorInfo {
|
||||||
loc: tokens.current_source_location(),
|
// error: ParseError::UnexpectedEndOfTokens,
|
||||||
})?;
|
// loc: tokens.current_source_location(),
|
||||||
match next.token() {
|
// })?;
|
||||||
Token::IntegerBinConstant
|
// match next.token() {
|
||||||
| Token::IntegerHexConstant
|
// Token::IntegerBinConstant
|
||||||
| Token::IntegerOctConstant
|
// | Token::IntegerHexConstant
|
||||||
| Token::IntegerConstant => {
|
// | Token::IntegerOctConstant
|
||||||
_ = tokens.next();
|
// | Token::IntegerConstant => {
|
||||||
Ok(this.parse_integral_constant(&next, next.source_location()))
|
// _ = tokens.next();
|
||||||
}
|
// Ok(this.parse_integral_constant(&next, next.source_location()))
|
||||||
_ => Err(ErrorInfo {
|
// }
|
||||||
error: ParseError::ExpectedConstantLiteral,
|
// _ => Err(ErrorInfo {
|
||||||
loc: tokens.current_source_location(),
|
// error: ParseError::ExpectedConstantLiteral,
|
||||||
}),
|
// loc: tokens.current_source_location(),
|
||||||
}
|
// }),
|
||||||
|
// }
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let &[cnst, vol, noalias] =
|
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