File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ protected function readNext() {
75
75
return null ;
76
76
}
77
77
$ char = $ this ->input ->peek ();
78
- if ($ char == " -- " ) {
78
+ if ($ this -> isComment () ) {
79
79
$ this ->skipComment ();
80
80
return $ this ->readNext ();
81
81
}
@@ -267,6 +267,13 @@ protected function isDoubleBracketString() {
267
267
return $ this ->input ->peek () == '[ ' && !$ this ->input ->eof (1 ) && $ this ->input ->peek (1 ) == '[ ' ;
268
268
}
269
269
270
+ /**
271
+ * @return bool
272
+ */
273
+ protected function isComment () {
274
+ return $ this ->input ->peek () == '- ' && !$ this ->input ->eof (1 ) && $ this ->input ->peek (1 ) == '- ' ;
275
+ }
276
+
270
277
/**
271
278
* @param string $char
272
279
*
Original file line number Diff line number Diff line change @@ -185,4 +185,25 @@ public function testInvalid() {
185
185
186
186
$ parser ->parse ();
187
187
}
188
+
189
+ public function testComments () {
190
+ $ parser = new Parser (new TokenStream (new InputStream ('{
191
+ -- comment
192
+ foo = {
193
+ test = 123
194
+ }
195
+ } ' )));
196
+
197
+ $ parser ->parse ();
198
+ }
199
+
200
+ public function testInlineComments () {
201
+ $ parser = new Parser (new TokenStream (new InputStream ('{
202
+ foo = {
203
+ test = 123 -- comment
204
+ }
205
+ } ' )));
206
+
207
+ $ parser ->parse ();
208
+ }
188
209
}
Original file line number Diff line number Diff line change @@ -81,4 +81,21 @@ public function testEmptyTable() {
81
81
82
82
$ this ->assertEquals ([], $ result );
83
83
}
84
+
85
+ public function testSimpleTableWithComments () {
86
+ $ parser = new Parser (new TokenStream (new InputStream ('{
87
+ foo = "bar" -- comment
88
+ } ' )));
89
+
90
+ $ node = $ parser ->parse ();
91
+
92
+ $ result = LuaToPhpConverter::convertToPhpValue ($ node );
93
+
94
+ $ this ->assertEquals (
95
+ [
96
+ 'foo ' => 'bar ' ,
97
+ ],
98
+ $ result
99
+ );
100
+ }
84
101
}
You can’t perform that action at this time.
0 commit comments