Assign trailing and preceding whitespaces to lambda block until the last comment in parser

This commit is contained in:
Nikolay Krasko
2016-10-25 18:04:18 +03:00
parent 0261385681
commit 08d628537c
16 changed files with 523 additions and 66 deletions
+38
View File
@@ -0,0 +1,38 @@
val la1 = {
// start
// start 1
foo()
// middle
foo()
// end
}
val la2 = {
/**/
}
val la3 = {
/** */
}
val la4 = {
/** Should be under block */
/** Should be under property */
val some = 1
}
val la5 = {
/** */
/** */
}
val la6 = /*1*/ {/*2*/ a /*3*/ -> /*4*/
}
val la7 = {/**/}
fun foo() {}
+191
View File
@@ -0,0 +1,191 @@
JetFile: CommentsBindingInLambda.kt
PACKAGE_DIRECTIVE
<empty list>
IMPORT_LIST
<empty list>
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('la1')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
LAMBDA_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BLOCK
PsiComment(EOL_COMMENT)('// start')
PsiWhiteSpace('\n ')
PsiComment(EOL_COMMENT)('// start 1')
PsiWhiteSpace('\n ')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
PsiComment(EOL_COMMENT)('// middle')
PsiWhiteSpace('\n\n ')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
PsiComment(EOL_COMMENT)('// end')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('la2')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
LAMBDA_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BLOCK
PsiComment(BLOCK_COMMENT)('/**/')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('la3')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
LAMBDA_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BLOCK
KDoc
PsiElement(KDOC_START)('/**')
KDOC_SECTION
PsiElement(KDOC_TEXT)(' ')
PsiElement(KDOC_END)('*/')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('la4')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
LAMBDA_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BLOCK
KDoc
PsiElement(KDOC_START)('/**')
KDOC_SECTION
PsiElement(KDOC_TEXT)(' Should be under block ')
PsiElement(KDOC_END)('*/')
PsiWhiteSpace('\n\n ')
PROPERTY
KDoc
PsiElement(KDOC_START)('/**')
KDOC_SECTION
PsiElement(KDOC_TEXT)(' Should be under property ')
PsiElement(KDOC_END)('*/')
PsiWhiteSpace('\n ')
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('some')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('la5')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
LAMBDA_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BLOCK
KDoc
PsiElement(KDOC_START)('/**')
KDOC_SECTION
PsiElement(KDOC_TEXT)(' ')
PsiElement(KDOC_END)('*/')
PsiWhiteSpace('\n ')
KDoc
PsiElement(KDOC_START)('/**')
KDOC_SECTION
PsiElement(KDOC_TEXT)(' ')
PsiElement(KDOC_END)('*/')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('la6')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
PsiComment(BLOCK_COMMENT)('/*1*/')
PsiWhiteSpace(' ')
LAMBDA_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiComment(BLOCK_COMMENT)('/*2*/')
PsiWhiteSpace(' ')
VALUE_PARAMETER_LIST
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiComment(BLOCK_COMMENT)('/*3*/')
PsiWhiteSpace(' ')
PsiElement(ARROW)('->')
PsiWhiteSpace(' ')
BLOCK
PsiComment(BLOCK_COMMENT)('/*4*/')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('la7')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
LAMBDA_EXPRESSION
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BLOCK
PsiComment(BLOCK_COMMENT)('/**/')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('foo')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiElement(RBRACE)('}')
@@ -0,0 +1,21 @@
fun test() {
if (true) {/*start-end*/}
if (true) {
/*start-end*/
}
if (true) {
/*start*/
/*end*/
}
if (true) {
/*start*/
/** doc */
val a = 12
/*end*/
}
}
@@ -0,0 +1,103 @@
JetFile: CommentsBindingInStatementBlock.kt
PACKAGE_DIRECTIVE
<empty list>
IMPORT_LIST
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
IF
PsiElement(if)('if')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
BOOLEAN_CONSTANT
PsiElement(true)('true')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
THEN
BLOCK
PsiElement(LBRACE)('{')
PsiComment(BLOCK_COMMENT)('/*start-end*/')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
IF
PsiElement(if)('if')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
BOOLEAN_CONSTANT
PsiElement(true)('true')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
THEN
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PsiComment(BLOCK_COMMENT)('/*start-end*/')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
IF
PsiElement(if)('if')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
BOOLEAN_CONSTANT
PsiElement(true)('true')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
THEN
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PsiComment(BLOCK_COMMENT)('/*start*/')
PsiWhiteSpace('\n ')
PsiComment(BLOCK_COMMENT)('/*end*/')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
IF
PsiElement(if)('if')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
BOOLEAN_CONSTANT
PsiElement(true)('true')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
THEN
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PsiComment(BLOCK_COMMENT)('/*start*/')
PsiWhiteSpace('\n\n ')
PROPERTY
KDoc
PsiElement(KDOC_START)('/**')
KDOC_SECTION
PsiElement(KDOC_TEXT)(' doc ')
PsiElement(KDOC_END)('*/')
PsiWhiteSpace('\n ')
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('12')
PsiWhiteSpace('\n\n ')
PsiComment(BLOCK_COMMENT)('/*end*/')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
+12
View File
@@ -0,0 +1,12 @@
fun test() {
// start
foo()
// middle
foo()
// end
}
fun foo() {}
+49
View File
@@ -0,0 +1,49 @@
JetFile: LineCommentsInBlock.kt
PACKAGE_DIRECTIVE
<empty list>
IMPORT_LIST
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PsiComment(EOL_COMMENT)('// start')
PsiWhiteSpace('\n ')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
PsiComment(EOL_COMMENT)('// middle')
PsiWhiteSpace('\n\n ')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
PsiComment(EOL_COMMENT)('// end')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('foo')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiElement(RBRACE)('}')
+2 -2
View File
@@ -61,9 +61,9 @@ JetFile: lambda.kt
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
PsiComment(EOL_COMMENT)('// parsed as array access')
PsiWhiteSpace('\n ')
BLOCK
PsiComment(EOL_COMMENT)('// parsed as array access')
PsiWhiteSpace('\n ')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('print')
+6 -6
View File
@@ -33,9 +33,9 @@ JetFile: recovery.kt
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
PsiComment(EOL_COMMENT)('// should be no space after c')
PsiWhiteSpace('\n ')
BLOCK
PsiComment(EOL_COMMENT)('// should be no space after c')
PsiWhiteSpace('\n ')
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
@@ -61,9 +61,9 @@ JetFile: recovery.kt
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
PsiComment(EOL_COMMENT)('// no label identifier')
PsiWhiteSpace('\n ')
BLOCK
PsiComment(EOL_COMMENT)('// no label identifier')
PsiWhiteSpace('\n ')
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
@@ -94,9 +94,9 @@ JetFile: recovery.kt
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
PsiComment(EOL_COMMENT)('// should be no space after loop2')
PsiWhiteSpace('\n ')
BLOCK
PsiComment(EOL_COMMENT)('// should be no space after loop2')
PsiWhiteSpace('\n ')
RETURN
PsiElement(return)('return')
PsiErrorElement:Label must be named