Skip to content

Requirements and workflow design

Ilya Andreev edited this page Jul 7, 2022 · 1 revision

Requirements

  • The jar executable should take the path of the python input file as a command line argument, and optionally take the path of the output file
  • If the Python input file has valid Python 3.9 syntax, translate it to eolang and write the result to the output file provided, or place the result near the input file if no output files were provided
  • If the input python does not have valid Python 3.9 syntax, inform the user
  • The repository should provide a set of tests which can be transpiled to the executable eolang code
  • The repository should provide tools for transpiling some big python project, indicate that no exceptions were thrown from the transpiler and the resulting eolang files are syntactically correct

Workflow

  • The main function parses the command line arguments and (if an existing input file was provided) reads the file
  • The parser module uses the ANTLR parser to build an abstract syntax tree and then maps its tree to our own internal representation (also based on AST)
  • The SimplePass module applies several python-to-python passes to eliminate some constructions which are not supported in eolang. These include:
    • Eliminate if-else statements with > 2 branches (rewrite an if-elsif-else as many if-else statements)
    • Eliminate for: rewrite it as a while + try
    • Prepend each identifier with x, so that no identifier starts with a capital letter
    • Standardize (simplify) quotes for string literals
    • Simplify except clauses for exception handling: change multiple except clauses of a try block to one except:, which catches everything, and a series of if-else, which emulates the behaviour of all the typed except clauses and reraises the exception if it should not be caught
    • Eliminate if-else again (because complex if-else statements appear as a result of the previous pass)
    • Eliminate complex assignments (i.e., translate a = b = c to b = c; a = b)
    • Eliminate simple cases of method calls (that is, substitute pointer to this explicitly)
    • Extract all function calls to the statement level to make the execution order explicit (i.e., translate a = f(1) + g(2) to tmp1 = f(1); tmp2 = g(2); a = tmp1 + tmp2
  • The resulting simplified AST is then translated to the eolang code and printed to the provided output path or to the file next to the input file