Reviewers: dcarney,
Message:
Committed patchset #1 manually as r17890.
Description:
Experimental lexer generator: Clarify TransitionKeys.disjoint_keys.
Also add a test which is really an example of what it does.
[email protected]
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=17890
Please review this at https://codereview.chromium.org/74713004/
SVN Base: https://v8.googlecode.com/svn/branches/experimental/parser
Affected files (+16, -2 lines):
M tools/lexer_generator/transition_key_test.py
M tools/lexer_generator/transition_keys.py
Index: tools/lexer_generator/transition_key_test.py
diff --git a/tools/lexer_generator/transition_key_test.py
b/tools/lexer_generator/transition_key_test.py
index
ef8fe6dce30df6ca88b562845c6e68d96197a9a4..3180b02052b5e31070e4e38e6c6828ab67ba6f0e
100644
--- a/tools/lexer_generator/transition_key_test.py
+++ b/tools/lexer_generator/transition_key_test.py
@@ -77,3 +77,12 @@ class TransitionKeyTestCase(unittest.TestCase):
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)
Index: tools/lexer_generator/transition_keys.py
diff --git a/tools/lexer_generator/transition_keys.py
b/tools/lexer_generator/transition_keys.py
index
ba0d9db40cb615605929d0619f752d0326d7a60a..f2035d4f4aecd476898b7879c165663ac412fbaf
100644
--- a/tools/lexer_generator/transition_keys.py
+++ b/tools/lexer_generator/transition_keys.py
@@ -161,7 +161,7 @@ class TransitionKey:
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 @@ class TransitionKey:
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.