Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Unified Diff: tools/lexer_generator/transition_keys.py

Issue 157813004: Experimental parser: store literals as ints (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/lexer_generator/transition_key_test.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/transition_keys.py
diff --git a/tools/lexer_generator/transition_keys.py b/tools/lexer_generator/transition_keys.py
index a7ef16ee54f8a3aa56627de99fd53a56ad30f8db..14dfe770bf60c4ea83b3647b3ac07084be9c2f02 100644
--- a/tools/lexer_generator/transition_keys.py
+++ b/tools/lexer_generator/transition_keys.py
@@ -25,6 +25,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+from types import IntType
from itertools import chain
from action import Term
from string import printable
@@ -144,8 +145,7 @@ class TransitionKey(object):
@staticmethod
def omega():
'''Always matches.'''
- return TransitionKey.__cached_key(None, 'omega',
- lambda : Term("OMEGA_KEY"))
+ return TransitionKey.__cached_key(None, 'omega', lambda : Term("OMEGA_KEY"))
@staticmethod
def any(encoding):
@@ -154,13 +154,14 @@ class TransitionKey(object):
lambda : encoding.all_components_iter())
@staticmethod
- def single_char(encoding, char): # TODO(dcarney): char should be int
+ def single_char(encoding, char):
'''Returns a TransitionKey for a single-character transition.'''
- return TransitionKey(encoding, Term("NUMERIC_RANGE_KEY", ord(char), ord(char)))
+ return TransitionKey.range(encoding, char, char)
@staticmethod
def range(encoding, a, b):
'''Returns a TransitionKey for a single-character transition.'''
+ assert type(a) == IntType and type(b) == IntType
return TransitionKey(encoding, Term("NUMERIC_RANGE_KEY", a, b))
@staticmethod
@@ -176,10 +177,9 @@ class TransitionKey(object):
key = term.name()
args = term.args()
if key == 'RANGE':
- components.append(Term('NUMERIC_RANGE_KEY', ord(args[0]), ord(args[1])))
+ components.append(Term('NUMERIC_RANGE_KEY', args[0], args[1]))
elif key == 'LITERAL':
- for char in args[0]: # TODO(dcarney): don't use strings for literals
- components.append(Term('NUMERIC_RANGE_KEY', ord(char), ord(char)))
+ components += map(lambda x : Term('NUMERIC_RANGE_KEY', x, x), args)
elif key == 'CAT':
for x in args:
TransitionKey.__process_term(encoding, x, components, key_map)
« no previous file with comments | « tools/lexer_generator/transition_key_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698