mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-19 23:52:02 +03:00
[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:
parent
0e24e670bb
commit
2fbaf759db
@ -85,14 +85,9 @@ impl ParserContext<'_> {
|
|||||||
/// Returns a [`FunctionInput`] AST node if the next tokens represent a function parameter.
|
/// Returns a [`FunctionInput`] AST node if the next tokens represent a function parameter.
|
||||||
pub fn parse_function_parameter(&mut self) -> Result<FunctionInput> {
|
pub fn parse_function_parameter(&mut self) -> Result<FunctionInput> {
|
||||||
let mode = self.parse_function_parameter_mode()?;
|
let mode = self.parse_function_parameter_mode()?;
|
||||||
let mutable = self.eat(&Token::Mut).then(|| self.prev_token.clone());
|
|
||||||
|
|
||||||
let name = self.expect_ident()?;
|
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)?;
|
self.expect(&Token::Colon)?;
|
||||||
let type_ = self.parse_type()?.0;
|
let type_ = self.parse_type()?.0;
|
||||||
Ok(FunctionInput::Variable(FunctionInputVariable::new(
|
Ok(FunctionInput::Variable(FunctionInputVariable::new(
|
||||||
|
@ -219,10 +219,7 @@ impl ParserContext<'_> {
|
|||||||
|
|
||||||
/// Returns a [`VariableName`] AST node if the next tokens represent a variable name with
|
/// Returns a [`VariableName`] AST node if the next tokens represent a variable name with
|
||||||
/// valid keywords.
|
/// valid keywords.
|
||||||
pub fn parse_variable_name(&mut self, decl_ty: Declare, span: Span) -> Result<VariableName> {
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
let name = self.expect_ident()?;
|
let name = self.expect_ident()?;
|
||||||
Ok(VariableName {
|
Ok(VariableName {
|
||||||
|
@ -422,11 +422,9 @@ impl Token {
|
|||||||
"in" => Token::In,
|
"in" => Token::In,
|
||||||
"input" => Token::Input,
|
"input" => Token::Input,
|
||||||
"let" => Token::Let,
|
"let" => Token::Let,
|
||||||
"mut" => Token::Mut,
|
|
||||||
"public" => Token::Public,
|
"public" => Token::Public,
|
||||||
"return" => Token::Return,
|
"return" => Token::Return,
|
||||||
"true" => Token::True,
|
"true" => Token::True,
|
||||||
"type" => Token::Type,
|
|
||||||
"u8" => Token::U8,
|
"u8" => Token::U8,
|
||||||
"u16" => Token::U16,
|
"u16" => Token::U16,
|
||||||
"u32" => Token::U32,
|
"u32" => Token::U32,
|
||||||
|
@ -124,11 +124,9 @@ pub enum Token {
|
|||||||
If,
|
If,
|
||||||
In,
|
In,
|
||||||
Let,
|
Let,
|
||||||
Mut,
|
|
||||||
/// For public inputs.
|
/// For public inputs.
|
||||||
Public,
|
Public,
|
||||||
Return,
|
Return,
|
||||||
Type,
|
|
||||||
|
|
||||||
// Meta Tokens
|
// Meta Tokens
|
||||||
Eof,
|
Eof,
|
||||||
@ -156,11 +154,9 @@ pub const KEYWORD_TOKENS: &[Token] = &[
|
|||||||
Token::In,
|
Token::In,
|
||||||
Token::Input,
|
Token::Input,
|
||||||
Token::Let,
|
Token::Let,
|
||||||
Token::Mut,
|
|
||||||
Token::Public,
|
Token::Public,
|
||||||
Token::Return,
|
Token::Return,
|
||||||
Token::True,
|
Token::True,
|
||||||
Token::Type,
|
|
||||||
Token::U8,
|
Token::U8,
|
||||||
Token::U16,
|
Token::U16,
|
||||||
Token::U32,
|
Token::U32,
|
||||||
@ -198,11 +194,9 @@ impl Token {
|
|||||||
Token::In => sym::In,
|
Token::In => sym::In,
|
||||||
Token::Input => sym::input,
|
Token::Input => sym::input,
|
||||||
Token::Let => sym::Let,
|
Token::Let => sym::Let,
|
||||||
Token::Mut => sym::Mut,
|
|
||||||
Token::Public => sym::Public,
|
Token::Public => sym::Public,
|
||||||
Token::Return => sym::Return,
|
Token::Return => sym::Return,
|
||||||
Token::True => sym::True,
|
Token::True => sym::True,
|
||||||
Token::Type => sym::Type,
|
|
||||||
Token::U8 => sym::u8,
|
Token::U8 => sym::u8,
|
||||||
Token::U16 => sym::u16,
|
Token::U16 => sym::u16,
|
||||||
Token::U32 => sym::u32,
|
Token::U32 => sym::u32,
|
||||||
@ -291,10 +285,8 @@ impl fmt::Display for Token {
|
|||||||
If => write!(f, "if"),
|
If => write!(f, "if"),
|
||||||
In => write!(f, "in"),
|
In => write!(f, "in"),
|
||||||
Let => write!(f, "let"),
|
Let => write!(f, "let"),
|
||||||
Mut => write!(f, "mut"),
|
|
||||||
Public => write!(f, "public"),
|
Public => write!(f, "public"),
|
||||||
Return => write!(f, "return"),
|
Return => write!(f, "return"),
|
||||||
Type => write!(f, "type"),
|
|
||||||
Eof => write!(f, "<eof>"),
|
Eof => write!(f, "<eof>"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 '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 '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 '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 [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 '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 | ^^^^"
|
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Parse
|
namespace: Parse
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
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 | ^"
|
||||||
|
@ -2,26 +2,26 @@
|
|||||||
namespace: ParseStatement
|
namespace: ParseStatement
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:9\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\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 [EPAR0370005]: expected : -- got 'x'\n --> test:1:11\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: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: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: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 | ^"
|
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:8\n |\n 1 | let (x,,y) = ();\n | ^"
|
||||||
|
@ -139,10 +139,6 @@ in
|
|||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
mut
|
|
||||||
|
|
||||||
&
|
&
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
type
|
|
||||||
|
Loading…
Reference in New Issue
Block a user