Python: Copy Python extractor to codeql repo

This commit is contained in:
Taus
2024-02-28 15:15:21 +00:00
parent 297a17975d
commit 6dec323cfc
369 changed files with 165346 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
from . import test_tokenizer
import sys
from blib2to3.pgen2.token import tok_name
def printtoken(type, token, start, end): # for testing
token_range = "%d,%d-%d,%d:" % (start + end)
print("%-20s%-15s%r" %
(token_range, tok_name[type], token)
)
def main():
verbose = sys.argv[1] == "-v"
if verbose:
inputfile = sys.argv[2]
else:
inputfile = sys.argv[1]
with open(inputfile, "r") as input:
t = test_tokenizer.Tokenizer(input.read()+"\n")
for tkn in t.tokens(verbose):
printtoken(*tkn)
if __name__ == "__main__":
main()