Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion app/Parser/Walker.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class Walker
public function __construct(protected string $document, $debug = false)
{
$this->debug = $debug;
$this->sourceFile = (new Parser)->parseSourceFile(trim($this->document));
$this->document = trim($document);
$this->sourceFile = (new Parser)->parseSourceFile($this->document);
$this->context = new Context;
}

Expand All @@ -49,12 +50,40 @@ protected function documentSkipsClosingQuote()
return false;
}

private function documentHasDoubleQuoteAsLastCharacter(): bool
{
return substr($this->document, -1) === '"';
}

private function replaceLastDoubleQuoteWithSingleQuote(): string
{
return substr($this->document, 0, -1) . "'";
}

public function walk()
{
if (!$this->documentSkipsClosingQuote()) {
return new Base;
}

/**
* If a last character is a double quote, for example:
*
* {{ config("
*
* then Microsoft\PhpParser\Parser::parseSourceFile returns autocompletingIndex: 1
* instead 0. Probably the parser turns the string into something like this:
*
* "{{ config(";"
*
* and returns ";" as an argument.
*
* This line of code checks if the last character is a double quote and fixes it.
*/
if ($this->documentHasDoubleQuoteAsLastCharacter()) {
return (new self($this->replaceLastDoubleQuoteWithSingleQuote(), $this->debug))->walk();
}

Parse::$debug = $this->debug;

$parsed = Parse::parse($this->sourceFile);
Expand Down
2 changes: 1 addition & 1 deletion app/Parsers/InlineHtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function doEchoParse(BaseNode $node, $prefix, $content)
}

$range->start->line += $this->startLine + $node->position->startLine - 2;
$range->end->line += $this->startLine + $node->position->startLine - 2;
$range->end->line += $this->startLine + $node->position->startLine - 2;

return $range;
};
Expand Down