Skip to content

Commit

Permalink
Merge pull request #4 from luizmoitinho/erick
Browse files Browse the repository at this point in the history
Iniciar desenvolvimento do PrettyPrinter
  • Loading branch information
erickolisveira authored Apr 27, 2020
2 parents 8f4a81d + 780efda commit ba01afc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/ExpressionLanguageParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,13 +690,11 @@ def p_error(p):
lex.lex()
arquivo = '''
<?php
do
{
while(1+1){
$valor = $valor2;
function add() {
while(true) {
return 1;
}
}while($a = 2);
}
?>
'''

Expand Down
18 changes: 18 additions & 0 deletions src/PrettyPrinter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
spaces = ' '
space_buffer = ''

class PrettyPrinter():

def incrementTab():
global spaces
global space_buffer
space_buffer = space_buffer + spaces


def printTab():
global space_buffer
print(space_buffer, end='')

def decrementTab():
global space_buffer
space_buffer = space_buffer[:-len(spaces)]
14 changes: 14 additions & 0 deletions src/Visitor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from PrettyPrinter import PrettyPrinter as pp

class Visitor():

def visitMain_MainInner(self, main):
print('<?php')
pp.incrementTab()
pp.printTab()
main.mainInner.accept(self)
print('?>')

Expand Down Expand Up @@ -53,7 +57,10 @@ def visitFds_parameter_noParameter(self, fds_parameter):

def visitFds_statements_withStatements(self, fds_statements):
print('{')
pp.incrementTab()
fds_statements.inner_statement_MUL.accept(self)
pp.decrementTab()
pp.printTab()
print('}')

def visitFds_statements_noStatements(self, fds_statements):
Expand Down Expand Up @@ -125,23 +132,29 @@ def visitScalar_Token(self, scalar):
print(scalar.token, end='')

def visitStatement_Expr(self, statement):
pp.printTab()
statement.expr.accept(self)
print(';')

def visitStatement_Break(self, statement):
pp.printTab()
statement._break.accept(self)

def visitStatement_Continue(self, statement):
pp.printTab()
statement._continue.accept(self)

def visitStatement_Return(self, statement):
pp.printTab()
statement._return.accept(self)

def visitStatement_Exit(self, statement):
pp.printTab()
statement.exit.accept(self)
print(';')

def visitStatement_While(self, statement):
pp.printTab()
statement.whilee.accept(self)

def visitStatement_Do_While(self, statement):
Expand All @@ -150,6 +163,7 @@ def visitStatement_Do_While(self, statement):


def visitStatement_Die(self, statement):
pp.printTab()
statement.die.accept(self)
print(';')

Expand Down
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.

0 comments on commit ba01afc

Please sign in to comment.