From 61dd2b83af1c5e48059481ab6b0c483400a3efc1 Mon Sep 17 00:00:00 2001 From: gregorni Date: Sat, 24 Jun 2023 19:47:11 +0200 Subject: [PATCH] Build an AST instead of compiling and decompiling This doesn't currently work, though, it won't reformat anything --- blueprintcompiler/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/blueprintcompiler/main.py b/blueprintcompiler/main.py index 9087b67..a783e45 100644 --- a/blueprintcompiler/main.py +++ b/blueprintcompiler/main.py @@ -19,7 +19,7 @@ import typing as T -import argparse, json, os, sys +import argparse, json, os, sys, re from .errors import PrintableError, report_bug, MultipleErrors, CompilerBugError from .gir import add_typelib_search_path @@ -188,13 +188,19 @@ class BlueprintApp: for warning in warnings: warning.pretty_print(file.name, data, stream=sys.stderr) - formatted = decompiler.decompile_string(xml) + tokens = tokenizer.tokenize(data) - if data != formatted: + tokenized_str = "" + for item in tokens: + tokenized_str += str(item) + + print(tokenized_str) + + if data != tokenized_str: if not opts.check: file.seek(0) file.truncate() - file.write(formatted) + file.write(tokenized_str) formatted_files += 1