diff --git a/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java b/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java index 522c70575b82..5d9f5e95ea24 100644 --- a/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java +++ b/platform/lang-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java @@ -620,8 +620,17 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { @Nullable @Override public IElementType lookAhead(int steps) { - if (steps + myCurrentLexeme >= myLexemeCount) return null; - return myLexTypes[myCurrentLexeme + steps]; + int cur = myCurrentLexeme; + + while (steps > 0) { + while (cur < myLexemeCount && whitespaceOrComment(myLexTypes[cur])) { + cur++; + } + + steps--; + } + + return cur < myLexemeCount ? myLexTypes[cur] : null; } @Override