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
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# comment
2+
# comment
3+
# comment
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
None + True - False
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@foo
2+
def bar():
3+
pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
...
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
a = 1
2+
3+
4+
5+
# comment
6+
b = 2
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def foo(a: int) -> int:
2+
return 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def foo(a, **b):
2+
pass
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def foo(a, *b):
2+
pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__init__ = 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import foo.bar
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import foo
2+
from .bar import foo
3+
from .. import foo
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def foo():
2+
if 1:
3+
2
4+
5+
def bar():
6+
2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
foo\
2+
bar
3+
4+
foo\
5+
bar
6+
7+
"foo\
8+
bar"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(1,
2+
2)
3+
4+
[
5+
1,
6+
2
7+
]
8+
9+
{ 1:
10+
2,
11+
3:
12+
13+
4
14+
15+
}
16+
17+
[
18+
1,
19+
2,
20+
]
21+
22+
foo(
23+
1, 2,
24+
3)
25+
26+
{ 1:
27+
2,
28+
3:
29+
30+
4,
31+
5:
32+
6
33+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if 1:
2+
if 2:
3+
123
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1
2+
-1
3+
0x1
4+
0xff
5+
0o123
6+
1.79769313486231e+308
7+
.5
8+
.a
9+
.
10+
0b01010101
11+
3.0.__format__
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1j
2+
10j
3+
10j+20
4+
10j-20
5+
j
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1_0
2+
-1_0
3+
0x_1
4+
0xf_f
5+
0o12_3
6+
1.797693_1348_6231e+3_08
7+
._5
8+
.a
9+
.
10+
0b0101_0101
11+
3.0.__format__
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
1 / 2
2+
1 // 2
3+
1 ** 2
4+
1 << 2
5+
1 >> 2
6+
1 += 2
7+
1 -= 2
8+
1 *= 2
9+
1 /= 2
10+
1 //= 2
11+
1 %= 2
12+
1 **= 2
13+
1 @= 2
14+
1 |= 2
15+
1 &= 2
16+
1 ^= 2
17+
1 <<= 2
18+
1 >>= 2
19+
1 == 2
20+
1 != 2
21+
1 >= 2
22+
1 <= 2
23+
1 or 2
24+
1 and 2
25+
not 1
26+
1 is 2
27+
1 is not 2
28+
1 in 2
29+
1 not in 2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
v[1]
2+
v[1:2]
3+
v[1:]
4+
v[:2]
5+
v[1:2]
6+
v[::]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"fdfd"
2+
'fsdgfd'
3+
"12\"34"
4+
"12\""
5+
"\"34"
6+
"12\r\n56"
7+
b"foo"
8+
r"bar"
9+
u"123"
10+
br"2332"
11+
rb"321432"
12+
13+
"""foo"""
14+
"""foo""" + 1
15+
16+
"""
17+
foo
18+
"""
19+
20+
"""\
21+
foo
22+
"""
23+
24+
"""A minimal subset of the locale module used at interpreter startup
25+
(imported by the _io module), in order to reduce startup time.
26+
27+
Don't import directly from third-party code; use the `locale` module instead!
28+
"""
29+
30+
"""
31+
\"""
32+
"""
33+
34+
"""\""""""
35+
36+
bg="#d00" if clear == NORMAL else"#fca"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if 1:
2+
pass
3+
else:
4+
2

0 commit comments

Comments
 (0)