Пример #1
0
 def testRegExpScanning(self):
     tests = [
         r'/^foo$/',
         r'/^[a-z]+/',
         '/^\\\\n/',
         r'/\[/',
         r'/[i]/',
         r'/[\]]/',
         r'/a[\]]/',
         r'/a[\]]b/',
         r'/[\]/]/gi',
         r'/\[[^\]]+\]/gi',
         r'/^(?!\d)(?:\w)+|^"(?:[^"]|"")+"/',
         r'/^@(?:(?!\d)(?:\w|\:)+|^"(?:[^"]|"")+")\[[^\]]+\]/',
         r"/^'(?:[^']|'')*'/",
         r'/^[0-9]+(?:\.[0-9]*(?:[eE][-+][0-9]+)?)?/',
         r'/^(?:==|=|<>|<=|<|>=|>|!~~|!~|~~|~|!==|!=|!~=|!~|!|&|\||\.|\:|,|\(|\)|\[|\]|\{|\}|\?|\:|;|@|\^|\/\+|\/|\*|\+|-)/',
     ]
     for string in tests:
         scanner = self.makeStringScanner(string)
         start = scanner.next()
         self.assertTokenTypeEqual('DIV', start)
         pattern = scanner.scan_regexp()
         flags = scanner.scan_regexp_flags()
         eof = scanner.next()
         self.assertTokenTypeEqual('REGEXP', pattern)
         self.assertTokenTypeEqual('EOF', eof)
Пример #2
0
 def getSingleToken(self, string):
     scanner = self.makeStringScanner(string)
     token = scanner.next()
     self.assertTokenTypeEqual('EOF', scanner.next())
     return token