Skip to content

Commit

Permalink
Clean up raw block closing
Browse files Browse the repository at this point in the history
Letting the raw block know how to close its BLOCK_WRAPPER is better than
hijacking parseProgramInverseProgramClose for something that has nothing
to do with parseing program/inverseProgram/close
  • Loading branch information
dmarcotte committed Apr 22, 2015
1 parent 7997c95 commit d7b250f
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions handlebars/src/com/dmarcotte/handlebars/parsing/HbParsing.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private boolean parseStatement(PsiBuilder builder) {

PsiBuilder.Marker blockMarker = builder.mark();
if (parseOpenInverse(builder)) {
parseProgramInverseProgramClose(builder, blockMarker, false);
parseProgramInverseProgramClose(builder, blockMarker);
}
else {
return false;
Expand All @@ -165,7 +165,7 @@ private boolean parseStatement(PsiBuilder builder) {
if (tokenType == OPEN_BLOCK) {
PsiBuilder.Marker blockMarker = builder.mark();
if (parseOpenBlock(builder)) {
parseProgramInverseProgramClose(builder, blockMarker, false);
parseProgramInverseProgramClose(builder, blockMarker);
}
else {
return false;
Expand Down Expand Up @@ -200,7 +200,11 @@ private boolean parseStatement(PsiBuilder builder) {
if (tokenType == OPEN_RAW_BLOCK) {
PsiBuilder.Marker blockMarker = builder.mark();
if (parseOpenRawBlock(builder)) {
parseProgramInverseProgramClose(builder, blockMarker, true);
if (builder.getTokenType() == CONTENT) {
builder.advanceLexer(); // eat non-HB content
}
parseCloseRawBlock(builder);
blockMarker.done(HbTokenTypes.BLOCK_WRAPPER);
}
else {
return false;
Expand Down Expand Up @@ -241,27 +245,20 @@ private boolean parseStatement(PsiBuilder builder) {
}

/**
* Helper method to take care of the business needed after an "open-type mustache" (openBlock, openRawBlock or openInverse)
* Helper method to take care of the business needed after an "open-type mustache" (openBlock or openInverse)
*
* Effective acts as the `program inverseAndProgram? closeBlock` part of the grammar
*
* <p/>
* NOTE: will resolve the given blockMarker
*/
private void parseProgramInverseProgramClose(PsiBuilder builder, PsiBuilder.Marker blockMarker, boolean raw) {
if (raw) {
if (builder.getTokenType() == CONTENT) {
builder.advanceLexer(); // eat non-HB content
}
parseCloseRawBlock(builder);
} else {
parseProgram(builder);
if (parseSimpleInverse(builder)) {
// if we have a simple inverse, must have more statements
parseStatements(builder);
}
parseCloseBlock(builder);
private void parseProgramInverseProgramClose(PsiBuilder builder, PsiBuilder.Marker blockMarker) {
parseProgram(builder);
if (parseSimpleInverse(builder)) {
// if we have a simple inverse, must have more statements
parseStatements(builder);
}
parseCloseBlock(builder);
blockMarker.done(HbTokenTypes.BLOCK_WRAPPER);
}

Expand Down

0 comments on commit d7b250f

Please sign in to comment.