Skip to content

Instantly share code, notes, and snippets.

@jy95
Created September 30, 2020 17:51
Show Gist options
  • Save jy95/62a07c7d0c85bfaf0997748f4362210e to your computer and use it in GitHub Desktop.
Save jy95/62a07c7d0c85bfaf0997748f4362210e to your computer and use it in GitHub Desktop.
generate_compilation_errors_table
def generate_compilation_errors_table(errors, allowed_sources):
msg = ""
# Don't add \r to that as it produces strange results
next_line = "\n"
indentation = 4
headers = ["File", "Line", "Error Message", "Code"]
# Headers
msg += ".. csv-table:: " + next_line
# Need a symbol that isn't in the Java
msg += " " * indentation + ":quote: §" + next_line
msg += " " * indentation + ":header: " + ",".join(headers) + next_line
msg += " " * indentation + ":widths: auto" + next_line * 2
# Allowed sources for that table
sources = [helper.relative_path(source) for source in allowed_sources]
# Contents
for error in [error for error in errors if error.get("source", "Unknown Source") in sources]:
# Print File , Line and Error message without problem
msg += " " * indentation + "§{}§".format(error.get("file", "Unknown Filename"))
msg += ",§{}§".format(error.get("line", "Unknown Line Number"))
msg += ",§{}§".format(error.get("message", "Unknown Message"))
# Print the code
code_lines = error.get("code", [])
# For whatever reason, INGINIOUS might truncate the stderr message if too long
# It might break the CSV table ... so we need this fix
if not code_lines:
# Might be confusing but they are the rules of RST for empty block
msg += ",§§" + next_line
else:
msg += ",§.. code-block:: java" + next_line * 2
indentation_for_code = indentation + 1
for code_line in code_lines:
# as we are in a code block, we need indentation + 1 in order to create compilable code in RST
msg += " " * indentation_for_code + code_line
# needed test to correctly format things
if code_line != code_lines[-1]:
msg += next_line
# At the end , we should not forget the quote symbol and the next line
msg += "§" + next_line
return msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment