Skip to content

Commit

Permalink
improved py_scadparser error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-dh committed May 22, 2021
1 parent 18fe487 commit 7a0f612
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions solid/py_scadparser/scad_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ def p_module(p):
p[0] = ScadModule(p[2], params)

def p_error(p):
print(f'{p.lineno}:{p.lexpos} {p.type} - {p.value}')
print("syntex error")
print(f'py_scadparser: Syntax error: {p.lexer.filename}({p.lineno}) {p.type} - {p.value}')

def parseFile(scadFile):

lexer = lex.lex()
lexer.filename = scadFile
parser = yacc.yacc()

uses = []
Expand Down
9 changes: 5 additions & 4 deletions solid/py_scadparser/scad_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def t_NUMBER(t):
return t

def t_error(t):
print(f'Illegal character ({t.lexer.lineno}) "{t.value[0]}"')
print(f'py_scadparser: Illegal character: {t.lexer.filename}({t.lexer.lineno}) "{t.value[0]}"')
t.lexer.skip(1)

if __name__ == "__main__":
Expand All @@ -97,9 +97,10 @@ def t_error(t):

p = Path(sys.argv[1])
f = p.open()
lex.lex()
lex.input(''.join(f.readlines()))
for tok in iter(lex.token, None):
lexer = lex.lex()
lexer.filename = p.as_posix()
lexer.input(''.join(f.readlines()))
for tok in iter(lexer.token, None):
if tok.type == "MODULE":
print("")
print(repr(tok.type), repr(tok.value), end='')
Expand Down

0 comments on commit 7a0f612

Please sign in to comment.