mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Query command option to disable AST postprocessing
This commit is contained in:
@@ -32,13 +32,19 @@ class QueryParseCommand extends Command
|
||||
)
|
||||
->addOption(
|
||||
'compiler-dump',
|
||||
false,
|
||||
'd',
|
||||
InputOption::VALUE_NONE,
|
||||
'Output underlying compiler AST before visitor processing'
|
||||
)
|
||||
->addOption(
|
||||
'no-compiler-postprocessing',
|
||||
'p',
|
||||
InputOption::VALUE_NONE,
|
||||
'Prevent AST optimization before visitor processing'
|
||||
)
|
||||
->addOption(
|
||||
'raw',
|
||||
false,
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Only output query dump'
|
||||
)
|
||||
@@ -55,11 +61,13 @@ class QueryParseCommand extends Command
|
||||
$output->writeln(str_repeat('-', 20));
|
||||
}
|
||||
|
||||
$postprocessing = !$input->getOption('no-compiler-postprocessing');
|
||||
|
||||
$parser = $this->container['query_parser'];
|
||||
if ($input->getOption('compiler-dump')) {
|
||||
$dump = $parser->dump($string);
|
||||
$dump = $parser->dump($string, $postprocessing);
|
||||
} else {
|
||||
$query = $parser->parse($string);
|
||||
$query = $parser->parse($string, $postprocessing);
|
||||
$dump = $query->dump();
|
||||
}
|
||||
|
||||
|
@@ -28,17 +28,17 @@ class QueryParser
|
||||
/**
|
||||
* Creates a Query object from a string
|
||||
*/
|
||||
public function parse($string)
|
||||
public function parse($string, $postprocessing = true)
|
||||
{
|
||||
return $this->visitString($string, new QueryVisitor());
|
||||
return $this->visitString($string, new QueryVisitor(), $postprocessing);
|
||||
}
|
||||
|
||||
public function dump($string)
|
||||
public function dump($string, $postprocessing = true)
|
||||
{
|
||||
return $this->visitString($string, new DumpVisitor());
|
||||
return $this->visitString($string, new DumpVisitor(), $postprocessing);
|
||||
}
|
||||
|
||||
private function visitString($string, Visit $visitor)
|
||||
private function visitString($string, Visit $visitor, $postprocessing = true)
|
||||
{
|
||||
try {
|
||||
$ast = $this->parser->parse($string);
|
||||
@@ -46,8 +46,9 @@ class QueryParser
|
||||
throw new QueryException('Provided query is not valid', 0, $e);
|
||||
}
|
||||
|
||||
|
||||
if ($postprocessing) {
|
||||
$this->fixOperatorAssociativity($ast);
|
||||
}
|
||||
|
||||
return $visitor->visit($ast);
|
||||
}
|
||||
|
Reference in New Issue
Block a user