from string import ascii_lowercase, digits ################################## StringName = u'PyJsConstantString%d_' NumberName = u'PyJsConstantNumber%d_' RegExpName = u'PyJsConstantRegExp%d_' ################################## ALPHAS = set(ascii_lowercase+ ascii_lowercase.upper()) NUMS = set(digits) IDENTIFIER_START = ALPHAS.union(NUMS) ESCAPE_CHARS = {'n', '0', 'b', 'f', 'r', 't', 'v', '"', "'", '\\'} OCTAL = {'0', '1', '2', '3', '4', '5', '6', '7'} HEX = set('0123456789abcdefABCDEF') from utils import * IDENTIFIER_PART = IDENTIFIER_PART.union({'.'}) def _is_cancelled(source, n): cancelled = False k = 0 while True: k+=1 if source[n-k]!='\\': break cancelled = not cancelled return cancelled def _ensure_regexp(source, n): #<- this function has to be improved '''returns True if regexp starts at n else returns False checks whether it is not a division ''' markers = '(+~"\'=[%:?!*^|&-,;/\\' k = 0 while True: k+=1 if n-k<0: return True char = source[n-k] if char in markers: return True if char!=' ' and char!='\n': break return False def parse_num(source, start, charset): """Returns a first index>=start of chat not in charset""" while start max_num: break num = cand len_parsed += 1 # we have to return in a different form because python may want to parse more... # for example '\777' will be parsed by python as a whole while js will use only \77 return '\\' + hex(num)[1:], n + len_parsed return source[n+1], n+2 #####TEST###### if __name__=='__main__': test = (''' ''') t, d = remove_constants(test) print t, d