Skip to content

Commit

Permalink
Correctly support backtick-enclosed strings
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Nov 2, 2024
1 parent 0fb96c5 commit 9e4c621
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/Tokens.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @test lang.ast.unittest.TokensTest
*/
class Tokens {
const DELIMITERS = " \r\n\t'\$\"=,;.:?!(){}[]#+-*/|&^@%~<>";
const DELIMITERS = " \r\n\t'\$\"`=,;.:?!(){}[]#+-*/|&^@%~<>";
const OPERATORS = [
'<' => ['<=>', '<<=', '<=', '<<', '<>', '<?'],
'>' => ['>>=', '>=', '>>'],
Expand Down Expand Up @@ -101,7 +101,7 @@ public function iterator($language) {
$line++;
} else if ("\r" === $token || "\t" === $token || ' ' === $token) {
// Skip over whitespace
} else if ("'" === $token || '"' === $token) {
} else if ("'" === $token || '"' === $token || '`' === $token) {
$string= $token;
$end= '\\'.$token;
do {
Expand Down
5 changes: 5 additions & 0 deletions src/test/php/lang/ast/unittest/parse/LiteralsTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function non_empty_string() {
$this->assertParsed([new Literal('"Test"', self::LINE)], '"Test";');
}

#[Test]
public function exec_statement() {
$this->assertParsed([new Literal('`ls -al`', self::LINE)], '`ls -al`;');
}

#[Test, Values(['[];', ['array();']])]
public function empty_array($declaration) {
$this->assertParsed([new ArrayLiteral([], self::LINE)], $declaration);
Expand Down

0 comments on commit 9e4c621

Please sign in to comment.