| 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 dfa_nodes = {} | 350 dfa_nodes = {} |
| 351 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) | 351 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) |
| 352 return (start_name, dfa_nodes) | 352 return (start_name, dfa_nodes) |
| 353 | 353 |
| 354 def to_dot(self): | 354 def to_dot(self): |
| 355 | 355 |
| 356 def f(node, node_content): | 356 def f(node, node_content): |
| 357 for key, values in node.transitions().items(): | 357 for key, values in node.transitions().items(): |
| 358 if key == TransitionKey.epsilon(): | 358 if key == TransitionKey.epsilon(): |
| 359 key = "ε" | 359 key = "ε" |
| 360 key = str(key).replace('\\', '\\\\') |
| 360 for value in values: | 361 for value in values: |
| 361 if value[1]: | 362 if value[1]: |
| 362 node_content.append( | 363 node_content.append( |
| 363 " S_%d -> S_%d [ label = \"%s {%s} -> %s\" ];" % | 364 " S_%d -> S_%d [ label = \"%s {%s} -> %s\" ];" % |
| 364 (node.node_number(), value[0].node_number(), key, value[1][0], | 365 (node.node_number(), value[0].node_number(), key, value[1][0], |
| 365 value[1][1])) | 366 value[1][1])) |
| 366 else: | 367 else: |
| 367 node_content.append( | 368 node_content.append( |
| 368 " S_%d -> S_%d [ label = \"%s\" ];" % | 369 " S_%d -> S_%d [ label = \"%s\" ];" % |
| 369 (node.node_number(), value[0].node_number(), key)) | 370 (node.node_number(), value[0].node_number(), key)) |
| 370 return node_content | 371 return node_content |
| 371 | 372 |
| 372 node_content = self.__visit_all_edges(f, []) | 373 node_content = self.__visit_all_edges(f, []) |
| 373 | 374 |
| 374 return ''' | 375 return ''' |
| 375 digraph finite_state_machine { | 376 digraph finite_state_machine { |
| 376 rankdir=LR; | 377 rankdir=LR; |
| 377 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s | 378 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s |
| 378 node [shape = doublecircle, style=unfilled]; S_%s | 379 node [shape = doublecircle, style=unfilled]; S_%s |
| 379 node [shape = circle]; | 380 node [shape = circle]; |
| 380 %s | 381 %s |
| 381 } | 382 } |
| 382 ''' % (self.__start.node_number(), | 383 ''' % (self.__start.node_number(), |
| 383 self.__end.node_number(), | 384 self.__end.node_number(), |
| 384 "\n".join(node_content)) | 385 "\n".join(node_content)) |
| OLD | NEW |