oqlinterpreter.class.inc.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. protected function Parse()
  20. {
  21. $oLexer = new OQLLexer($this->m_sQuery);
  22. $oParser = new OQLParser($this->m_sQuery);
  23. while($oLexer->yylex())
  24. {
  25. $oParser->doParse($oLexer->token, $oLexer->value, $oLexer->getTokenPos());
  26. }
  27. $res = $oParser->doFinish();
  28. return $res;
  29. }
  30. public function ParseObjectQuery()
  31. {
  32. $oRes = $this->Parse();
  33. if (!$oRes instanceof OqlObjectQuery)
  34. {
  35. throw new OqlException('Expecting an OQL query', $this->m_sQuery, 0, 0, get_class($oRes), array('OqlObjectQuery'));
  36. }
  37. return $oRes;
  38. }
  39. /*
  40. public function ParseValueSetQuery()
  41. {
  42. $oRes = $this->Parse();
  43. if (!$oRes instanceof OqlValueSetQuery)
  44. {
  45. throw new OqlException('Expecting a value set query', $this->m_sQuery, 0, 0, get_class($oRes), array('OqlValueSetQuery'));
  46. }
  47. return $oRes;
  48. }
  49. */
  50. public function ParseExpression()
  51. {
  52. $oRes = $this->Parse();
  53. if (!$oRes instanceof Expression)
  54. {
  55. throw new OqlException('Expecting an OQL expression', $this->m_sQuery, 0, 0, get_class($oRes), array('Expression'));
  56. }
  57. return $oRes;
  58. }
  59. }
  60. ?>