Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 80754c8

Browse files
authored
fix: logical or is tokenized as pipe (#262)
closes #261 Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent 5954e88 commit 80754c8

File tree

3 files changed

+268
-1
lines changed

3 files changed

+268
-1
lines changed

src/lexer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl Lexer {
527527
}
528528
[b'|', b'|', ..] => {
529529
state.source.skip(2);
530-
(TokenKind::Pipe, b"||".into())
530+
(TokenKind::BooleanOr, b"||".into())
531531
}
532532
[b'|', b'=', ..] => {
533533
state.source.skip(2);

tests/fixtures/0330-pipe/ast.txt

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
[
2+
FullOpeningTag(
3+
Span {
4+
line: 1,
5+
column: 1,
6+
position: 0,
7+
},
8+
),
9+
Expression {
10+
expression: AssignmentOperation(
11+
Assign {
12+
left: Variable(
13+
SimpleVariable(
14+
SimpleVariable {
15+
span: Span {
16+
line: 3,
17+
column: 1,
18+
position: 7,
19+
},
20+
name: "$a",
21+
},
22+
),
23+
),
24+
equals: Span {
25+
line: 3,
26+
column: 4,
27+
position: 10,
28+
},
29+
right: BitwiseOperation(
30+
Or {
31+
left: Variable(
32+
SimpleVariable(
33+
SimpleVariable {
34+
span: Span {
35+
line: 3,
36+
column: 6,
37+
position: 12,
38+
},
39+
name: "$a",
40+
},
41+
),
42+
),
43+
or: Span {
44+
line: 3,
45+
column: 9,
46+
position: 15,
47+
},
48+
right: Variable(
49+
SimpleVariable(
50+
SimpleVariable {
51+
span: Span {
52+
line: 3,
53+
column: 11,
54+
position: 17,
55+
},
56+
name: "$b",
57+
},
58+
),
59+
),
60+
},
61+
),
62+
},
63+
),
64+
ending: Semicolon(
65+
Span {
66+
line: 3,
67+
column: 13,
68+
position: 19,
69+
},
70+
),
71+
},
72+
Expression {
73+
expression: AssignmentOperation(
74+
Assign {
75+
left: Variable(
76+
SimpleVariable(
77+
SimpleVariable {
78+
span: Span {
79+
line: 4,
80+
column: 1,
81+
position: 21,
82+
},
83+
name: "$a",
84+
},
85+
),
86+
),
87+
equals: Span {
88+
line: 4,
89+
column: 4,
90+
position: 24,
91+
},
92+
right: LogicalOperation(
93+
Or {
94+
left: Variable(
95+
SimpleVariable(
96+
SimpleVariable {
97+
span: Span {
98+
line: 4,
99+
column: 6,
100+
position: 26,
101+
},
102+
name: "$a",
103+
},
104+
),
105+
),
106+
double_pipe: Span {
107+
line: 4,
108+
column: 9,
109+
position: 29,
110+
},
111+
right: Variable(
112+
SimpleVariable(
113+
SimpleVariable {
114+
span: Span {
115+
line: 4,
116+
column: 12,
117+
position: 32,
118+
},
119+
name: "$b",
120+
},
121+
),
122+
),
123+
},
124+
),
125+
},
126+
),
127+
ending: Semicolon(
128+
Span {
129+
line: 4,
130+
column: 14,
131+
position: 34,
132+
},
133+
),
134+
},
135+
Expression {
136+
expression: AssignmentOperation(
137+
Assign {
138+
left: Variable(
139+
SimpleVariable(
140+
SimpleVariable {
141+
span: Span {
142+
line: 5,
143+
column: 1,
144+
position: 36,
145+
},
146+
name: "$a",
147+
},
148+
),
149+
),
150+
equals: Span {
151+
line: 5,
152+
column: 4,
153+
position: 39,
154+
},
155+
right: BitwiseOperation(
156+
And {
157+
left: Variable(
158+
SimpleVariable(
159+
SimpleVariable {
160+
span: Span {
161+
line: 5,
162+
column: 6,
163+
position: 41,
164+
},
165+
name: "$a",
166+
},
167+
),
168+
),
169+
and: Span {
170+
line: 5,
171+
column: 9,
172+
position: 44,
173+
},
174+
right: Variable(
175+
SimpleVariable(
176+
SimpleVariable {
177+
span: Span {
178+
line: 5,
179+
column: 11,
180+
position: 46,
181+
},
182+
name: "$b",
183+
},
184+
),
185+
),
186+
},
187+
),
188+
},
189+
),
190+
ending: Semicolon(
191+
Span {
192+
line: 5,
193+
column: 13,
194+
position: 48,
195+
},
196+
),
197+
},
198+
Expression {
199+
expression: AssignmentOperation(
200+
Assign {
201+
left: Variable(
202+
SimpleVariable(
203+
SimpleVariable {
204+
span: Span {
205+
line: 6,
206+
column: 1,
207+
position: 50,
208+
},
209+
name: "$a",
210+
},
211+
),
212+
),
213+
equals: Span {
214+
line: 6,
215+
column: 4,
216+
position: 53,
217+
},
218+
right: LogicalOperation(
219+
And {
220+
left: Variable(
221+
SimpleVariable(
222+
SimpleVariable {
223+
span: Span {
224+
line: 6,
225+
column: 6,
226+
position: 55,
227+
},
228+
name: "$a",
229+
},
230+
),
231+
),
232+
double_ampersand: Span {
233+
line: 6,
234+
column: 9,
235+
position: 58,
236+
},
237+
right: Variable(
238+
SimpleVariable(
239+
SimpleVariable {
240+
span: Span {
241+
line: 6,
242+
column: 12,
243+
position: 61,
244+
},
245+
name: "$b",
246+
},
247+
),
248+
),
249+
},
250+
),
251+
},
252+
),
253+
ending: Semicolon(
254+
Span {
255+
line: 6,
256+
column: 14,
257+
position: 63,
258+
},
259+
),
260+
},
261+
]

tests/fixtures/0330-pipe/code.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
$a = $a | $b;
4+
$a = $a || $b;
5+
$a = $a & $b;
6+
$a = $a && $b;

0 commit comments

Comments
 (0)