Skip to content

Commit

Permalink
Corrigir bugs no PrettyPrinter e aumentar alcance do PrettyPrinter
Browse files Browse the repository at this point in the history
  • Loading branch information
erickolisveira committed Apr 27, 2020
1 parent ba01afc commit ba690ab
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/ExpressionLanguageParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,16 +690,21 @@ def p_error(p):
lex.lex()
arquivo = '''
<?php
function add() {
while(true) {
return 1;
}
}
function add() {
while($i <= $j){
while($array[$i] < $x && $i < $fim){
$i = $i + 1;
}
while(($array[$j] > $x) && ($j > $inicio)){
$j = $j - 1;
}
}
}
?>
'''

lex.input(arquivo)
parser = yacc.yacc()
result = parser.parse(debug=True)
result = parser.parse(debug=False)
v = vis.Visitor()
result.accept(v)
17 changes: 12 additions & 5 deletions src/Visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Visitor():
def visitMain_MainInner(self, main):
print('<?php')
pp.incrementTab()
pp.printTab()
main.mainInner.accept(self)
print('?>')

Expand Down Expand Up @@ -34,6 +33,7 @@ def visitInnerStatementMul_Single(self, innerStatementMul):
innerStatementMul.innerStatement.accept(self)

def visitFuncDecStatement_Function(self, funcDecStatement):
pp.printTab()
print('function', end=' ')
funcDecStatement.fds_id.accept(self)
funcDecStatement.fds_parameter.accept(self)
Expand Down Expand Up @@ -65,6 +65,7 @@ def visitFds_statements_withStatements(self, fds_statements):

def visitFds_statements_noStatements(self, fds_statements):
print('{')
pp.printTab()
print('}')

def visitParameterList_Parameter_Mul(self, parameterList):
Expand Down Expand Up @@ -158,6 +159,7 @@ def visitStatement_While(self, statement):
statement.whilee.accept(self)

def visitStatement_Do_While(self, statement):
pp.printTab()
statement.dowhilee.accept(self)
print(';')

Expand Down Expand Up @@ -453,13 +455,17 @@ def visitStatementBlockOpt_Statement(self, statementblockopt):
statementblockopt.statement.accept(self)

def visitStatementBlockOpt_StatementMul(self, statementblockopt):
print('{', end='')
print('{')
pp.incrementTab()
statementblockopt.statementmul.accept(self)
print('}', end='')
pp.decrementTab()
pp.printTab()
print('}')

def visitStatementBlockOpt_Empty(self, statementblockopt):
print('{', end='')
print('}', end='')
print('{')
pp.printTab()
print('}')

def visitstatementMulSingle(self, statementMul):
statementMul.statement.accept(self)
Expand All @@ -471,5 +477,6 @@ def visitstatementMulMul(self, statementMul):
def visitDoWhileStatementSingle(self, whilestatement):
print('do', end='')
whilestatement.statementblockopt.accept(self)
pp.printTab()
print('while', end='')
whilestatement.exprparentheses.accept(self)
Binary file modified src/__pycache__/SintaxeAbstrata.cpython-37.pyc
Binary file not shown.
Binary file modified src/__pycache__/Visitor.cpython-37.pyc
Binary file not shown.
Binary file modified src/__pycache__/parsetab.cpython-37.pyc
Binary file not shown.

0 comments on commit ba690ab

Please sign in to comment.