[parser] Remove mut and type keywords.

As discussed, these are no longer in the grammar. If and when we need them, we
will re-add them.

This also removes some extra code that gives a specific error when mut is
used. However, that is in fact another bug, because `mut` is a valid identifier
in the current grammar, and thus this extra code unjustly rejects code that uses
`mut` as an identifier.

Adjust some tests and expectations.
This commit is contained in:
Alessandro Coglio 2022-05-13 23:36:08 -07:00
parent 0e24e670bb
commit 2fbaf759db
8 changed files with 22 additions and 46 deletions

View File

@ -85,14 +85,9 @@ impl ParserContext<'_> {
/// Returns a [`FunctionInput`] AST node if the next tokens represent a function parameter.
pub fn parse_function_parameter(&mut self) -> Result<FunctionInput> {
let mode = self.parse_function_parameter_mode()?;
let mutable = self.eat(&Token::Mut).then(|| self.prev_token.clone());
let name = self.expect_ident()?;
if let Some(mutable) = &mutable {
self.emit_err(ParserError::mut_function_input(mutable.span + name.span));
}
self.expect(&Token::Colon)?;
let type_ = self.parse_type()?.0;
Ok(FunctionInput::Variable(FunctionInputVariable::new(

View File

@ -219,10 +219,7 @@ impl ParserContext<'_> {
/// Returns a [`VariableName`] AST node if the next tokens represent a variable name with
/// valid keywords.
pub fn parse_variable_name(&mut self, decl_ty: Declare, span: Span) -> Result<VariableName> {
if self.eat(&Token::Mut) {
self.emit_err(ParserError::let_mut_statement(self.prev_token.span + span));
}
pub fn parse_variable_name(&mut self, decl_ty: Declare, _span: Span) -> Result<VariableName> {
let name = self.expect_ident()?;
Ok(VariableName {

View File

@ -422,11 +422,9 @@ impl Token {
"in" => Token::In,
"input" => Token::Input,
"let" => Token::Let,
"mut" => Token::Mut,
"public" => Token::Public,
"return" => Token::Return,
"true" => Token::True,
"type" => Token::Type,
"u8" => Token::U8,
"u16" => Token::U16,
"u32" => Token::U32,

View File

@ -124,11 +124,9 @@ pub enum Token {
If,
In,
Let,
Mut,
/// For public inputs.
Public,
Return,
Type,
// Meta Tokens
Eof,
@ -156,11 +154,9 @@ pub const KEYWORD_TOKENS: &[Token] = &[
Token::In,
Token::Input,
Token::Let,
Token::Mut,
Token::Public,
Token::Return,
Token::True,
Token::Type,
Token::U8,
Token::U16,
Token::U32,
@ -198,11 +194,9 @@ impl Token {
Token::In => sym::In,
Token::Input => sym::input,
Token::Let => sym::Let,
Token::Mut => sym::Mut,
Token::Public => sym::Public,
Token::Return => sym::Return,
Token::True => sym::True,
Token::Type => sym::Type,
Token::U8 => sym::u8,
Token::U16 => sym::u16,
Token::U32 => sym::u32,
@ -291,10 +285,8 @@ impl fmt::Display for Token {
If => write!(f, "if"),
In => write!(f, "in"),
Let => write!(f, "let"),
Mut => write!(f, "mut"),
Public => write!(f, "public"),
Return => write!(f, "return"),
Type => write!(f, "type"),
Eof => write!(f, "<eof>"),
}
}

View File

@ -70,7 +70,5 @@ outputs:
- "Error [EPAR0370009]: unexpected string: expected 'expression', got 'if'\n --> test:1:1\n |\n 1 | if\n | ^^"
- "Error [EPAR0370009]: unexpected string: expected 'expression', got 'in'\n --> test:1:1\n |\n 1 | in\n | ^^"
- "Error [EPAR0370009]: unexpected string: expected 'expression', got 'let'\n --> test:1:1\n |\n 1 | let\n | ^^^"
- "Error [EPAR0370009]: unexpected string: expected 'expression', got 'mut'\n --> test:1:1\n |\n 1 | mut\n | ^^^"
- "Error [EPAR0370023]: Expected more characters to lex but found none."
- "Error [EPAR0370009]: unexpected string: expected 'expression', got 'return'\n --> test:1:1\n |\n 1 | return\n | ^^^^^^"
- "Error [EPAR0370009]: unexpected string: expected 'expression', got 'type'\n --> test:1:1\n |\n 1 | type\n | ^^^^"

View File

@ -2,4 +2,4 @@
namespace: Parse
expectation: Fail
outputs:
- "Error [EPAR0370013]: function func(mut a: u32) { ... } is deprecated. Passed variables are mutable by default.\n --> test:3:12\n |\n 3 | function f(mut a: u8) {}\n | ^^^^^\nError [EPAR0370005]: expected -> -- got '{'\n --> test:3:23\n |\n 3 | function f(mut a: u8) {}\n | ^"
- "Error [EPAR0370005]: expected : -- got 'a'\n --> test:3:16\n |\n 3 | function f(mut a: u8) {}\n | ^"

View File

@ -2,26 +2,26 @@
namespace: ParseStatement
expectation: Fail
outputs:
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x = expr;\n | ^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:11\n |\n 1 | let mut x = expr;\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x = ();\n | ^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:11\n |\n 1 | let mut x = ();\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x = x+y;\n | ^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:11\n |\n 1 | let mut x = x+y;\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x = (x,y);\n | ^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:11\n |\n 1 | let mut x = (x,y);\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x = x();\n | ^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:11\n |\n 1 | let mut x = x();\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x = expr;\n | ^^^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:13\n |\n 1 | const mut x = expr;\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x = ();\n | ^^^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:13\n |\n 1 | const mut x = ();\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x = x+y;\n | ^^^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:13\n |\n 1 | const mut x = x+y;\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x = (x,y);\n | ^^^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:13\n |\n 1 | const mut x = (x,y);\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x = x();\n | ^^^^^^^^^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:13\n |\n 1 | const mut x = x();\n | ^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x: u32 = expr;\n | ^^^^^^^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x: u32 = ();\n | ^^^^^^^\nError [EPAR0370005]: expected A valid expression. -- got 'A tuple expression.'\n --> test:1:18\n |\n 1 | let mut x: u32 = ();\n | ^^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x: u32 = x+y;\n | ^^^^^^^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x: u32 = (x,y);\n | ^^^^^^^\nError [EPAR0370005]: expected A valid expression. -- got 'A tuple expression.'\n --> test:1:18\n |\n 1 | let mut x: u32 = (x,y);\n | ^^^^^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | let mut x: u32 = x();\n | ^^^^^^^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x: u32 = expr;\n | ^^^^^^^^^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x: u32 = ();\n | ^^^^^^^^^\nError [EPAR0370005]: expected A valid expression. -- got 'A tuple expression.'\n --> test:1:20\n |\n 1 | const mut x: u32 = ();\n | ^^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x: u32 = x+y;\n | ^^^^^^^^^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x: u32 = (x,y);\n | ^^^^^^^^^\nError [EPAR0370005]: expected A valid expression. -- got 'A tuple expression.'\n --> test:1:20\n |\n 1 | const mut x: u32 = (x,y);\n | ^^^^^"
- "Error [EPAR0370014]: let mut = ... is deprecated. `let` keyword implies mutabality by default.\n --> test:1:1\n |\n 1 | const mut x: u32 = x();\n | ^^^^^^^^^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x = expr;\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x = ();\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x = x+y;\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x = (x,y);\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x = x();\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x = expr;\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x = ();\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x = x+y;\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x = (x,y);\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x = x();\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x: u32 = expr;\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x: u32 = ();\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x: u32 = x+y;\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x: u32 = (x,y);\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\n |\n 1 | let mut x: u32 = x();\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x: u32 = expr;\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x: u32 = ();\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x: u32 = x+y;\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x: u32 = (x,y);\n | ^"
- "Error [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\n |\n 1 | const mut x: u32 = x();\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:10\n |\n 1 | let (x,y,,) = ();\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:6\n |\n 1 | let (,x,y) = ();\n | ^"
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:8\n |\n 1 | let (x,,y) = ();\n | ^"

View File

@ -139,10 +139,6 @@ in
let
mut
&
return
type