comparison test_jsscan.py @ 2:f82ff2c61c06

added ignore kwarg
author Atul Varma <avarma@mozilla.com>
date Thu, 22 Apr 2010 13:18:09 -0700
parents daa1c6d996f3
children 30c1f55eff96
comparison
equal deleted inserted replaced
1:22781f88a857 2:f82ff2c61c06
18 ('literal', '=', (1, 8)) 18 ('literal', '=', (1, 8))
19 ('whitespace', ' ', (1, 9)) 19 ('whitespace', ' ', (1, 9))
20 ('digits', '1', (1, 10)) 20 ('digits', '1', (1, 10))
21 ('literal', ';', (1, 11)) 21 ('literal', ';', (1, 11))
22 22
23 Filtering:
24
25 >>> tokenize(' k', ignore='whitespace')
26 ('name', 'k', (1, 2))
27
23 Escaped double-quoted strings: 28 Escaped double-quoted strings:
24 29
25 >>> tokenize(r'"i say \\"tomato\\""') 30 >>> tokenize(r'"i say \\"tomato\\""')
26 ('string', '"i say \\\\"tomato\\\\""', (1, 0)) 31 ('string', '"i say \\\\"tomato\\\\""', (1, 0))
27 32
35 40
36 import doctest 41 import doctest
37 42
38 from jsscan import * 43 from jsscan import *
39 44
40 def tokenize(string): 45 def tokenize(string, ignore=None):
41 for token in Tokenizer(string).tokenize(): 46 for token in Tokenizer(string).tokenize(ignore=ignore):
42 print token 47 print token
43 48
44 if __name__ == '__main__': 49 if __name__ == '__main__':
45 doctest.testmod(verbose=True) 50 doctest.testmod(verbose=True)