| OLD | NEW |
| 1 # Copyright 2013 the V8 project authors. All rights reserved. | 1 # Copyright 2013 the V8 project authors. All rights reserved. |
| 2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
| 3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
| 4 # met: | 4 # met: |
| 5 # | 5 # |
| 6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
| 9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
| 10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 from types import TupleType | 28 from types import TupleType |
| 29 from inspect import getmembers | 29 from inspect import getmembers |
| 30 from nfa import * | 30 from nfa import * |
| 31 | 31 |
| 32 # Nfa is built in two stages: |
| 33 # 1. Build a tree of operations on rules. |
| 34 # Each node in the tree is a tuple (operation, subtree1, ... subtreeN). |
| 35 # Rule parser builds this tree by invoking static methods of NfaBuilder. |
| 36 # 2. For each node, perform the operation of the node to produce an Nfa. |
| 37 # If an operation is called X, then it is performed by the method |
| 38 # of NfaBuilder called __x(). See __process() for mapping from |
| 39 # operation to processing methods. |
| 40 |
| 32 class NfaBuilder(object): | 41 class NfaBuilder(object): |
| 33 | 42 |
| 34 def __init__(self, encoding, character_classes = {}): | 43 def __init__(self, encoding, character_classes = {}): |
| 35 self.__node_number = 0 | 44 self.__node_number = 0 |
| 36 self.__operation_map = {} | 45 self.__operation_map = {} |
| 37 self.__members = getmembers(self) | 46 self.__members = getmembers(self) |
| 38 self.__encoding = encoding | 47 self.__encoding = encoding |
| 39 self.__character_classes = character_classes | 48 self.__character_classes = character_classes |
| 40 self.__states = [] | 49 self.__states = [] |
| 41 self.__global_end_node = None | 50 self.__global_end_node = None |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 337 |
| 329 __modifer_map = { | 338 __modifer_map = { |
| 330 '+': 'ONE_OR_MORE', | 339 '+': 'ONE_OR_MORE', |
| 331 '?': 'ZERO_OR_ONE', | 340 '?': 'ZERO_OR_ONE', |
| 332 '*': 'ZERO_OR_MORE', | 341 '*': 'ZERO_OR_MORE', |
| 333 } | 342 } |
| 334 | 343 |
| 335 @staticmethod | 344 @staticmethod |
| 336 def apply_modifier(modifier, graph): | 345 def apply_modifier(modifier, graph): |
| 337 return (NfaBuilder.__modifer_map[modifier], graph) | 346 return (NfaBuilder.__modifer_map[modifier], graph) |
| OLD | NEW |