Skip to content

Commit

Permalink
Fixed issue kumaraman21#20- when starting a scenario with an "And" st…
Browse files Browse the repository at this point in the history
…ep, there is no previous step and the StoryParser is not able to set the step type. => set the first type to "GIVEN"
  • Loading branch information
AndreeaCh committed Jul 14, 2013
1 parent feacd1c commit f092f1f
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 96 deletions.
190 changes: 95 additions & 95 deletions src/com/github/kumaraman21/intellijbehave/parser/StoryParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,114 +25,114 @@
import static com.github.kumaraman21.intellijbehave.utility.StepTypeMappings.STEP_TEXT_TO_STORY_ELEMENT_TYPE_MAPPING;

public class StoryParser implements PsiParser {
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
final PsiBuilder.Marker rootMarker = builder.mark();

parseStory(builder);

rootMarker.done(root);
return builder.getTreeBuilt();
}

private void parseStory(PsiBuilder builder) {
final PsiBuilder.Marker storyMarker = builder.mark();
parseStoryDescriptionLinesIfPresent(builder);
parseScenarios(builder);
storyMarker.done(StoryElementType.STORY);
}

private void parseStoryDescriptionLinesIfPresent(PsiBuilder builder) {
if(builder.getTokenType() == StoryTokenType.STORY_DESCRIPTION) {
while(builder.getTokenType() == StoryTokenType.STORY_DESCRIPTION) {
parseStoryDescriptionLine(builder);
}
}
}

private void parseStoryDescriptionLine(PsiBuilder builder) {
builder.advanceLexer();
}

private void parseScenarios(PsiBuilder builder) {
if(builder.getTokenType() == StoryTokenType.SCENARIO_TEXT) {
while(builder.getTokenType() == StoryTokenType.SCENARIO_TEXT) {
parseScenario(builder);
}
}
else {
builder.advanceLexer();
builder.error("Scenario expected");
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
final PsiBuilder.Marker rootMarker = builder.mark();

parseStory(builder);

rootMarker.done(root);
return builder.getTreeBuilt();
}
}

private void parseScenario(PsiBuilder builder) {
final PsiBuilder.Marker stepMarker = builder.mark();
builder.advanceLexer();
parseSteps(builder);
parseStoryDescriptionLinesIfPresent(builder);
stepMarker.done(StoryElementType.SCENARIO);
}

private void parseSteps(PsiBuilder builder) {
parseStoryDescriptionLinesIfPresent(builder);
if(builder.getTokenType() == StoryTokenType.STEP_TYPE) {

StoryElementType previousStepElementType = null;
while(builder.getTokenType() == StoryTokenType.STEP_TYPE) {
previousStepElementType = parseStep(builder, previousStepElementType);

private void parseStory(PsiBuilder builder) {
final PsiBuilder.Marker storyMarker = builder.mark();
parseStoryDescriptionLinesIfPresent(builder);
}
parseScenarios(builder);
storyMarker.done(StoryElementType.STORY);
}
else {
builder.error("At least one step expected");

private void parseStoryDescriptionLinesIfPresent(PsiBuilder builder) {
if (builder.getTokenType() == StoryTokenType.STORY_DESCRIPTION) {
while (builder.getTokenType() == StoryTokenType.STORY_DESCRIPTION) {
parseStoryDescriptionLine(builder);
}
}
}
}

private StoryElementType parseStep(PsiBuilder builder, StoryElementType previousStepElementType) {
final PsiBuilder.Marker stepMarker = builder.mark();
private void parseStoryDescriptionLine(PsiBuilder builder) {
builder.advanceLexer();
}

StoryElementType currentStepElementType;
private void parseScenarios(PsiBuilder builder) {
if (builder.getTokenType() == StoryTokenType.SCENARIO_TEXT) {
while (builder.getTokenType() == StoryTokenType.SCENARIO_TEXT) {
parseScenario(builder);
}
} else {
builder.advanceLexer();
builder.error("Scenario expected");
}
}

String stepTypeText = builder.getTokenText().trim().toUpperCase();
if(stepTypeText.equalsIgnoreCase("And")) {
currentStepElementType = previousStepElementType;
private void parseScenario(PsiBuilder builder) {
final PsiBuilder.Marker stepMarker = builder.mark();
builder.advanceLexer();
parseSteps(builder);
parseStoryDescriptionLinesIfPresent(builder);
stepMarker.done(StoryElementType.SCENARIO);
}
else {
currentStepElementType = STEP_TEXT_TO_STORY_ELEMENT_TYPE_MAPPING.get(stepTypeText);

private void parseSteps(PsiBuilder builder) {
parseStoryDescriptionLinesIfPresent(builder);
if (builder.getTokenType() == StoryTokenType.STEP_TYPE) {

StoryElementType previousStepElementType = null;
while (builder.getTokenType() == StoryTokenType.STEP_TYPE) {
previousStepElementType = parseStep(builder, previousStepElementType);
parseStoryDescriptionLinesIfPresent(builder);
}
} else {
builder.error("At least one step expected");
}
}

parseStepType(builder);
parseStepText(builder);
parseTableIfPresent(builder);
stepMarker.done(currentStepElementType);
private StoryElementType parseStep(PsiBuilder builder, StoryElementType previousStepElementType) {
final PsiBuilder.Marker stepMarker = builder.mark();

StoryElementType currentStepElementType;

return currentStepElementType;
}
String stepTypeText = builder.getTokenText().trim().toUpperCase();
if (stepTypeText.equalsIgnoreCase("And")) {
if (previousStepElementType != null) {
currentStepElementType = previousStepElementType;
} else { //If there is no previous step, set the first step type to "GIVEN".
currentStepElementType = STEP_TEXT_TO_STORY_ELEMENT_TYPE_MAPPING.get("GIVEN");
}
} else {
currentStepElementType = STEP_TEXT_TO_STORY_ELEMENT_TYPE_MAPPING.get(stepTypeText);
}

private void parseStepType(PsiBuilder builder) {
builder.advanceLexer();
}
parseStepType(builder);
parseStepText(builder);
parseTableIfPresent(builder);
stepMarker.done(currentStepElementType);

private void parseStepText(PsiBuilder builder) {
if(builder.getTokenType() == StoryTokenType.STEP_TEXT) {
builder.advanceLexer();
return currentStepElementType;
}
else {
builder.error("Step text expected");

private void parseStepType(PsiBuilder builder) {
builder.advanceLexer();
}

private void parseStepText(PsiBuilder builder) {
if (builder.getTokenType() == StoryTokenType.STEP_TEXT) {
builder.advanceLexer();
} else {
builder.error("Step text expected");
}
}

private void parseTableIfPresent(PsiBuilder builder) {
if (builder.getTokenType() == StoryTokenType.TABLE_ROW) {
while (builder.getTokenType() == StoryTokenType.TABLE_ROW) {
parseTableRow(builder);
}
}
}

private void parseTableRow(PsiBuilder builder) {
builder.advanceLexer();
}
}

private void parseTableIfPresent(PsiBuilder builder) {
if(builder.getTokenType() == StoryTokenType.TABLE_ROW) {
while(builder.getTokenType() == StoryTokenType.TABLE_ROW) {
parseTableRow(builder);
}
}
}

private void parseTableRow(PsiBuilder builder) {
builder.advanceLexer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public String getDisplayName() {
return "JBehave";
}

@Override
//@Override
public Icon getIcon() {
return null;
}
Expand Down

0 comments on commit f092f1f

Please sign in to comment.