mirror of
https://github.com/danog/parser.git
synced 2024-11-26 20:04:57 +01:00
chore: allow static, self, and parent in exprs (#195)
Signed-off-by: azjezz <azjezz@protonmail.com>
This commit is contained in:
parent
5264269078
commit
239bd69b86
@ -618,13 +618,6 @@ expressions! {
|
||||
|
||||
#[before(static_postfix), current(TokenKind::Self_)]
|
||||
self_postfix(|state: &mut State| {
|
||||
if !state.has_class_scope {
|
||||
return Err(ParseError::CannotFindTypeInCurrentScope(
|
||||
state.current.kind.to_string(),
|
||||
state.current.span,
|
||||
));
|
||||
}
|
||||
|
||||
state.next();
|
||||
|
||||
postfix(state, Expression::Self_, &TokenKind::DoubleColon)
|
||||
@ -632,13 +625,6 @@ expressions! {
|
||||
|
||||
#[before(parent_postfix), current(TokenKind::Static)]
|
||||
static_postfix(|state: &mut State| {
|
||||
if !state.has_class_scope {
|
||||
return Err(ParseError::CannotFindTypeInCurrentScope(
|
||||
state.current.kind.to_string(),
|
||||
state.current.span,
|
||||
));
|
||||
}
|
||||
|
||||
state.next();
|
||||
|
||||
postfix(state, Expression::Static, &TokenKind::DoubleColon)
|
||||
@ -646,13 +632,6 @@ expressions! {
|
||||
|
||||
#[before(left_parenthesis), current(TokenKind::Parent)]
|
||||
parent_postfix(|state: &mut State| {
|
||||
if !state.has_class_scope {
|
||||
return Err(ParseError::CannotFindTypeInCurrentScope(
|
||||
state.current.kind.to_string(),
|
||||
state.current.span,
|
||||
));
|
||||
}
|
||||
|
||||
state.next();
|
||||
|
||||
postfix(state, Expression::Parent, &TokenKind::DoubleColon)
|
||||
@ -693,37 +672,16 @@ expressions! {
|
||||
|
||||
let target = match state.current.kind {
|
||||
TokenKind::Self_ => {
|
||||
if !state.has_class_scope {
|
||||
return Err(ParseError::CannotFindTypeInCurrentScope(
|
||||
state.current.kind.to_string(),
|
||||
state.current.span,
|
||||
));
|
||||
}
|
||||
|
||||
state.next();
|
||||
|
||||
Expression::Self_
|
||||
}
|
||||
TokenKind::Static => {
|
||||
if !state.has_class_scope {
|
||||
return Err(ParseError::CannotFindTypeInCurrentScope(
|
||||
state.current.kind.to_string(),
|
||||
state.current.span,
|
||||
));
|
||||
}
|
||||
|
||||
state.next();
|
||||
|
||||
Expression::Static
|
||||
}
|
||||
TokenKind::Parent => {
|
||||
if !state.has_class_scope {
|
||||
return Err(ParseError::CannotFindTypeInCurrentScope(
|
||||
state.current.kind.to_string(),
|
||||
state.current.span,
|
||||
));
|
||||
}
|
||||
|
||||
state.next();
|
||||
|
||||
Expression::Parent
|
||||
|
2
tests/fixtures/0270/parser-error.txt
vendored
2
tests/fixtures/0270/parser-error.txt
vendored
@ -1 +1 @@
|
||||
CannotFindTypeInCurrentScope("static", (3, 6)) -> Parse Error: Cannot find type `static` in this scope on line 3 on column 6
|
||||
ExpectedToken(["`::`"], Some(";"), (3, 12)) -> Parse Error: unexpected token `;`, expecting `::` on line 3 column 12
|
||||
|
33
tests/fixtures/0271/ast.txt
vendored
Normal file
33
tests/fixtures/0271/ast.txt
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
[
|
||||
Expression {
|
||||
expr: AssignmentOperation(
|
||||
Assign {
|
||||
left: Variable(
|
||||
SimpleVariable(
|
||||
SimpleVariable {
|
||||
span: (
|
||||
3,
|
||||
1,
|
||||
),
|
||||
name: "a",
|
||||
},
|
||||
),
|
||||
),
|
||||
span: (
|
||||
3,
|
||||
4,
|
||||
),
|
||||
right: ConstFetch {
|
||||
target: Static,
|
||||
constant: SimpleIdentifier {
|
||||
span: (
|
||||
3,
|
||||
14,
|
||||
),
|
||||
name: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
]
|
1
tests/fixtures/0271/parser-error.txt
vendored
1
tests/fixtures/0271/parser-error.txt
vendored
@ -1 +0,0 @@
|
||||
CannotFindTypeInCurrentScope("static", (3, 6)) -> Parse Error: Cannot find type `static` in this scope on line 3 on column 6
|
138
tests/fixtures/0284/ast.txt
vendored
Normal file
138
tests/fixtures/0284/ast.txt
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
[
|
||||
Class(
|
||||
Class {
|
||||
start: (
|
||||
7,
|
||||
1,
|
||||
),
|
||||
end: (
|
||||
9,
|
||||
1,
|
||||
),
|
||||
name: SimpleIdentifier {
|
||||
span: (
|
||||
7,
|
||||
7,
|
||||
),
|
||||
name: "a",
|
||||
},
|
||||
extends: None,
|
||||
implements: None,
|
||||
attributes: [
|
||||
AttributeGroup {
|
||||
start: (
|
||||
6,
|
||||
1,
|
||||
),
|
||||
end: (
|
||||
6,
|
||||
64,
|
||||
),
|
||||
members: [
|
||||
Attribute {
|
||||
start: (
|
||||
6,
|
||||
3,
|
||||
),
|
||||
end: (
|
||||
6,
|
||||
19,
|
||||
),
|
||||
expression: Call {
|
||||
target: Identifier(
|
||||
SimpleIdentifier(
|
||||
SimpleIdentifier {
|
||||
span: (
|
||||
6,
|
||||
3,
|
||||
),
|
||||
name: "foo",
|
||||
},
|
||||
),
|
||||
),
|
||||
args: [
|
||||
Arg {
|
||||
name: None,
|
||||
value: ConstFetch {
|
||||
target: Self_,
|
||||
constant: SimpleIdentifier {
|
||||
span: (
|
||||
6,
|
||||
13,
|
||||
),
|
||||
name: "class",
|
||||
},
|
||||
},
|
||||
unpack: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
Attribute {
|
||||
start: (
|
||||
6,
|
||||
21,
|
||||
),
|
||||
end: (
|
||||
6,
|
||||
64,
|
||||
),
|
||||
expression: Call {
|
||||
target: Identifier(
|
||||
SimpleIdentifier(
|
||||
SimpleIdentifier {
|
||||
span: (
|
||||
6,
|
||||
21,
|
||||
),
|
||||
name: "bar",
|
||||
},
|
||||
),
|
||||
),
|
||||
args: [
|
||||
Arg {
|
||||
name: None,
|
||||
value: New {
|
||||
target: Self_,
|
||||
span: (
|
||||
6,
|
||||
25,
|
||||
),
|
||||
args: [],
|
||||
},
|
||||
unpack: false,
|
||||
},
|
||||
Arg {
|
||||
name: None,
|
||||
value: New {
|
||||
target: Parent,
|
||||
span: (
|
||||
6,
|
||||
37,
|
||||
),
|
||||
args: [],
|
||||
},
|
||||
unpack: false,
|
||||
},
|
||||
Arg {
|
||||
name: None,
|
||||
value: New {
|
||||
target: Static,
|
||||
span: (
|
||||
6,
|
||||
51,
|
||||
),
|
||||
args: [],
|
||||
},
|
||||
unpack: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
members: [],
|
||||
},
|
||||
),
|
||||
]
|
9
tests/fixtures/0284/code.php
vendored
Normal file
9
tests/fixtures/0284/code.php
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
// |- TODO: static in constant expression is not allowed.
|
||||
// |
|
||||
// v
|
||||
#[foo(self::class), bar(new self(), new parent(), new static())]
|
||||
class a {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user