mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
Parser for Short Hand Syntax (->) Check method
SVN:b1312[5747]
This commit is contained in:
@@ -843,7 +843,10 @@ class FalseExpression extends ScalarExpression
|
|||||||
|
|
||||||
class ExternalFieldExpression extends UnaryExpression
|
class ExternalFieldExpression extends UnaryExpression
|
||||||
{
|
{
|
||||||
|
public function __construct($value)
|
||||||
|
{
|
||||||
|
parent::__construct($value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FieldExpression extends UnaryExpression
|
class FieldExpression extends UnaryExpression
|
||||||
|
|||||||
@@ -1596,16 +1596,19 @@ static public $yy_action = array(
|
|||||||
#line 158 "..\oql-parser.y"
|
#line 158 "..\oql-parser.y"
|
||||||
function yy_r61(){ $this->_retvalue = new FieldOqlExpression($this->yystack[$this->yyidx + 0]->minor, $this->yystack[$this->yyidx + -2]->minor); }
|
function yy_r61(){ $this->_retvalue = new FieldOqlExpression($this->yystack[$this->yyidx + 0]->minor, $this->yystack[$this->yyidx + -2]->minor); }
|
||||||
#line 1602 "..\oql-parser.php"
|
#line 1602 "..\oql-parser.php"
|
||||||
#line 161 "..\oql-parser.y"
|
#line 162 "..\oql-parser.y"
|
||||||
function yy_r63(){ $this->_retvalue = new ExternalFieldOqlExpression($this->yystack[$this->yyidx + -2]->minor, $this->yystack[$this->yyidx + 0]->minor); }
|
function yy_r63(){
|
||||||
#line 1605 "..\oql-parser.php"
|
$expr = new FieldOqlExpression($this->yystack[$this->yyidx + 0]->minor);
|
||||||
#line 163 "..\oql-parser.y"
|
$this->_retvalue = new ExternalFieldOqlExpression($this->yystack[$this->yyidx + -2]->minor, $expr);
|
||||||
function yy_r64(){ $this->_retvalue=$this->yystack[$this->yyidx + 0]->minor; }
|
}
|
||||||
#line 1608 "..\oql-parser.php"
|
#line 1608 "..\oql-parser.php"
|
||||||
#line 166 "..\oql-parser.y"
|
#line 167 "..\oql-parser.y"
|
||||||
function yy_r65(){ $this->_retvalue = new VariableOqlExpression(substr($this->yystack[$this->yyidx + 0]->minor, 1)); }
|
function yy_r64(){ $this->_retvalue=$this->yystack[$this->yyidx + 0]->minor; }
|
||||||
#line 1611 "..\oql-parser.php"
|
#line 1611 "..\oql-parser.php"
|
||||||
#line 168 "..\oql-parser.y"
|
#line 170 "..\oql-parser.y"
|
||||||
|
function yy_r65(){ $this->_retvalue = new VariableOqlExpression(substr($this->yystack[$this->yyidx + 0]->minor, 1)); }
|
||||||
|
#line 1614 "..\oql-parser.php"
|
||||||
|
#line 172 "..\oql-parser.y"
|
||||||
function yy_r66(){
|
function yy_r66(){
|
||||||
if ($this->yystack[$this->yyidx + 0]->minor[0] == '`')
|
if ($this->yystack[$this->yyidx + 0]->minor[0] == '`')
|
||||||
{
|
{
|
||||||
@@ -1617,22 +1620,22 @@ static public $yy_action = array(
|
|||||||
}
|
}
|
||||||
$this->_retvalue = new OqlName($name, $this->m_iColPrev);
|
$this->_retvalue = new OqlName($name, $this->m_iColPrev);
|
||||||
}
|
}
|
||||||
#line 1624 "..\oql-parser.php"
|
|
||||||
#line 179 "..\oql-parser.y"
|
|
||||||
function yy_r67(){$this->_retvalue=(int)$this->yystack[$this->yyidx + 0]->minor; }
|
|
||||||
#line 1627 "..\oql-parser.php"
|
#line 1627 "..\oql-parser.php"
|
||||||
#line 180 "..\oql-parser.y"
|
#line 183 "..\oql-parser.y"
|
||||||
function yy_r68(){$this->_retvalue=(int)-$this->yystack[$this->yyidx + 0]->minor; }
|
function yy_r67(){$this->_retvalue=(int)$this->yystack[$this->yyidx + 0]->minor; }
|
||||||
#line 1630 "..\oql-parser.php"
|
#line 1630 "..\oql-parser.php"
|
||||||
#line 181 "..\oql-parser.y"
|
#line 184 "..\oql-parser.y"
|
||||||
function yy_r69(){$this->_retvalue=new OqlHexValue($this->yystack[$this->yyidx + 0]->minor); }
|
function yy_r68(){$this->_retvalue=(int)-$this->yystack[$this->yyidx + 0]->minor; }
|
||||||
#line 1633 "..\oql-parser.php"
|
#line 1633 "..\oql-parser.php"
|
||||||
#line 182 "..\oql-parser.y"
|
|
||||||
function yy_r70(){$this->_retvalue=stripslashes(substr($this->yystack[$this->yyidx + 0]->minor, 1, strlen($this->yystack[$this->yyidx + 0]->minor) - 2)); }
|
|
||||||
#line 1636 "..\oql-parser.php"
|
|
||||||
#line 185 "..\oql-parser.y"
|
#line 185 "..\oql-parser.y"
|
||||||
function yy_r71(){$this->_retvalue=$this->yystack[$this->yyidx + 0]->minor; }
|
function yy_r69(){$this->_retvalue=new OqlHexValue($this->yystack[$this->yyidx + 0]->minor); }
|
||||||
|
#line 1636 "..\oql-parser.php"
|
||||||
|
#line 186 "..\oql-parser.y"
|
||||||
|
function yy_r70(){$this->_retvalue=stripslashes(substr($this->yystack[$this->yyidx + 0]->minor, 1, strlen($this->yystack[$this->yyidx + 0]->minor) - 2)); }
|
||||||
#line 1639 "..\oql-parser.php"
|
#line 1639 "..\oql-parser.php"
|
||||||
|
#line 189 "..\oql-parser.y"
|
||||||
|
function yy_r71(){$this->_retvalue=$this->yystack[$this->yyidx + 0]->minor; }
|
||||||
|
#line 1642 "..\oql-parser.php"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* placeholder for the left hand side in a reduce operation.
|
* placeholder for the left hand side in a reduce operation.
|
||||||
@@ -1747,7 +1750,7 @@ static public $yy_action = array(
|
|||||||
#line 25 "..\oql-parser.y"
|
#line 25 "..\oql-parser.y"
|
||||||
|
|
||||||
throw new OQLParserException($this->m_sSourceQuery, $this->m_iLine, $this->m_iCol, $this->tokenName($yymajor), $TOKEN);
|
throw new OQLParserException($this->m_sSourceQuery, $this->m_iLine, $this->m_iCol, $this->tokenName($yymajor), $TOKEN);
|
||||||
#line 1755 "..\oql-parser.php"
|
#line 1758 "..\oql-parser.php"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1914,7 +1917,7 @@ throw new OQLParserException($this->m_sSourceQuery, $this->m_iLine, $this->m_iCo
|
|||||||
} while ($yymajor != self::YYNOCODE && $this->yyidx >= 0);
|
} while ($yymajor != self::YYNOCODE && $this->yyidx >= 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#line 243 "..\oql-parser.y"
|
#line 247 "..\oql-parser.y"
|
||||||
|
|
||||||
|
|
||||||
class OQLParserException extends OQLException
|
class OQLParserException extends OQLException
|
||||||
@@ -1979,4 +1982,4 @@ class OQLParser extends OQLParserRaw
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 1988 "..\oql-parser.php"
|
#line 1991 "..\oql-parser.php"
|
||||||
|
|||||||
@@ -158,7 +158,11 @@ basic_field_id(A) ::= name(X). { A = new FieldOqlExpression(X); }
|
|||||||
basic_field_id(A) ::= class_name(X) DOT name(Y). { A = new FieldOqlExpression(Y, X); }
|
basic_field_id(A) ::= class_name(X) DOT name(Y). { A = new FieldOqlExpression(Y, X); }
|
||||||
|
|
||||||
field_id(A) ::= basic_field_id(X). { A = X; }
|
field_id(A) ::= basic_field_id(X). { A = X; }
|
||||||
field_id(A) ::= field_id(X) ARROW name(Y). { A = new ExternalFieldOqlExpression(X, Y); }
|
field_id(A) ::= field_id(X) ARROW name(Y).
|
||||||
|
{
|
||||||
|
$expr = new FieldOqlExpression(Y);
|
||||||
|
A = new ExternalFieldOqlExpression(X, $expr);
|
||||||
|
}
|
||||||
|
|
||||||
class_name(A) ::= name(X). { A=X; }
|
class_name(A) ::= name(X). { A=X; }
|
||||||
|
|
||||||
|
|||||||
@@ -208,7 +208,34 @@ class ExternalFieldOqlExpression extends ExternalFieldExpression implements Chec
|
|||||||
*/
|
*/
|
||||||
public function Check(ModelReflection $oModelReflection, $aAliases, $sSourceQuery)
|
public function Check(ModelReflection $oModelReflection, $aAliases, $sSourceQuery)
|
||||||
{
|
{
|
||||||
// TODO: Implement Check() method.
|
$sParentAlias = null;
|
||||||
|
foreach($this->aExpression as $i => $oFieldOqlExpression)
|
||||||
|
{
|
||||||
|
if (is_null($sParentAlias))
|
||||||
|
{
|
||||||
|
$oFieldOqlExpression->RefreshAlias($oModelReflection, $aAliases, $sSourceQuery);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$oFieldOqlExpression->SetParent($sParentAlias);
|
||||||
|
}
|
||||||
|
$oFieldOqlExpression->Check($oModelReflection, $aAliases, $sSourceQuery);
|
||||||
|
|
||||||
|
$sClass = $aAliases[$oFieldOqlExpression->GetParent()];
|
||||||
|
$sTargetClass = $oModelReflection->GetAttributeProperty($sClass, $oFieldOqlExpression->GetName(), 'targetclass');
|
||||||
|
if (is_null($sTargetClass))
|
||||||
|
{
|
||||||
|
if ($i != (count($this->aExpression) - 1))
|
||||||
|
{
|
||||||
|
throw new OqlNormalizeException('Forbiden operation for attribute', $sSourceQuery, $oFieldOqlExpression->GetNameDetails(), $oModelReflection->GetFiltersList($sClass));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aAliases[$sTargetClass] = $sTargetClass;
|
||||||
|
$sParentAlias = $sTargetClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,6 +267,39 @@ class FieldOqlExpression extends FieldExpression implements CheckableExpression
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function Check(ModelReflection $oModelReflection, $aAliases, $sSourceQuery)
|
public function Check(ModelReflection $oModelReflection, $aAliases, $sSourceQuery)
|
||||||
|
{
|
||||||
|
$sClassAlias = $this->GetParent();
|
||||||
|
$sFltCode = $this->GetName();
|
||||||
|
if (empty($sClassAlias))
|
||||||
|
{
|
||||||
|
// Try to find an alias
|
||||||
|
// Build an array of field => array of aliases
|
||||||
|
$this->RefreshAlias($oModelReflection, $aAliases, $sSourceQuery);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!array_key_exists($sClassAlias, $aAliases))
|
||||||
|
{
|
||||||
|
throw new OqlNormalizeException('Unknown class [alias]', $sSourceQuery, $this->GetParentDetails(), array_keys($aAliases));
|
||||||
|
}
|
||||||
|
$sClass = $aAliases[$sClassAlias];
|
||||||
|
if (!$oModelReflection->IsValidFilterCode($sClass, $sFltCode))
|
||||||
|
{
|
||||||
|
throw new OqlNormalizeException('Unknown filter code', $sSourceQuery, $this->GetNameDetails(), $oModelReflection->GetFiltersList($sClass));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by Check => throws exception if error
|
||||||
|
*
|
||||||
|
* @param \ModelReflection $oModelReflection
|
||||||
|
* @param $aAliases
|
||||||
|
* @param $sSourceQuery
|
||||||
|
*
|
||||||
|
* @throws \OqlNormalizeException
|
||||||
|
*/
|
||||||
|
public function RefreshAlias(ModelReflection $oModelReflection, $aAliases, $sSourceQuery)
|
||||||
{
|
{
|
||||||
$sClassAlias = $this->GetParent();
|
$sClassAlias = $this->GetParent();
|
||||||
$sFltCode = $this->GetName();
|
$sFltCode = $this->GetName();
|
||||||
@@ -264,18 +324,7 @@ class FieldOqlExpression extends FieldExpression implements CheckableExpression
|
|||||||
throw new OqlNormalizeException('Ambiguous filter code', $sSourceQuery, $this->GetNameDetails());
|
throw new OqlNormalizeException('Ambiguous filter code', $sSourceQuery, $this->GetNameDetails());
|
||||||
}
|
}
|
||||||
$sClassAlias = $aFieldClasses[$sFltCode][0];
|
$sClassAlias = $aFieldClasses[$sFltCode][0];
|
||||||
}
|
$this->SetParent($sClassAlias);
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!array_key_exists($sClassAlias, $aAliases))
|
|
||||||
{
|
|
||||||
throw new OqlNormalizeException('Unknown class [alias]', $sSourceQuery, $this->GetParentDetails(), array_keys($aAliases));
|
|
||||||
}
|
|
||||||
$sClass = $aAliases[$sClassAlias];
|
|
||||||
if (!$oModelReflection->IsValidFilterCode($sClass, $sFltCode))
|
|
||||||
{
|
|
||||||
throw new OqlNormalizeException('Unknown filter code', $sSourceQuery, $this->GetNameDetails(), $oModelReflection->GetFiltersList($sClass));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2015-08-31
|
2018-04-26
|
||||||
Reference in New Issue
Block a user