erros para stderr e mais cenas

This commit is contained in:
Afonso Franco 2023-05-28 22:41:52 +01:00
parent f04cd34656
commit c66bd1cace
Signed by: afonso
SSH key fingerprint: SHA256:JiuxZNdA5bRWXPMUJChI0AQ75yC+cXY4xM0IaVwEVys
9 changed files with 14 additions and 13 deletions

BIN
relatorio/pltoml-help.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
relatorio/pltoml-input.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

BIN
relatorio/pltoml.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View file

@ -48,13 +48,13 @@ def p_table_simple(p):
temp[headers[-1]] = {}
temp = temp[headers[-1]]
else:
print("Cannot define the same table twice")
print("Cannot define the same table twice",file=sys.stderr)
p.parser.syntax_error = True
return
p.parser.current_header = temp
p.parser.current_header_name = p[1]
# isto ta errado
def p_table_array(p):
"""table : ARRTABLE"""
p.parser.current_inline_tables = []
@ -71,8 +71,9 @@ def p_table_array(p):
temp[headers[-1]] = [{}]
else:
if not isinstance(temp[headers[-1]], list):
print(f"Error, cannot define {path} is not a list")
print(f"Error, cannot define {path} is not a list",file=sys.stderr)
p.parser.syntax_error = True
return
temp[headers[-1]].append({})
temp = temp[headers[-1]][-1]
p.parser.current_header = temp
@ -93,13 +94,13 @@ def p_object(p):
if len(p[1]) > 1:
for table in p.parser.current_inline_tables:
if p[1][: len(table)] == table:
print(f"Error, trying to redefine {path}, an inline table")
print(f"Error, trying to redefine {path}, an inline table",file=sys.stderr)
return
is_table = True
if isinstance(p[3], dict):
for table in p.parser.current_tables:
if table[: len(p[1])] == p[1]:
print(f"Error, trying to redefine {path}, a table")
print(f"Error, trying to redefine {path}, a table",file=sys.stderr)
return
p.parser.current_inline_tables.append(p[1])
if is_table:
@ -109,10 +110,10 @@ def p_object(p):
temp[header] = {}
temp = temp[header]
if not isinstance(temp, dict):
print("Error, cannot add {p[3]} to a {type(temp)} variable")
print("Error, cannot add {p[3]} to a {type(temp)} variable",file=sys.stderr)
return
if headers[-1] in temp:
print(f"Error, cannot define {path} twice")
print(f"Error, cannot define {path} twice",file=sys.stderr)
return
temp[headers[-1]] = p[3]
@ -160,7 +161,7 @@ def p_dictCont_multiple(p):
"""dictCont : dictCont ',' dictElem"""
duplicate_list = [k for k in p[1] if k in p[3]]
for dup in duplicate_list:
print(f"Duplicate inline-table key {dup}")
print(f"Duplicate inline-table key {dup}",file=sys.stderr)
if len(duplicate_list) == 0:
p[1].update(p[3])
p[0] = p[1]
@ -293,7 +294,7 @@ def parse(in_file, out_file):
in_content = in_fd.read()
in_fd.close()
except Exception as e:
print(f"Error: {e}")
print(f"Error: {e}",file=sys.stderr)
return
else:
in_content = sys.stdin.read()
@ -307,7 +308,7 @@ def parse(in_file, out_file):
out_fd.write(output)
out_fd.close()
except Exception as e:
print(f"Error: {str(e)}")
print(f"Error: {str(e)}",file=sys.stderr)
return
else:
print(output)

View file

@ -11,7 +11,7 @@ def greetings():
print(r" / ____/ /___/ / / /_/ / / / / /___")
print(r" /_/ /_____/_/ \____/_/ /_/_____/")
print(r"--------------------------------------")
print(r"Authors: Tiago Sousa and Afonso Franco")
print(r" Processamento de Linguagens 2022/23 ")
print(r"--------------------------------------")
def main():

View file

@ -8,7 +8,7 @@ def tokenizer(in_file,out_file):
in_content = in_fd.read()
in_fd.close()
except Exception as e:
print(f"Error: {e}")
print(f"Error: {e}",file=sys.stderr)
return
else:
in_content = sys.stdin.read()
@ -23,7 +23,7 @@ def tokenizer(in_file,out_file):
out_fd.write(output)
out_fd.close()
except Exception as e:
print(f"Error: {e}")
print(f"Error: {e}",file=sys.stderr)
return
else:
print(output)