Improve jison script, run the update parser

This commit is contained in:
Damien Alexandre
2014-09-22 16:58:50 +02:00
parent 4a051e4e42
commit 1b8ae26c64
5 changed files with 36 additions and 6 deletions

4
.gitignore vendored
View File

@@ -59,3 +59,7 @@ behat.yml
# Exclude crossdomain.xml file it's generated # Exclude crossdomain.xml file it's generated
/www/crossdomain.xml /www/crossdomain.xml
# Exclude jison files
grammar/query.js
grammar/jison-*

19
build_query_parser.sh Normal file → Executable file
View File

@@ -1,4 +1,19 @@
#!/bin/sh #!/bin/sh
jison_version="master";
jison_php="jison-$jison_version/ports/php/php.js"
cd grammar cd grammar
node jison/ports/php/php.js query.jison
mv QueryParser.php ../lib/Alchemy/Phrasea/SearchEngine/Elastic/QueryParser.php if [ -f $jison_php ];
then
echo "Skip jison download"
else
echo "Download jison lib"
wget https://github.com/zaach/jison/archive/$jison_version.zip
unzip $jison_version.zip
rm $jison_version.zip
fi
node jison-$jison_version/ports/php/php.js query.jison
mv QueryParser.php ../lib/Alchemy/Phrasea/SearchEngine/Elastic/QueryParser.php

View File

@@ -18,7 +18,7 @@ class KeywordNode extends Node
public function getQuery() public function getQuery()
{ {
throw new LogicException("A keyword can't be converted to a query."); throw new \LogicException("A keyword can't be converted to a query.");
} }
public function __toString() public function __toString()

View File

@@ -276,6 +276,8 @@ class ElasticSearchEngine implements SearchEngineInterface
{ {
$parser = new QueryParser(); $parser = new QueryParser();
$ast = $parser->parse($string); $ast = $parser->parse($string);
$userQuery = $ast->getQuery(); $userQuery = $ast->getQuery();
$params = $this->createQueryParams($userQuery, $options ?: new SearchEngineOptions()); $params = $this->createQueryParams($userQuery, $options ?: new SearchEngineOptions());

View File

@@ -446,12 +446,14 @@ class QueryParser
switch ($yystate) { switch ($yystate) {
case 1: case 1:
return $thisS; return $thisS;
break; break;
case 2: case 2:
// $thisS = sprintf('(%s DEF_OP %s)', $s[$o-1]->text, $s[$o]->text); // $thisS = sprintf('(%s DEF_OP %s)', $s[$o-1]->text, $s[$o]->text);
$thisS = new AST\AndExpression($s[$o-1]->text, $s[$o]->text); $thisS = new AST\AndExpression($s[$o-1]->text, $s[$o]->text);
@@ -459,40 +461,48 @@ case 2:
break; break;
case 4: case 4:
$thisS = new AST\AndExpression($s[$o-2]->text, $s[$o]->text); $thisS = new AST\AndExpression($s[$o-2]->text, $s[$o]->text);
break; break;
case 5: case 5:
$thisS = new AST\OrExpression($s[$o-2]->text, $s[$o]->text); $thisS = new AST\OrExpression($s[$o-2]->text, $s[$o]->text);
break; break;
case 6: case 6:
$thisS = new AST\InExpression($s[$o]->text, $s[$o-2]->text); $thisS = new AST\InExpression($s[$o]->text, $s[$o-2]->text);
break; break;
case 7: case 7:
$thisS = $s[$o-1]; $thisS = $s[$o-1];
break; break;
case 10: case 10:
$thisS = new AST\KeywordNode($s[$o]->text); $thisS = new AST\KeywordNode($s[$o]->text);
break; break;
case 11: case 11:
$thisS = new AST\PrefixNode($s[$o-1]->text); $thisS = new AST\PrefixNode($s[$o-1]->text);
break; break;
case 12: case 12:
$thisS = new AST\TextNode($s[$o]->text); $thisS = new AST\TextNode($s[$o]->text);
break; break;
case 13: case 13:
$thisS = new AST\QuotedTextNode($s[$o]->text); $thisS = new AST\QuotedTextNode($s[$o]->text);
break; break;
@@ -811,7 +821,7 @@ break;
} }
} }
} }
if ( isset($match) && $match ) { if ( $match ) {
$matchCount = strlen($match[0]); $matchCount = strlen($match[0]);
$lineCount = preg_match("/(?:\r\n?|\n).*/", $match[0], $lines); $lineCount = preg_match("/(?:\r\n?|\n).*/", $match[0], $lines);
$line = ($lines ? $lines[$lineCount - 1] : false); $line = ($lines ? $lines[$lineCount - 1] : false);
@@ -897,7 +907,6 @@ break;
function LexerPerformAction($avoidingNameCollisions, $YY_START = null) function LexerPerformAction($avoidingNameCollisions, $YY_START = null)
{ {
; ;
switch($avoidingNameCollisions) { switch($avoidingNameCollisions) {
case 0:/* skip whitespace */ case 0:/* skip whitespace */
@@ -1120,4 +1129,4 @@ class ParserRange
$this->x = $x; $this->x = $x;
$this->y = $y; $this->y = $y;
} }
} }