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