Package: transmogripy
TransmogripyAboutTransmogripy is a tool to convert short pascal scripts to python. It is originally meant to convert TaLoS scripts but can be easily adapted to many other environments.RequirementsTransmogripy is intentionally meant to be run in bare-bones environments, so the only requirements are python >= 3.6, it can even run in embeddable systems like QGIS's python environment.On Numpynumpy is not a requirement, and is not even used. However, numpy might appear in the output script. This can be prevented by explicitly setting theallow_numpyparameter toFalse.UsageThe main function is theconvertfunction.fromtransmogripyimportconvertprint(convert("""vara: integer;beginstr := GetVal(Sym[j], 'Name') + ':' + IntToStr(Count[j]);a := 10; { do somethingalso this}(* repeat until loop execution *)repeatwriteln('repeat until loop execution: ', a);a := a + log10(12);l := floattoint(12.5);until a = 20;end"""))prints:"""
this script was automatically converted from pascal using transmogripy v...
"""

from talos import *
import math


def main():
   str = GetVal(Sym[j], 'Name') + ':' + str(count[j])
   a = 10  # do something
   # also this
   # repeat until loop execution
   while True:
      writeln('repeat until loop execution: ', a)
      a = a + math.log10(12)
      l = int(12.5)
      if a == 20: breakBehaviour ofResult :=There are many different ways to handle pascal'sResult:=code, and can be set withconvert'sresult_behaviourparameter:"variable": a temporary variable__Return__will be created and only returned at the end of the script"return":Result:=will be converted toreturnand a check for an early return will not be made."warn": as"return", except a warning will be issued if an early return is detected"try"(default): as"warn", but if an early warning is detected, the conversion will be re-tried with the"variable"optionComments and inline commentsThe conversion attempts to convert comments, however, all inline comments (comments that have code after them in the same line) will be removed:vara:integer;begina:=0;Result:=0;whilea<>10do{end of line comment}beginResult:=Result{inline comment}+a;a:=a+1;// end-of line commentend;endconverts to"""this script was automatically converted from pascal using transmogripy v..."""fromtalosimport*defmain():a=0__Return__=0whilea!=10:# end of line comment__Return__=__Return__+aa=a+1# end-of line commentreturn__Return__This behaviour can be changed with theremove_inline_commentsparameter, setting it toFalsewill instead raise an exception when an inline comment is encounteredImports, headers, and segmentsSome pascal function, likelog, require python libraries to be imported. Transmorgopy automatically adds libraries that are referenced in the converted code.vara:integer;begina:=0;Result:=0;whilea<>10dobeginResult:=Result+log10(a);a:=a+1;end;endconverts to"""this script was automatically converted from pascal using transmogripy v..."""fromtalosimport*importmathdefmain():a=0__Return__=0whilea!=10:__Return__=__Return__+math.log10(a)a=a+1return__Return__In addition, additional lines can be added before/after the converted code using thepre_words/post_wordsparameters. (note:pre_words's default is(from talos import *,), resulting in thefrom talos import *line)Code checkingBy default, Transmogripy checks the syntax of the output script, and issues a warning if any errors are found. This can be changed by setting thecheck_syntaxparameter toFalse.Not SupportedThe following Pascal/Delphi features are not supported and will raise an error:pre-compiler directives (foo({$IFDEF bar}bar{$ENDIF}))gotostatements (goto foo)all clauses and keywords (if/while/etc...) must be in lowercase (While)else if->elifis only supported ifelseandifare on the same linein general, only properly formatted scripts are supported