/src/lib/regular_expression/internal/regular_expression_items/regular_expression_item_look.e

http://github.com/tybor/Liberty · Specman e · 104 lines · 64 code · 12 blank · 28 comment · 3 complexity · 5d796e621e523373df5e3f530e071a49 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class REGULAR_EXPRESSION_ITEM_LOOK
  5. --
  6. --
  7. inherit
  8. REGULAR_EXPRESSION_ITEM
  9. REGULAR_EXPRESSION_ITEM_GLOBALS
  10. create {ANY}
  11. make
  12. feature {ANY}
  13. node: BACKTRACKING_NODE
  14. -- the node look
  15. is_ahead: BOOLEAN
  16. -- should look ahead? (or else behind?)
  17. is_positive: BOOLEAN
  18. -- is positive look? (or else negative?)
  19. make (value: BACKTRACKING_NODE; ahead, positive: BOOLEAN)
  20. require
  21. value_not_void: value /= Void
  22. do
  23. node := value
  24. is_ahead := ahead
  25. is_positive := positive
  26. ensure
  27. definition: node = value and is_ahead = ahead and is_positive = positive
  28. node_not_void: node /= Void
  29. end
  30. explore (matcher: BACKTRACKING_REGULAR_EXPRESSION)
  31. do
  32. if is_ahead then
  33. matcher.begin_look_ahead
  34. matcher.push_cut_point
  35. if is_positive then
  36. matcher.push_or(the_end_look_ahead_backtrack_item)
  37. matcher.push_and(the_end_look_ahead_continue_item)
  38. else
  39. matcher.push_or(the_end_look_ahead_continue_item)
  40. matcher.push_and(the_end_look_ahead_backtrack_item)
  41. end
  42. else
  43. matcher.begin_look_behind
  44. matcher.push_cut_point
  45. if is_positive then
  46. matcher.push_or(the_end_look_behind_backtrack_item)
  47. matcher.push_and(the_end_look_behind_continue_item)
  48. else
  49. matcher.push_or(the_end_look_behind_continue_item)
  50. matcher.push_and(the_end_look_behind_backtrack_item)
  51. end
  52. end
  53. matcher.set_current_node(node)
  54. end
  55. feature {} -- looks
  56. the_end_look_ahead_backtrack_item: REGULAR_EXPRESSION_ITEM_LOOK_END
  57. once
  58. create Result.make(True, False)
  59. end
  60. the_end_look_ahead_continue_item: REGULAR_EXPRESSION_ITEM_LOOK_END
  61. once
  62. create Result.make(True, True)
  63. end
  64. the_end_look_behind_backtrack_item: REGULAR_EXPRESSION_ITEM_LOOK_END
  65. once
  66. create Result.make(False, False)
  67. end
  68. the_end_look_behind_continue_item: REGULAR_EXPRESSION_ITEM_LOOK_END
  69. once
  70. create Result.make(False, True)
  71. end
  72. end -- class REGULAR_EXPRESSION_ITEM_LOOK
  73. --
  74. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  75. --
  76. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  77. -- of this software and associated documentation files (the "Software"), to deal
  78. -- in the Software without restriction, including without limitation the rights
  79. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  80. -- copies of the Software, and to permit persons to whom the Software is
  81. -- furnished to do so, subject to the following conditions:
  82. --
  83. -- The above copyright notice and this permission notice shall be included in
  84. -- all copies or substantial portions of the Software.
  85. --
  86. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  87. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  88. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  89. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  90. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  91. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  92. -- THE SOFTWARE.