Package com.stuffwithstuff.magpie.parser

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

package com.stuffwithstuff.magpie.parser;

import com.stuffwithstuff.magpie.ast.Expr;

public class BacktickParser implements PrefixParser {
  @Override
  public Expr parse(MagpieParser parser, Token token) {
    if (!parser.inQuote()) {
      throw new ParseException(token.getPosition(),
          "Cannot unquote outside of a quotation.");
    }
   
    Position position = token.getPosition();
    Expr body;
    if (parser.match(TokenType.NAME)) {
      body = Expr.name(parser.last(1).getPosition(),
          parser.last(1).getString());
    } else {
      parser.consume(TokenType.LEFT_PAREN);
      body = parser.groupExpression(TokenType.RIGHT_PAREN);
    }
   
    return Expr.unquote(position, body);
  }
}
TOP

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

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.