Skip to content

Commit

Permalink
Address labels in AST pretty printing
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed May 1, 2024
1 parent 01df92b commit 70702af
Showing 1 changed file with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -731,22 +731,48 @@ public void visit( BoxAssert node ) {

public void visit( BoxBreak node ) {
if ( isTemplate() ) {
print( "<bx:break>" );
print( "<bx:break" );
if ( node.getLabel() != null ) {
print( " label=\"" );
print( node.getLabel() );
print( "\"" );
}
print( ">" );
} else {
print( "break;" );
print( "break" );
if ( node.getLabel() != null ) {
print( " " );
print( node.getLabel() );
}
print( ";" );
}
}

public void visit( BoxContinue node ) {
if ( isTemplate() ) {
print( "<bx:continue>" );
print( "<bx:continue" );
if ( node.getLabel() != null ) {
print( " label=\"" );
print( node.getLabel() );
print( "\"" );
}
print( ">" );
} else {
print( "continue;" );
print( "continue" );
if ( node.getLabel() != null ) {
print( " " );
print( node.getLabel() );
}
print( ";" );
}
}

public void visit( BoxDo node ) {
// No template version of this
if ( node.getLabel() != null ) {
print( node.getLabel() );
print( ": " );
}
print( "do {" );
newLine();
for ( var statement : node.getBody() ) {
Expand Down Expand Up @@ -779,6 +805,10 @@ public void visit( BoxExpressionStatement node ) {
}

public void visit( BoxForIn node ) {
if ( node.getLabel() != null ) {
print( node.getLabel() );
print( ": " );
}
print( "for( " );
if ( node.getHasVar() ) {
print( "var " );
Expand All @@ -798,6 +828,10 @@ public void visit( BoxForIn node ) {
}

public void visit( BoxForIndex node ) {
if ( node.getLabel() != null ) {
print( node.getLabel() );
print( ": " );
}
print( "for( " );
if ( node.getInitializer() != null ) {
node.getInitializer().accept( this );
Expand Down Expand Up @@ -1264,14 +1298,24 @@ public void visit( BoxWhile node ) {
if ( isTemplate() ) {
print( "<bx:while condition=\"" );
doQuotedExpression( node.getCondition() );
print( "\">" );
print( "\"" );
if ( node.getLabel() != null ) {
print( " label=\"" );
print( node.getLabel() );
print( "\"" );
}
print( ">" );
increaseIndent();
for ( var statement : node.getBody() ) {
statement.accept( this );
}
decreaseIndent();
print( "</bx:while>" );
} else {
if ( node.getLabel() != null ) {
print( node.getLabel() );
print( ": " );
}
print( "while (" );
node.getCondition().accept( this );
increaseIndent();
Expand Down

0 comments on commit 70702af

Please sign in to comment.