thorrparse.ipp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef __THORRPARSE_IPP_
  14. #define __THORRPARSE_IPP_
  15. #include "thorralgo.ipp"
  16. #include "roxiemem.hpp"
  17. //--------------------------------------------------------------------------
  18. //NB: This is malloced..
  19. struct RegexMatchInfo : public CInterface
  20. {
  21. public:
  22. inline RegexMatchInfo(const void * _row) : row(_row) { }
  23. inline void setown(const void * _row) { row.setown(_row); }
  24. public:
  25. roxiemem::OwnedConstRoxieRow row;
  26. unsigned length;
  27. int score;
  28. };
  29. class RegexMatches : public CInterface, public INlpResultIterator
  30. {
  31. enum { MaxCachedResult=100 };
  32. public:
  33. RegexMatchInfo * appendOwnResult(const void * _row)
  34. {
  35. RegexMatchInfo * match = new RegexMatchInfo(_row);
  36. results.append(*match);
  37. return match;
  38. }
  39. RegexMatchInfo * createMatch();
  40. void reset();
  41. virtual bool first()
  42. {
  43. cur = 0;
  44. return results.isItem(cur);
  45. }
  46. virtual bool next()
  47. {
  48. cur++;
  49. return results.isItem(cur);
  50. }
  51. virtual bool isValid()
  52. {
  53. return results.isItem(cur);
  54. }
  55. virtual const void * getRow()
  56. {
  57. return rtlLinkRow(results.item(cur).row);
  58. }
  59. protected:
  60. unsigned cur;
  61. CIArrayOf<RegexMatchInfo> results;
  62. };
  63. class THORHELPER_API RegexParser : public CInterface, public INlpMatchedAction, public INlpParser
  64. {
  65. public:
  66. RegexParser(ICodeContext * ctx, RegexAlgorithm * _algo, INlpHelper * _helper, unsigned _activityId);
  67. ~RegexParser();
  68. IMPLEMENT_IINTERFACE
  69. virtual bool performMatch(IMatchedAction & action, const void * in, unsigned len, const void * data);
  70. virtual INlpResultIterator * queryResultIter() { return &results; }
  71. virtual void reset() { results.reset(); }
  72. virtual bool onMatch(NlpState & matched);
  73. const void * createMatchRow(RegexState & state, NlpMatchWalker & walker);
  74. public:
  75. INlpHelper * helper;
  76. Owned<IEngineRowAllocator> outputAllocator;
  77. RegexAlgorithm * algo;
  78. RegexMatches results;
  79. CRegexMatchedResults matched;
  80. RegexStateCache cache;
  81. unsigned charWidth;
  82. };
  83. #endif /* __THORRPARSE_HPP_ */