Revision: 17890
Author: [email protected]
Date: Tue Nov 19 18:47:08 2013 UTC
Log: Experimental lexer generator: Clarify
TransitionKeys.disjoint_keys.
Also add a test which is really an example of what it does.
[email protected]
BUG=
Review URL: https://codereview.chromium.org/74713004
http://code.google.com/p/v8/source/detail?r=17890
Modified:
/branches/experimental/parser/tools/lexer_generator/transition_key_test.py
/branches/experimental/parser/tools/lexer_generator/transition_keys.py
=======================================
---
/branches/experimental/parser/tools/lexer_generator/transition_key_test.py
Wed Nov 6 09:14:29 2013 UTC
+++
/branches/experimental/parser/tools/lexer_generator/transition_key_test.py
Tue Nov 19 18:47:08 2013 UTC
@@ -77,3 +77,12 @@
graph = RegexParser.parse("[^:self_defined:]")
key = TransitionKey.character_class(graph, classes)
self.assertTrue(key.matches_char('A'))
+
+
+ def test_disjoint_keys(self):
+ key1 = TransitionKey([(1, 10)])
+ key2 = TransitionKey([(5, 15)])
+ disjoint_set = TransitionKey.disjoint_keys(set([key1, key2]))
+ self.assertTrue(TransitionKey([(1, 4)]) in disjoint_set)
+ self.assertTrue(TransitionKey([(5, 10)]) in disjoint_set)
+ self.assertTrue(TransitionKey([(11, 15)]) in disjoint_set)
=======================================
--- /branches/experimental/parser/tools/lexer_generator/transition_keys.py
Tue Nov 19 18:25:42 2013 UTC
+++ /branches/experimental/parser/tools/lexer_generator/transition_keys.py
Tue Nov 19 18:47:08 2013 UTC
@@ -161,7 +161,7 @@
already constructed aliases for character classes (they can be used in
the
new character class). It is a map from strings (character class names)
to
TransitionKeys. For example, graph might represent the character class
- [a-z:digit:] where 'digit' is a previously constructed characte class
found
+ [a-z:digit:] where 'digit' is a previously constructed character class
found
in "key_map".'''
ranges = []
assert graph[0] == 'CLASS' or graph[0] == 'NOT_CLASS'
@@ -316,7 +316,12 @@
def disjoint_keys(key_set):
'''Takes a set of possibly overlapping TransitionKeys, returns a list
of
TransitionKeys which don't overlap and whose union is the same as the
union
- of the original key_set. key_set is a set of TransitionKeys.'''
+ of the original key_set. In addition, TransitionKeys are not merged,
only
+ split.
+
+ For example, if key_set contains two TransitionKeys for ranges [1-10]
and
+ [5-15], disjoint_keys returns a set of three TransitionKeys: [1-4],
[5-10],
+ [11-16].'''
ranges = TransitionKey.__disjoint_ranges_from_key_set(key_set)
return map(lambda x : TransitionKey([x]), ranges)
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.