package abstrasy.pcfx;
import abstrasy.Node;
import abstrasy.interpreter.InterpreterException;
import abstrasy.interpreter.StdErrors;
/**
* Abstrasy Interpreter
*
* Copyright : Copyright (c) 2006-2012, Luc Bruninx.
*
* Concédée sous licence EUPL, version 1.1 uniquement (la «Licence»).
*
* Vous ne pouvez utiliser la présente oeuvre que conformément à la Licence.
* Vous pouvez obtenir une copie de la Licence à l’adresse suivante:
*
* http://www.osor.eu/eupl
*
* Sauf obligation légale ou contractuelle écrite, le logiciel distribué sous
* la Licence est distribué "en l’état", SANS GARANTIES OU CONDITIONS QUELLES
* QU’ELLES SOIENT, expresses ou implicites.
*
* Consultez la Licence pour les autorisations et les restrictions
* linguistiques spécifiques relevant de la Licence.
*
*
* @author Luc Bruninx
* @version 1.0
*/
public class PCFx_dequeue_static extends PCFx {
/**
* respecte la protection de la finalité des listes
*/
public PCFx_dequeue_static() {
}
/**
* eval
*
* @param startAt Node
* @return Node
* @throws Exception
* @todo Implémenter cette méthode abstrasy.PCFx
*/
public Node eval(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
startAt.requireNodeType(1, Node.VTYPE_INDIRECTION);
Node xnode = startAt.getSubNode(1, Node.TYPE_CLIST | Node.TYPE_STRING);
if (xnode.getQType()==Node.TYPE_STRING) {
/*
* (dequeue! "ABC") -> "A"
*/
xnode.requireAccessType(Node.ACCESSVTYPE_MUTABLE_WRITELOCK);
if (xnode.getString().length() < 1)
throw new InterpreterException(StdErrors.Empty_string);
String tstr = xnode.getString();
String le = tstr.substring(0, 1);
xnode.setString(tstr.substring(1, tstr.length()));
return new Node(le);
}
else {
/**
* (dequeue! [...]) -> f
*/
xnode.requireAccessType(Node.ACCESSTYPE_WRITELOCK);
if (xnode.size() < 1)
throw new InterpreterException(StdErrors.Out_of_range);
Node le = xnode.elementAt(0);
xnode.removeElementAt(0);
return le;
}
}
}