3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-16 17:09:33 +01:00

Update paren.py module to improve parentheses verbosity

This commit is contained in:
Pragmatic Software 2014-12-20 19:44:40 +00:00
parent a09d3c1d63
commit ba59edb040
2 changed files with 7 additions and 5 deletions

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 801, BUILD_REVISION => 802,
BUILD_DATE => "2014-12-18", BUILD_DATE => "2014-12-20",
}; };
1; 1;

View File

@ -4,7 +4,7 @@ from __future__ import print_function
import sys import sys
from pycparser import c_parser, c_generator, c_ast, plyparser from pycparser import c_parser, c_generator, c_ast, plyparser
from pycparser.ply import yacc from pycparser.ply import yacc
with open("paren/stddef") as f: with open("paren/stddef") as f:
STDDEF = f.read() STDDEF = f.read()
@ -19,7 +19,7 @@ class CParser(c_parser.CParser):
errorlog=yacc.NullLogger(), errorlog=yacc.NullLogger(),
optimize=kw.get('yacc_optimize', True), optimize=kw.get('yacc_optimize', True),
tabmodule=kw.get('yacctab', 'yacctab')) tabmodule=kw.get('yacctab', 'yacctab'))
def parse(self, text, filename='', debuglevel=0): def parse(self, text, filename='', debuglevel=0):
self.clex.filename = filename self.clex.filename = filename
self.clex.reset_lineno() self.clex.reset_lineno()
@ -35,6 +35,9 @@ class CParser(c_parser.CParser):
class CGenerator(c_generator.CGenerator): class CGenerator(c_generator.CGenerator):
def _is_simple_node(self, n):
return isinstance(n, (c_ast.Constant, c_ast.ID, c_ast.FuncCall))
def visit_UnaryOp(self, n): def visit_UnaryOp(self, n):
# don't parenthesize an operand to sizeof if it's not a type # don't parenthesize an operand to sizeof if it's not a type
if n.op == 'sizeof': if n.op == 'sizeof':
@ -79,4 +82,3 @@ if __name__ == "__main__":
print("Usage: paren <expression>") print("Usage: paren <expression>")
else: else:
print('error') print('error')