1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
This commit is contained in:
schaeff 2022-06-08 12:10:44 +02:00
parent a08d49b7e5
commit 62d339f485
2 changed files with 10 additions and 2 deletions

View file

@ -50,6 +50,7 @@ struct_field = { ty ~ identifier }
vis_private = {"private"}
vis_public = {"public"}
vis = { vis_private | vis_public }
_mut = {"mut"}
// Statements
statement = { (return_statement // does not require subsequent newline
@ -116,7 +117,8 @@ array_initializer_expression = { "[" ~ expression ~ ";" ~ expression ~ "]" }
// End Expressions
typed_identifier = { ty ~ identifier }
typed_identifier = { ty ~ _mut? ~ identifier }
assignee = { identifier ~ assignee_access* }
assignee_access = { array_access | dot_access }
identifier = @{ ((!keyword ~ ASCII_ALPHA) | (keyword ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* }
@ -179,5 +181,5 @@ COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) }
// the ordering of reserved keywords matters: if "as" is before "assert", then "assert" gets parsed as (as)(sert) and incorrectly
// accepted
keyword = @{"assert"|"as"|"bool"|"const"|"def"|"do"|"else"|"endfor"|"export"|"false"|"field"|"for"|"if"|"then"|"fi"|"import"|"from"|
"in"|"private"|"public"|"return"|"struct"|"true"|"u8"|"u16"|"u32"|"u64"
"in"|"mut"|"private"|"public"|"return"|"struct"|"true"|"u8"|"u16"|"u32"|"u64"
}

View file

@ -705,10 +705,15 @@ mod ast {
TypedIdentifier(TypedIdentifier<'ast>),
}
#[derive(Debug, FromPest, PartialEq, Clone)]
#[pest_ast(rule(Rule::_mut))]
pub struct Mutable {}
#[derive(Debug, FromPest, PartialEq, Clone)]
#[pest_ast(rule(Rule::typed_identifier))]
pub struct TypedIdentifier<'ast> {
pub ty: Type<'ast>,
pub _mut: Option<Mutable>,
pub identifier: IdentifierExpression<'ast>,
#[pest_ast(outer())]
pub span: Span<'ast>,
@ -1423,6 +1428,7 @@ mod tests {
ty: Type::Basic(BasicType::Field(FieldType {
span: Span::new(source, 23, 28).unwrap()
})),
_mut: None,
identifier: IdentifierExpression {
value: String::from("a"),
span: Span::new(source, 29, 30).unwrap(),