From 5084a0b41870d9813096a4ade3bda5e4c1111a09 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 5 Nov 2014 22:27:10 +0100 Subject: [PATCH] Attempt to silence yacc Reference #65 --- patacrep/latex/syntax.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/patacrep/latex/syntax.py b/patacrep/latex/syntax.py index a1be7181..896d8442 100644 --- a/patacrep/latex/syntax.py +++ b/patacrep/latex/syntax.py @@ -224,26 +224,33 @@ class Parser: else: symbols[0] = symbols[2].prepend(symbols[1]) +def silent_yacc(*args, **kwargs): + """Call yacc, suppressing (as far as possible) output and generated files. + """ + return yacc.yacc( + write_tables=0, + debug=0, + *args, + **kwargs + ) def tex2plain(string): """Parse string and return its plain text version.""" return detex( - yacc.yacc( - write_tables=0, - debug=0, - module=Parser(), - ).parse( - string, - lexer=SimpleLexer().lexer, - ) + silent_yacc( + module=Parser(), + ).parse( + string, + lexer=SimpleLexer().lexer, ) + ) def parsesong(string, filename=None): """Parse song and return its metadata.""" return detex( - yacc.yacc(module=Parser(filename)).parse( - string, - lexer=SongLexer().lexer, - ).metadata - ) + silent_yacc(module=Parser(filename)).parse( + string, + lexer=SongLexer().lexer, + ).metadata + )