Update of /cvsroot/wisp/wisp/users/dig
In directory sc8-pr-cvs1:/tmp/cvs-serv4068
Modified Files:
tran.py
Log Message:
made the parser chop up string literals
Index: tran.py
===================================================================
RCS file: /cvsroot/wisp/wisp/users/dig/tran.py,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- tran.py 18 May 2003 18:00:09 -0000 1.118
+++ tran.py 18 May 2003 21:28:22 -0000 1.119
@@ -110,13 +110,30 @@
this.commenters = '\\'
this.quotes = '"'
this.wordchars += '!#$%&()*+,-./:;<=>?@[]'
+ this.waiting = []
def get_token (this):
+ if this.waiting: return this.waiting.pop(0)
tok = shlex.get_token(this)
if tok == '': tok = None
elif tok[:2] == '#o': tok = Integer_Literal(long(tok[2:], 8))
elif tok[:2] == '#x': tok = Integer_Literal(long(tok[2:], 16))
elif tok[:2] == '#/' and len(tok) == 3:
tok = Integer_Literal(ord(tok[2]))
+ elif tok[0] == tok[-1] == '"':
+ s = []; esc = 0
+ for c in tok[1:-1]:
+ if esc:
+ esc = 0
+ try: c = {'n': '\n', 'r': '\r'}[c]
+ except: pass
+ elif c == '\\':
+ esc = 1
+ continue
+ s.insert(0, Integer_Literal(ord(c)))
+ if esc == 1: raise 'trailing escape', tok
+ s.append(Integer_Literal(len(s)))
+ this.waiting = s
+ return this.waiting.pop(0)
else:
try: tok = Integer_Literal(long(tok, 10))
except: pass
|