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(
|
||||
// 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
|
||||
|
||||
LPAR, // parenthesized
|
||||
@@ -325,24 +327,34 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
*/
|
||||
private void parsePrefixExpression() {
|
||||
// System.out.println("pre at " + myBuilder.getTokenText());
|
||||
|
||||
if (at(LBRACKET)) {
|
||||
if (!parseLocalDeclaration()) {
|
||||
PsiBuilder.Marker expression = mark();
|
||||
myJetParsing.parseAnnotations(false);
|
||||
parsePrefixExpression();
|
||||
expression.done(ANNOTATED_EXPRESSION);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
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();
|
||||
expression.done(PREFIX_EXPRESSION);
|
||||
} else {
|
||||
parsePostfixExpression();
|
||||
myBuilder.restoreJoiningComplexTokensState();
|
||||
|
||||
parsePrefixExpression();
|
||||
expression.done(PREFIX_EXPRESSION);
|
||||
}
|
||||
else {
|
||||
myBuilder.restoreJoiningComplexTokensState();
|
||||
parsePostfixExpression();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -32,7 +32,7 @@ import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
* @author abreslav
|
||||
*/
|
||||
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> newlinesEnabled = new Stack<Boolean>();
|
||||
@@ -126,6 +126,10 @@ public class SemanticWhitespaceAwarePsiBuilderImpl extends PsiBuilderAdapter imp
|
||||
if (nextRawToken == DOT) return SAFE_ACCESS;
|
||||
if (nextRawToken == COLON) return ELVIS;
|
||||
}
|
||||
else if (rawTokenType == EXCL) {
|
||||
IElementType nextRawToken = rawLookup(rawLookupSteps);
|
||||
if (nextRawToken == EXCL) return EXCLEXCL;
|
||||
}
|
||||
return rawTokenType;
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ LONG_TEMPLATE_ENTRY_END=\}
|
||||
">=" { return JetTokens.GTEQ ; }
|
||||
"==" { return JetTokens.EQEQ ; }
|
||||
"!=" { return JetTokens.EXCLEQ ; }
|
||||
"!!" { return JetTokens.EXCLEXCL ; }
|
||||
//"!!" { return JetTokens.EXCLEXCL ; }
|
||||
"&&" { return JetTokens.ANDAND ; }
|
||||
"||" { return JetTokens.OROR ; }
|
||||
//"?." { 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