Commit 5ea2ef68 authored by Pierre Augier's avatar Pierre Augier
Browse files

Get block name

parent 3a475b05b92c
......@@ -17,11 +17,15 @@ class MyClass:
result = fp.use_pythranized_block("block0")
else:
# pythran block (
# float[][] a, b,
# float[][] a, b;
# int n
# ) -> result
# silly comment
# another comment here
# pythran block (
# float[][][] a, b,
# float[][][] a, b;
# int n
# ) -> result
result = 0.0
......
from tokenize import tokenize, untokenize
from tokenize import (
tokenize,
untokenize,
COMMENT,
INDENT,
DEDENT,
OP,
STRING,
NAME,
)
from token import tok_name
from io import BytesIO
path = "example_class.py"
blocks = []
with open(path) as file:
code = file.read()
has_to_find_name_block = False
g = tokenize(BytesIO(code.encode('utf-8')).readline)
g = tokenize(BytesIO(code.encode("utf-8")).readline)
for toknum, tokval, a, b, c in g:
print((toknum, tokval, a, b, c))
if toknum == NAME and tokval == "use_pythranized_block":
has_to_find_name_block = True
if has_to_find_name_block and toknum == STRING:
name_block = eval(tokval)
print("Block", name_block)
has_to_find_name_block = False
blocks.append(name_block)
print((tok_name[toknum], tokval))
print(blocks)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment