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
5 changes: 5 additions & 0 deletions trunk_lexer/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ impl Lexer {
let char = self.current.unwrap();

let kind = match char {
'@' => {
self.col += 1;

TokenKind::At
}
'!' => {
self.col += 1;

Expand Down
1 change: 1 addition & 0 deletions trunk_lexer/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum TokenKind {
ArrayCast,
Arrow,
NullsafeArrow,
At,
As,
Asterisk,
Attribute,
Expand Down
3 changes: 3 additions & 0 deletions trunk_parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ pub struct Use {
#[derive(Debug, PartialEq, Clone, Serialize)]
pub enum Expression {
Static,
ErrorSuppress {
expr: Box<Self>,
},
Increment {
value: Box<Self>,
},
Expand Down
24 changes: 22 additions & 2 deletions trunk_parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,7 @@ fn is_prefix(op: &TokenKind) -> bool {
| TokenKind::BoolCast
| TokenKind::IntCast
| TokenKind::DoubleCast
| TokenKind::At
)
}

Expand All @@ -2003,8 +2004,9 @@ fn prefix_binding_power(op: &TokenKind) -> u8 {
| TokenKind::BoolCast
| TokenKind::IntCast
| TokenKind::DoubleCast => 101,
TokenKind::Minus => 100,
TokenKind::Bang => 99,
TokenKind::At => 16,
TokenKind::Minus => 99,
TokenKind::Bang => 98,
_ => unreachable!(),
}
}
Expand All @@ -2025,6 +2027,9 @@ fn prefix(op: &TokenKind, rhs: Expression) -> Expression {
kind: op.into(),
value: Box::new(rhs),
},
TokenKind::At => Expression::ErrorSuppress {
expr: Box::new(rhs),
},
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -3157,6 +3162,21 @@ mod tests {
);
}

#[test]
fn error_suppress() {
assert_ast(
"<?php @hello();",
&[expr!(Expression::ErrorSuppress {
expr: Box::new(Expression::Call {
target: Box::new(Expression::Identifier {
name: "hello".into()
}),
args: vec![],
}),
})],
);
}

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