Support !!foo as a double-negation
This commit is contained in:
@@ -64,7 +64,9 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
|
|
||||||
/*package*/ static final TokenSet EXPRESSION_FIRST = TokenSet.create(
|
/*package*/ static final TokenSet EXPRESSION_FIRST = TokenSet.create(
|
||||||
// Prefix
|
// Prefix
|
||||||
MINUS, PLUS, MINUSMINUS, PLUSPLUS, EXCL, LBRACKET, LABEL_IDENTIFIER, AT, ATAT,
|
MINUS, PLUS, MINUSMINUS, PLUSPLUS,
|
||||||
|
EXCL, EXCLEXCL, // Joining complex tokens makes it necessary to put EXCLEXCL here
|
||||||
|
LBRACKET, LABEL_IDENTIFIER, AT, ATAT,
|
||||||
// Atomic
|
// Atomic
|
||||||
|
|
||||||
LPAR, // parenthesized
|
LPAR, // parenthesized
|
||||||
@@ -325,24 +327,34 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
*/
|
*/
|
||||||
private void parsePrefixExpression() {
|
private void parsePrefixExpression() {
|
||||||
// System.out.println("pre at " + myBuilder.getTokenText());
|
// System.out.println("pre at " + myBuilder.getTokenText());
|
||||||
|
|
||||||
if (at(LBRACKET)) {
|
if (at(LBRACKET)) {
|
||||||
if (!parseLocalDeclaration()) {
|
if (!parseLocalDeclaration()) {
|
||||||
PsiBuilder.Marker expression = mark();
|
PsiBuilder.Marker expression = mark();
|
||||||
myJetParsing.parseAnnotations(false);
|
myJetParsing.parseAnnotations(false);
|
||||||
parsePrefixExpression();
|
parsePrefixExpression();
|
||||||
expression.done(ANNOTATED_EXPRESSION);
|
expression.done(ANNOTATED_EXPRESSION);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (atSet(Precedence.PREFIX.getOperations())) {
|
}
|
||||||
PsiBuilder.Marker expression = mark();
|
else {
|
||||||
|
myBuilder.disableJoiningComplexTokens();
|
||||||
|
if (atSet(Precedence.PREFIX.getOperations())) {
|
||||||
|
PsiBuilder.Marker expression = mark();
|
||||||
|
|
||||||
parseOperationReference();
|
parseOperationReference();
|
||||||
|
|
||||||
parsePrefixExpression();
|
myBuilder.restoreJoiningComplexTokensState();
|
||||||
expression.done(PREFIX_EXPRESSION);
|
|
||||||
} else {
|
parsePrefixExpression();
|
||||||
parsePostfixExpression();
|
expression.done(PREFIX_EXPRESSION);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
myBuilder.restoreJoiningComplexTokensState();
|
||||||
|
parsePostfixExpression();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -32,7 +32,7 @@ import static org.jetbrains.jet.lexer.JetTokens.*;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class SemanticWhitespaceAwarePsiBuilderImpl extends PsiBuilderAdapter implements SemanticWhitespaceAwarePsiBuilder {
|
public class SemanticWhitespaceAwarePsiBuilderImpl extends PsiBuilderAdapter implements SemanticWhitespaceAwarePsiBuilder {
|
||||||
private final TokenSet complexTokens = TokenSet.create(SAFE_ACCESS, ELVIS);
|
private final TokenSet complexTokens = TokenSet.create(SAFE_ACCESS, ELVIS, EXCLEXCL);
|
||||||
private final Stack<Boolean> joinComplexTokens = new Stack<Boolean>();
|
private final Stack<Boolean> joinComplexTokens = new Stack<Boolean>();
|
||||||
|
|
||||||
private final Stack<Boolean> newlinesEnabled = new Stack<Boolean>();
|
private final Stack<Boolean> newlinesEnabled = new Stack<Boolean>();
|
||||||
@@ -126,6 +126,10 @@ public class SemanticWhitespaceAwarePsiBuilderImpl extends PsiBuilderAdapter imp
|
|||||||
if (nextRawToken == DOT) return SAFE_ACCESS;
|
if (nextRawToken == DOT) return SAFE_ACCESS;
|
||||||
if (nextRawToken == COLON) return ELVIS;
|
if (nextRawToken == COLON) return ELVIS;
|
||||||
}
|
}
|
||||||
|
else if (rawTokenType == EXCL) {
|
||||||
|
IElementType nextRawToken = rawLookup(rawLookupSteps);
|
||||||
|
if (nextRawToken == EXCL) return EXCLEXCL;
|
||||||
|
}
|
||||||
return rawTokenType;
|
return rawTokenType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ LONG_TEMPLATE_ENTRY_END=\}
|
|||||||
">=" { return JetTokens.GTEQ ; }
|
">=" { return JetTokens.GTEQ ; }
|
||||||
"==" { return JetTokens.EQEQ ; }
|
"==" { return JetTokens.EQEQ ; }
|
||||||
"!=" { return JetTokens.EXCLEQ ; }
|
"!=" { return JetTokens.EXCLEQ ; }
|
||||||
"!!" { return JetTokens.EXCLEXCL ; }
|
//"!!" { return JetTokens.EXCLEXCL ; }
|
||||||
"&&" { return JetTokens.ANDAND ; }
|
"&&" { return JetTokens.ANDAND ; }
|
||||||
"||" { return JetTokens.OROR ; }
|
"||" { return JetTokens.OROR ; }
|
||||||
//"?." { return JetTokens.SAFE_ACCESS;}
|
//"?." { return JetTokens.SAFE_ACCESS;}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
|||||||
|
fun main(args : Array<String>) {
|
||||||
|
!true;
|
||||||
|
!!true;
|
||||||
|
!!!true;
|
||||||
|
!!!!true;
|
||||||
|
true!!!
|
||||||
|
true!!!!
|
||||||
|
true!!and(false)
|
||||||
|
true!!.and(false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
JetFile: AssertNotNull.jet
|
||||||
|
NAMESPACE_HEADER
|
||||||
|
<empty list>
|
||||||
|
FUN
|
||||||
|
PsiElement(fun)('fun')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('main')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('args')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('Array')
|
||||||
|
TYPE_ARGUMENT_LIST
|
||||||
|
PsiElement(LT)('<')
|
||||||
|
TYPE_PROJECTION
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('String')
|
||||||
|
PsiElement(GT)('>')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(true)('true')
|
||||||
|
PsiElement(SEMICOLON)(';')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(true)('true')
|
||||||
|
PsiElement(SEMICOLON)(';')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(true)('true')
|
||||||
|
PsiElement(SEMICOLON)(';')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
PREFIX_EXPRESSION
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(true)('true')
|
||||||
|
PsiElement(SEMICOLON)(';')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
POSTFIX_EXPRESSION
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(true)('true')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCLEXCL)('!!')
|
||||||
|
PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line)
|
||||||
|
PsiElement(EXCL)('!')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
POSTFIX_EXPRESSION
|
||||||
|
POSTFIX_EXPRESSION
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(true)('true')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCLEXCL)('!!')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCLEXCL)('!!')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
BINARY_EXPRESSION
|
||||||
|
POSTFIX_EXPRESSION
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(true)('true')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCLEXCL)('!!')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(IDENTIFIER)('and')
|
||||||
|
PARENTHESIZED
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(false)('false')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
DOT_QUALIFIED_EXPRESSION
|
||||||
|
POSTFIX_EXPRESSION
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(true)('true')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(EXCLEXCL)('!!')
|
||||||
|
PsiElement(DOT)('.')
|
||||||
|
CALL_EXPRESSION
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('and')
|
||||||
|
VALUE_ARGUMENT_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
VALUE_ARGUMENT
|
||||||
|
BOOLEAN_CONSTANT
|
||||||
|
PsiElement(false)('false')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
Reference in New Issue
Block a user