oqlinterpreter.class.inc.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. class OqlNormalizeException extends OQLException
  3. {
  4. public function __construct($sIssue, $sInput, OqlName $oName, $aExpecting = null)
  5. {
  6. parent::__construct($sIssue, $sInput, 0, $oName->GetPos(), $oName->GetValue(), $aExpecting);
  7. }
  8. }
  9. class OqlInterpreterException extends OQLException
  10. {
  11. }
  12. class OqlInterpreter
  13. {
  14. public $m_sQuery;
  15. public function __construct($sQuery)
  16. {
  17. $this->m_sQuery = $sQuery;
  18. }
  19. // Note: this function is left public for unit test purposes
  20. public function Parse()
  21. {
  22. $oLexer = new OQLLexer($this->m_sQuery);
  23. $oParser = new OQLParser($this->m_sQuery);
  24. while($oLexer->yylex())
  25. {
  26. $oParser->doParse($oLexer->token, $oLexer->value, $oLexer->getTokenPos());
  27. }
  28. $res = $oParser->doFinish();
  29. return $res;
  30. }
  31. public function ParseObjectQuery()
  32. {
  33. $oRes = $this->Parse();
  34. if (!$oRes instanceof OqlObjectQuery)
  35. {
  36. throw new OqlException('Expecting an OQL query', $this->m_sQuery, 0, 0, get_class($oRes), array('OqlObjectQuery'));
  37. }
  38. return $oRes;
  39. }
  40. public function ParseExpression()
  41. {
  42. $oRes = $this->Parse();
  43. if (!$oRes instanceof Expression)
  44. {
  45. throw new OqlException('Expecting an OQL expression', $this->m_sQuery, 0, 0, get_class($oRes), array('Expression'));
  46. }
  47. return $oRes;
  48. }
  49. }
  50. ?>