Skip to content

Commit e7ccce4

Browse files
committed
remove Nop stmt
1 parent eccd56e commit e7ccce4

201 files changed

Lines changed: 269 additions & 1553 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ Gives the output:
8080

8181
```
8282
(program
83-
(nop)
8483
(class "Foo" (extends Bar) (implements Baz)
8584
(members
8685
(property public int = (integer 1))

src/parser/control_flow.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ impl<'src, 'ast> Parser<'src, 'ast> {
3030
&& self.current_token.kind != TokenKind::ElseIf
3131
&& self.current_token.kind != TokenKind::Eof
3232
{
33+
if matches!(
34+
self.current_token.kind,
35+
TokenKind::OpenTag | TokenKind::CloseTag
36+
) {
37+
self.bump();
38+
continue;
39+
}
3340
stmts.push(self.parse_stmt());
3441
}
3542
stmts.into_bump_slice() as &'ast [StmtId<'ast>]
@@ -58,6 +65,13 @@ impl<'src, 'ast> Parser<'src, 'ast> {
5865
while self.current_token.kind != TokenKind::EndIf
5966
&& self.current_token.kind != TokenKind::Eof
6067
{
68+
if matches!(
69+
self.current_token.kind,
70+
TokenKind::OpenTag | TokenKind::CloseTag
71+
) {
72+
self.bump();
73+
continue;
74+
}
6175
stmts.push(self.parse_stmt());
6276
}
6377
Some(stmts.into_bump_slice() as &'ast [StmtId<'ast>])
@@ -105,6 +119,13 @@ impl<'src, 'ast> Parser<'src, 'ast> {
105119
while self.current_token.kind != TokenKind::EndWhile
106120
&& self.current_token.kind != TokenKind::Eof
107121
{
122+
if matches!(
123+
self.current_token.kind,
124+
TokenKind::OpenTag | TokenKind::CloseTag
125+
) {
126+
self.bump();
127+
continue;
128+
}
108129
stmts.push(self.parse_stmt());
109130
}
110131
if self.current_token.kind == TokenKind::EndWhile {
@@ -215,6 +236,13 @@ impl<'src, 'ast> Parser<'src, 'ast> {
215236
while self.current_token.kind != TokenKind::EndFor
216237
&& self.current_token.kind != TokenKind::Eof
217238
{
239+
if matches!(
240+
self.current_token.kind,
241+
TokenKind::OpenTag | TokenKind::CloseTag
242+
) {
243+
self.bump();
244+
continue;
245+
}
218246
stmts.push(self.parse_stmt());
219247
}
220248
if self.current_token.kind == TokenKind::EndFor {
@@ -274,6 +302,13 @@ impl<'src, 'ast> Parser<'src, 'ast> {
274302
while self.current_token.kind != TokenKind::EndForeach
275303
&& self.current_token.kind != TokenKind::Eof
276304
{
305+
if matches!(
306+
self.current_token.kind,
307+
TokenKind::OpenTag | TokenKind::CloseTag
308+
) {
309+
self.bump();
310+
continue;
311+
}
277312
stmts.push(self.parse_stmt());
278313
}
279314
if self.current_token.kind == TokenKind::EndForeach {
@@ -364,6 +399,13 @@ impl<'src, 'ast> Parser<'src, 'ast> {
364399
&& self.current_token.kind != end_token
365400
&& self.current_token.kind != TokenKind::Eof
366401
{
402+
if matches!(
403+
self.current_token.kind,
404+
TokenKind::OpenTag | TokenKind::CloseTag
405+
) {
406+
self.bump();
407+
continue;
408+
}
367409
body_stmts.push(self.parse_stmt());
368410
}
369411

@@ -557,6 +599,13 @@ impl<'src, 'ast> Parser<'src, 'ast> {
557599
while self.current_token.kind != TokenKind::EndDeclare
558600
&& self.current_token.kind != TokenKind::Eof
559601
{
602+
if matches!(
603+
self.current_token.kind,
604+
TokenKind::OpenTag | TokenKind::CloseTag
605+
) {
606+
self.bump();
607+
continue;
608+
}
560609
stmts.push(self.parse_stmt());
561610
}
562611
if self.current_token.kind == TokenKind::EndDeclare {

src/parser/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ impl<'src, 'ast> Parser<'src, 'ast> {
133133
let mut statements = std::vec::Vec::new(); // Temporary vec, will be moved to arena
134134

135135
while self.current_token.kind != TokenKind::Eof {
136+
if matches!(
137+
self.current_token.kind,
138+
TokenKind::OpenTag | TokenKind::CloseTag
139+
) {
140+
self.bump();
141+
continue;
142+
}
136143
statements.push(self.parse_top_stmt());
137144
}
138145

src/parser/stmt.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ impl<'src, 'ast> Parser<'src, 'ast> {
299299
while self.current_token.kind != TokenKind::CloseBrace
300300
&& self.current_token.kind != TokenKind::Eof
301301
{
302+
if matches!(
303+
self.current_token.kind,
304+
TokenKind::OpenTag | TokenKind::CloseTag
305+
) {
306+
self.bump();
307+
continue;
308+
}
302309
statements.push(self.parse_stmt());
303310
}
304311

tests/grammar_review_fixes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ fn test_function_by_ref() {
1212

1313
assert!(program.errors.is_empty());
1414
assert!(
15-
program.statements.len() >= 2,
16-
"Program should have at least 2 statements (open tag + function)"
15+
program.statements.len() >= 1,
16+
"Program should have at least 1 statement (function)"
1717
);
1818

19-
// Skip the Nop statement from <?php tag and check the function
19+
// Check the function
2020
let func_stmt = program
2121
.statements
2222
.iter()
@@ -47,7 +47,7 @@ fn test_anonymous_class_modifiers() {
4747
let program = parser.parse_program();
4848
assert!(program.errors.is_empty());
4949

50-
// Find the expression statement (skip Nop from open tag)
50+
// Find the expression statement
5151
let expr_stmt = program
5252
.statements
5353
.iter()

tests/nikic_compat.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ fn test_group_use_flattening() {
1212

1313
assert!(program.errors.is_empty());
1414

15-
// Currently flattens to 2 Use statements (Nop + Use)
16-
assert_eq!(program.statements.len(), 2);
15+
// Currently flattens to 1 Use statement (Use)
16+
assert_eq!(program.statements.len(), 1);
1717

18-
match program.statements[1] {
18+
match program.statements[0] {
1919
Stmt::Use { uses, .. } => {
2020
assert_eq!(uses.len(), 2);
2121
}
@@ -33,8 +33,8 @@ fn test_list_vs_short_array() {
3333
assert!(program.errors.is_empty());
3434

3535
// Check first assignment: list($a) = ...
36-
// Index 1 because 0 is Nop
37-
match program.statements[1] {
36+
// Index 0 because Nop is gone
37+
match program.statements[0] {
3838
Stmt::Expression { expr, .. } => {
3939
match expr {
4040
Expr::Assign { var, .. } => {
@@ -49,7 +49,7 @@ fn test_list_vs_short_array() {
4949
}
5050

5151
// Check second assignment: [$b] = ...
52-
match program.statements[2] {
52+
match program.statements[1] {
5353
Stmt::Expression { expr, .. } => match expr {
5454
Expr::Assign { var, .. } => {
5555
assert!(matches!(**var, Expr::Array { .. }));
@@ -75,7 +75,7 @@ $x = <<<EOT
7575

7676
assert!(program.errors.is_empty());
7777

78-
match program.statements[1] {
78+
match program.statements[0] {
7979
Stmt::Expression { expr, .. } => {
8080
match expr {
8181
Expr::Assign { expr, .. } => {

tests/sexpr_tests.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ fn test_sexpr_basic() {
1616
formatter.visit_program(&program);
1717
let output = formatter.finish();
1818

19-
assert_eq!(
20-
output,
21-
"(program\n (nop)\n (echo (+ (integer 1) (integer 2))))"
22-
);
19+
assert_eq!(output, "(program\n (echo (+ (integer 1) (integer 2))))");
2320
}
2421

2522
#[test]
@@ -36,7 +33,7 @@ fn test_sexpr_control_flow() {
3633

3734
assert_eq!(
3835
output,
39-
"(program\n (nop)\n (if (variable \"$a\")\n (then\n (echo (integer 1)))\n (else\n (echo (integer 2))))\n (while (variable \"$b\")\n (body\n (assign (variable \"$a\") (integer 1)))))"
36+
"(program\n (if (variable \"$a\")\n (then\n (echo (integer 1)))\n (else\n (echo (integer 2))))\n (while (variable \"$b\")\n (body\n (assign (variable \"$a\") (integer 1)))))"
4037
);
4138
}
4239

@@ -54,6 +51,6 @@ fn test_sexpr_class() {
5451

5552
assert_eq!(
5653
output,
57-
"(program\n (nop)\n (class \"Foo\" (extends Bar) (implements Baz)\n (members\n (property public int $p = (integer 1))\n (method \"m\" (params ($a))\n (body\n (return (variable \"$a\")))))))"
54+
"(program\n (class \"Foo\" (extends Bar) (implements Baz)\n (members\n (property public int $p = (integer 1))\n (method \"m\" (params ($a))\n (body\n (return (variable \"$a\")))))))"
5855
);
5956
}

tests/snapshots/additional_edge_cases__array_spread_operator.snap

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
---
22
source: tests/additional_edge_cases.rs
3-
assertion_line: 35
43
expression: program
54
---
65
Program {
76
statements: [
8-
Nop {
9-
span: Span {
10-
start: 0,
11-
end: 6,
12-
},
13-
},
147
Expression {
158
expr: Assign {
169
var: Variable {
@@ -406,7 +399,7 @@ Program {
406399
],
407400
errors: [],
408401
span: Span {
409-
start: 0,
402+
start: 6,
410403
end: 130,
411404
},
412405
}

tests/snapshots/additional_edge_cases__arrow_function_complex.snap

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
---
22
source: tests/additional_edge_cases.rs
3-
assertion_line: 232
43
expression: program
54
---
65
Program {
76
statements: [
8-
Nop {
9-
span: Span {
10-
start: 0,
11-
end: 6,
12-
},
13-
},
147
Expression {
158
expr: Assign {
169
var: Variable {
@@ -550,7 +543,7 @@ Program {
550543
],
551544
errors: [],
552545
span: Span {
553-
start: 0,
546+
start: 6,
554547
end: 214,
555548
},
556549
}

tests/snapshots/additional_edge_cases__complex_type_combinations.snap

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ expression: program
44
---
55
Program {
66
statements: [
7-
Nop {
8-
span: Span {
9-
start: 0,
10-
end: 6,
11-
},
12-
},
137
Function {
148
attributes: [],
159
name: Token {
@@ -366,7 +360,7 @@ Program {
366360
],
367361
errors: [],
368362
span: Span {
369-
start: 0,
363+
start: 6,
370364
end: 134,
371365
},
372366
}

0 commit comments

Comments
 (0)