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.lang.PsiBuilder;
|
||||||
import com.intellij.psi.TokenType;
|
import com.intellij.psi.TokenType;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
@@ -22,14 +23,23 @@ public class SemanticWhitespaceAwarePsiBuilderImpl extends PsiBuilderAdapter imp
|
|||||||
public boolean eolInLastWhitespace() {
|
public boolean eolInLastWhitespace() {
|
||||||
if (!eolsEnabled.peek()) return false;
|
if (!eolsEnabled.peek()) return false;
|
||||||
if (eof()) return true;
|
if (eof()) return true;
|
||||||
IElementType previousToken = rawLookup(-1);
|
// TODO: maybe, memoize this somehow?
|
||||||
if (previousToken == TokenType.WHITE_SPACE) {
|
for (int i = 1; i <= getCurrentOffset(); i++) {
|
||||||
int previousTokenStart = rawTokenTypeStart(-1);
|
IElementType previousToken = rawLookup(-i);
|
||||||
int previousTokenEnd = rawTokenTypeStart(0);
|
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 previousTokenStart >= 0;
|
||||||
assert previousTokenEnd < getOriginalText().length();
|
assert previousTokenEnd < getOriginalText().length();
|
||||||
for (int i = previousTokenStart; i < previousTokenEnd; i++) {
|
for (int j = previousTokenStart; j < previousTokenEnd; j++) {
|
||||||
if (getOriginalText().charAt(i) == '\n') return true;
|
if (getOriginalText().charAt(j) == '\n') return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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 testDecomposers_ERR() throws Exception {doTest(true);}
|
||||||
public void testEmptyFile() throws Exception {doTest(true);}
|
public void testEmptyFile() throws Exception {doTest(true);}
|
||||||
public void testEnums() 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 testEOLsOnRollback() throws Exception {doTest(true);}
|
||||||
public void testExtensions() throws Exception {doTest(true);}
|
public void testExtensions() throws Exception {doTest(true);}
|
||||||
public void testExtensions_ERR() throws Exception {doTest(true);}
|
public void testExtensions_ERR() throws Exception {doTest(true);}
|
||||||
|
|||||||
Reference in New Issue
Block a user