Package com.stuffwithstuff.magpie.parser

Source Code of com.stuffwithstuff.magpie.parser.InfixOperatorParser

package com.stuffwithstuff.magpie.parser;

import com.stuffwithstuff.magpie.ast.Expr;

/**
* Parses an infix operator call that just desugars to a regular method call.
*/
public class InfixOperatorParser implements InfixParser {
  public InfixOperatorParser(int precedence) {
    mPrecedence = precedence;
  }
 
  @Override
  public Expr parse(MagpieParser parser, Expr left, Token token) {
    // Assume left associativity.
    Expr right = parser.parsePrecedence(mPrecedence);
   
    return Expr.call(left.getPosition().union(right.getPosition()),
        left, token.getText(), right);
  }
 
  @Override
  public int getPrecedence() { return mPrecedence; }
 
  private final int mPrecedence;
}
TOP

Related Classes of com.stuffwithstuff.magpie.parser.InfixOperatorParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.