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() {
7575 return null ;
7676 }
7777 $ char = $ this ->input ->peek ();
78- if ($ char == " -- " ) {
78+ if ($ this -> isComment () ) {
7979 $ this ->skipComment ();
8080 return $ this ->readNext ();
8181 }
@@ -267,6 +267,13 @@ protected function isDoubleBracketString() {
267267 return $ this ->input ->peek () == '[ ' && !$ this ->input ->eof (1 ) && $ this ->input ->peek (1 ) == '[ ' ;
268268 }
269269
270+ /**
271+ * @return bool
272+ */
273+ protected function isComment () {
274+ return $ this ->input ->peek () == '- ' && !$ this ->input ->eof (1 ) && $ this ->input ->peek (1 ) == '- ' ;
275+ }
276+
270277 /**
271278 * @param string $char
272279 *
Original file line number Diff line number Diff line change @@ -185,4 +185,25 @@ public function testInvalid() {
185185
186186 $ parser ->parse ();
187187 }
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+ }
188209}
Original file line number Diff line number Diff line change @@ -81,4 +81,21 @@ public function testEmptyTable() {
8181
8282 $ this ->assertEquals ([], $ result );
8383 }
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+ }
84101}
You can’t perform that action at this time.
0 commit comments