Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion trunk_lexer/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ impl Lexer {
if qualified {
TokenKind::QualifiedIdentifier(buffer.into())
} else {
identifier_to_keyword(&buffer).unwrap_or_else(|| TokenKind::Identifier(buffer.into()))
identifier_to_keyword(&buffer)
.unwrap_or_else(|| TokenKind::Identifier(buffer.into()))
}
}
b'/' | b'#' => {
Expand Down
33 changes: 30 additions & 3 deletions trunk_parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ impl Parser {
let name = self.ident()?;
let mut value = None;

if is_backed {
if self.current.kind == TokenKind::Equals {
expect!(self, TokenKind::Equals, "expected =");

value = Some(self.expression(0)?);
Expand Down Expand Up @@ -2212,8 +2212,8 @@ mod tests {
use super::Parser;
use crate::{
ast::{
Arg, ArrayItem, Case, ClassFlag, Constant, DeclareItem, ElseIf, IncludeKind, InfixOp,
MethodFlag, PropertyFlag,
Arg, ArrayItem, BackedEnumType, Case, ClassFlag, Constant, DeclareItem, ElseIf,
IncludeKind, InfixOp, MethodFlag, PropertyFlag,
},
Catch, Expression, Identifier, Param, Statement, Type,
};
Expand Down Expand Up @@ -3567,6 +3567,33 @@ mod tests {
);
}

#[test]
fn backed_enum_without_values() {
assert_ast(
"<?php enum Foo: string {
case Bar;
case Baz = 'Baz';
}",
&[Statement::Enum {
name: "Foo".as_bytes().into(),
implements: vec![],
backed_type: Some(BackedEnumType::String),
body: vec![
Statement::EnumCase {
name: "Bar".as_bytes().into(),
value: None,
},
Statement::EnumCase {
name: "Baz".as_bytes().into(),
value: Some(Expression::ConstantString {
value: "Baz".into(),
}),
},
],
}],
);
}

fn assert_ast(source: &str, expected: &[Statement]) {
let mut lexer = Lexer::new(None);
let tokens = lexer.tokenize(source).unwrap();
Expand Down