Skip to content

Commit c720dda

Browse files
committed
1 parent 333d2d9 commit c720dda

34 files changed

+509
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
import utokenize as tokenize
3+
4+
5+
f = open(sys.argv[1], "r")
6+
for t in tokenize.generate_tokens(f.readline):
7+
print(t)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys
2+
import utokenize as tokenize
3+
4+
5+
f = open(sys.argv[1], "r")
6+
for t in tokenize.generate_tokens(f.readline):
7+
# print(t)
8+
print(
9+
"TokenInfo(type=%d (%s), string=%r, startl=%d)"
10+
% (t.type, tokenize.tok_name[t.type], t.string, t.start)
11+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Same as example_dump.py, but for CPython's tokenize module
2+
import sys
3+
import tokenize as tokenize
4+
5+
6+
f = open(sys.argv[1], "r")
7+
for t in tokenize.generate_tokens(f.readline):
8+
# print(t)
9+
print(
10+
"TokenInfo(type=%d (%s), string=%r, startl=%d)"
11+
% (t.type, tokenize.tok_name[t.type], t.string, t.start[0])
12+
)

python-stdlib/utokenize/metadata.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
srctype = micropython-lib
2+
type = module
3+
version = 2.0
4+
author = Paul Sokolovsky
5+
long_desc = Simple tokenizer for Python source code.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sys
2+
import os
3+
import glob
4+
5+
6+
def handle_one(f):
7+
rc = os.system("pycopy example_test_dump.py %s >%s.upy" % (f, f))
8+
if rc != 0:
9+
print("%s: FAIL" % f)
10+
return False
11+
rc = os.system("diff -u %s.cpy %s.upy" % (f, f))
12+
if rc != 0:
13+
print("%s: error" % f)
14+
return False
15+
print("%s: ok" % f)
16+
return True
17+
18+
19+
if len(sys.argv) > 1 and sys.argv[1] == "--make-expected":
20+
for f in glob.glob("testdata/*.py"):
21+
rc = os.system("python3.6 example_test_dump_cpy.py %s >%s.cpy" % (f, f))
22+
assert rc == 0
23+
sys.exit()
24+
25+
26+
errors = False
27+
28+
for f in sorted(glob.glob("testdata/*.py")):
29+
e = handle_one(f)
30+
errors = errors or not e
31+
32+
sys.exit(int(errors))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.cpy
2+
*.upy
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def foo():
2+
print(1)
3+
print(2)
4+
5+
foo()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def foo():
2+
print(1)
3+
4+
print(2)
5+
6+
7+
print(3)
8+
9+
print(4)
10+
11+
print(5)
12+
13+
14+
foo()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def foo():
2+
if 1:
3+
if 2:
4+
pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo # comment

0 commit comments

Comments
 (0)