mirror of
https://github.com/danog/parser.git
synced 2025-01-22 21:11:55 +01:00
Merge pull request #68 from ryangjchandler/fix/backed-enums-without-values
This commit is contained in:
commit
1c90b5e907
@ -531,7 +531,8 @@ impl Lexer {
|
|||||||
if qualified {
|
if qualified {
|
||||||
TokenKind::QualifiedIdentifier(buffer.into())
|
TokenKind::QualifiedIdentifier(buffer.into())
|
||||||
} else {
|
} 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'#' => {
|
b'/' | b'#' => {
|
||||||
|
@ -622,7 +622,7 @@ impl Parser {
|
|||||||
let name = self.ident()?;
|
let name = self.ident()?;
|
||||||
let mut value = None;
|
let mut value = None;
|
||||||
|
|
||||||
if is_backed {
|
if self.current.kind == TokenKind::Equals {
|
||||||
expect!(self, TokenKind::Equals, "expected =");
|
expect!(self, TokenKind::Equals, "expected =");
|
||||||
|
|
||||||
value = Some(self.expression(0)?);
|
value = Some(self.expression(0)?);
|
||||||
@ -2212,8 +2212,8 @@ mod tests {
|
|||||||
use super::Parser;
|
use super::Parser;
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{
|
ast::{
|
||||||
Arg, ArrayItem, Case, ClassFlag, Constant, DeclareItem, ElseIf, IncludeKind, InfixOp,
|
Arg, ArrayItem, BackedEnumType, Case, ClassFlag, Constant, DeclareItem, ElseIf,
|
||||||
MethodFlag, PropertyFlag,
|
IncludeKind, InfixOp, MethodFlag, PropertyFlag,
|
||||||
},
|
},
|
||||||
Catch, Expression, Identifier, Param, Statement, Type,
|
Catch, Expression, Identifier, Param, Statement, Type,
|
||||||
};
|
};
|
||||||
@ -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]) {
|
fn assert_ast(source: &str, expected: &[Statement]) {
|
||||||
let mut lexer = Lexer::new(None);
|
let mut lexer = Lexer::new(None);
|
||||||
let tokens = lexer.tokenize(source).unwrap();
|
let tokens = lexer.tokenize(source).unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user