PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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