/** * Named list operators * * @param b PerlBuilder * @param l Parsing level * @return parsing result */ public static boolean isListOperator(PsiBuilder b, int l) { PerlTokenData prevTokenData = ((PerlBuilder) b).lookupToken(-1); if (prevTokenData != null && prevTokenData.getTokenType() == OPERATOR_DEREFERENCE) return false; IElementType tokenType = b.getTokenType(); IElementType nextTokenType = b.lookAhead(1); if (CONVERTABLE_TOKENS.contains(tokenType) && nextTokenType != LEFT_PAREN // not function call && !PACKAGE_TOKENS.contains(nextTokenType) // not method Package:: && !(nextTokenType == IDENTIFIER && ((PerlBuilder) b) .isKnownPackage( ((PerlBuilder) b).lookupToken(1).getTokenText())) // not Method Package ) // todo we should check current namespace here return !PerlSubUtil.BUILT_IN_UNARY.contains(b.getTokenText()); else if (PACKAGE_TOKENS.contains(tokenType) && CONVERTABLE_TOKENS.contains(nextTokenType) && b.lookAhead(2) != LEFT_PAREN) return !PerlSubUtil.isUnary( b.getTokenText(), ((PerlBuilder) b).lookupToken(1).getTokenText()); return false; }
/** * Named unary operators * * @param b PerlBuilder * @param l parsing level * @return parsing result */ public static boolean isUnaryOperator(PsiBuilder b, int l) { assert b instanceof PerlBuilder; PerlTokenData prevTokenData = ((PerlBuilder) b).lookupToken(-1); if (prevTokenData != null && prevTokenData.getTokenType() == OPERATOR_DEREFERENCE) return false; IElementType tokenType = b.getTokenType(); IElementType nextTokenType = b.lookAhead(1); if (CONVERTABLE_TOKENS.contains(tokenType) && nextTokenType != LEFT_PAREN && !PACKAGE_TOKENS.contains(nextTokenType)) // todo we should check current namespace here return PerlSubUtil.BUILT_IN_UNARY.contains(b.getTokenText()); else if (PACKAGE_TOKENS.contains(tokenType) && CONVERTABLE_TOKENS.contains(SUB) && b.lookAhead(2) != LEFT_PAREN) { PerlTokenData nextToken = ((PerlBuilder) b).lookupToken(1); if (nextToken != null) return PerlSubUtil.isUnary(b.getTokenText(), nextToken.getTokenText()); } return false; }