SwiftSupport.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:ts-swift-transpiler 作者:
/**
 "If an operator has whitespace around both sides or around neither side,
 it is treated as a binary operator. As an example, the + operator in a+b
 and a + b is treated as a binary operator."
 */
public static boolean isBinaryOp(TokenStream tokens) {
    int stop = getLastOpTokenIndex(tokens);
    if ( stop==-1 ) return false;

    int start = tokens.index();
    Token prevToken = tokens.get(start-1); // includes hidden-channel tokens
    Token nextToken = tokens.get(stop+1);
    boolean prevIsWS = isLeftOperatorWS(prevToken);
    boolean nextIsWS = isRightOperatorWS(nextToken);
    boolean result = prevIsWS && nextIsWS || (!prevIsWS && !nextIsWS);
    String text = tokens.getText(Interval.of(start, stop));
    //System.out.println("isBinaryOp: '"+prevToken+"','"+text+"','"+nextToken+"' is "+result);
    return result;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号