Skip to content

Instantly share code, notes, and snippets.

@MarkusOstermayer
Last active December 31, 2019 15:43
Show Gist options
  • Save MarkusOstermayer/7eb3fbd58b27d99808fdd76979d4d9cc to your computer and use it in GitHub Desktop.
Save MarkusOstermayer/7eb3fbd58b27d99808fdd76979d4d9cc to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
A tool to create Markdowntables from Turingcode
"""
import sys
import re
def main():
states = []
# Check, if a Filename got passes to the Programm
if(len(sys.argv) < 2):
sys.stdout.write(f"Please execute: {sys.argv[0]} <filename>\n")
# Open the File in Readmode and store the Code
try:
code = None
with open(sys.argv[1], "r") as file:
code = file.readlines()
except FileNotFoundError:
sys.stdout.write("File not found\n")
return
# Hardcodet Tableheader
sys.stdout.write("| aktueller Status | aktuelles Symbol | neues Symbol "
"| Richtung | neuer Status |\n")
sys.stdout.write("| :------ | :------: | :------: | :------: "
"| :------ |\n")
oldstatus = "0"
states.append(oldstatus)
curstatus = None
for line in code:
# Fore removing inline COmments
line = re.sub(r"([;].+)", r"", line)
if (line[0] != ";" and len(line) > 1):
curstatus = line.split(" ")[0]
# Check if the Status is the past one known
if (curstatus != oldstatus):
sys.stdout.write("| |\n")
states.append(curstatus)
oldstatus = curstatus
sys.stdout.write("|".join(line.split(" ")))
sys.stdout.write("\n\n\n")
# Hardcodet Tableheader
sys.stdout.write("| Status | Erklaerung |\n")
sys.stdout.write("| :------ | :------: |\n")
for state in states:
sys.stdout.write(f"|{state}| ... |\n")
return
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment