EOLs are treated properly in the presence of comments and multiple whitespace tokens
This commit is contained in:
@@ -4,6 +4,7 @@ package org.jetbrains.jet.lang.parsing;
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
@@ -22,14 +23,23 @@ public class SemanticWhitespaceAwarePsiBuilderImpl extends PsiBuilderAdapter imp
|
||||
public boolean eolInLastWhitespace() {
|
||||
if (!eolsEnabled.peek()) return false;
|
||||
if (eof()) return true;
|
||||
IElementType previousToken = rawLookup(-1);
|
||||
if (previousToken == TokenType.WHITE_SPACE) {
|
||||
int previousTokenStart = rawTokenTypeStart(-1);
|
||||
int previousTokenEnd = rawTokenTypeStart(0);
|
||||
// TODO: maybe, memoize this somehow?
|
||||
for (int i = 1; i <= getCurrentOffset(); i++) {
|
||||
IElementType previousToken = rawLookup(-i);
|
||||
if (previousToken == JetTokens.BLOCK_COMMENT
|
||||
|| previousToken == JetTokens.DOC_COMMENT
|
||||
|| previousToken == JetTokens.EOL_COMMENT) {
|
||||
continue;
|
||||
}
|
||||
if (previousToken != TokenType.WHITE_SPACE) {
|
||||
break;
|
||||
}
|
||||
int previousTokenStart = rawTokenTypeStart(-i);
|
||||
int previousTokenEnd = rawTokenTypeStart(-i + 1);
|
||||
assert previousTokenStart >= 0;
|
||||
assert previousTokenEnd < getOriginalText().length();
|
||||
for (int i = previousTokenStart; i < previousTokenEnd; i++) {
|
||||
if (getOriginalText().charAt(i) == '\n') return true;
|
||||
for (int j = previousTokenStart; j < previousTokenEnd; j++) {
|
||||
if (getOriginalText().charAt(j) == '\n') return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
fun foo() {
|
||||
a
|
||||
+ b
|
||||
a
|
||||
/** */+ b
|
||||
a
|
||||
/* */+ b
|
||||
a /*
|
||||
*/ + b
|
||||
a
|
||||
/*
|
||||
*/ + b
|
||||
a /**
|
||||
*/ + b
|
||||
a //
|
||||
+ b
|
||||
a //
|
||||
+ b
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
JetFile: EOLsInComments.jet
|
||||
NAMESPACE
|
||||
FUN
|
||||
PsiElement(fun)('fun')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
TYPE_PARAMETER_LIST
|
||||
<empty list>
|
||||
VALUE_PARAMETER_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace(' ')
|
||||
BLOCK
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace('\n ')
|
||||
PREFIX_EXPRESSION
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiComment(DOC_COMMENT)('/** */')
|
||||
PREFIX_EXPRESSION
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiComment(BLOCK_COMMENT)('/* */')
|
||||
PREFIX_EXPRESSION
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n ')
|
||||
BINARY_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiComment(BLOCK_COMMENT)('/*\n */')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiComment(BLOCK_COMMENT)('/*\n */')
|
||||
PsiWhiteSpace(' ')
|
||||
PREFIX_EXPRESSION
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n ')
|
||||
BINARY_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiComment(DOC_COMMENT)('/**\n */')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiComment(EOL_COMMENT)('//')
|
||||
PsiWhiteSpace('\n ')
|
||||
PREFIX_EXPRESSION
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiComment(EOL_COMMENT)('//')
|
||||
PsiWhiteSpace('\n')
|
||||
PREFIX_EXPRESSION
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(RBRACE)('}')
|
||||
@@ -38,6 +38,7 @@ public class JetParsingTest extends ParsingTestCase {
|
||||
public void testDecomposers_ERR() throws Exception {doTest(true);}
|
||||
public void testEmptyFile() throws Exception {doTest(true);}
|
||||
public void testEnums() throws Exception {doTest(true);}
|
||||
public void testEOLsInComments() throws Exception {doTest(true);}
|
||||
public void testEOLsOnRollback() throws Exception {doTest(true);}
|
||||
public void testExtensions() throws Exception {doTest(true);}
|
||||
public void testExtensions_ERR() throws Exception {doTest(true);}
|
||||
|
||||
Reference in New Issue
Block a user