Package abstrasy.pcfx

Source Code of abstrasy.pcfx.PCFx_raw_input

package abstrasy.pcfx;

import abstrasy.Interpreter;
import abstrasy.Node;

import abstrasy.consoleui.OutputTextArea;

import abstrasy.interpreter.InterpreterException;

import abstrasy.interpreter.SilentException;

import java.util.Scanner;

/**
* 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_raw_input extends PCFx {

    public PCFx_raw_input() {
    }

    /**
     * eval
     *
     * @param startAt Node
     * @return Node
     * @throws Exception
     * @todo Implémenter cette méthode abstrasy.PCFx
     */
    public Node eval(Node startAt) throws Exception {
        String read = null;
        OutputTextArea out = Interpreter.mySelf().getOutputTextArea();
        if (out != null) {
            // OutputConsole...
            int i = 1;
            while (i < startAt.size()) {
                String x = Node.node2VString(startAt.getSubNode(i++, Node.VTYPE_VALUABLE)).getString();
                System.out.print(x);
                if (out != null) {
                    out.write(x);
                }
            }
            while (read == null) {
                try {
                    read = out.readln(startAt);
                }
                catch (Exception ex) {
                    read = null;
                    if (Interpreter.isDebugMode()) {
                        ex.printStackTrace();
                    }
                    if (ex instanceof InterpreterException || ex instanceof SilentException) {
                        throw ex;
                    }
                }
            }
            System.out.println(read);
        }
        else {
            // in InputStream...
            int i = 1;
            while (i < startAt.size()) {
                System.out.print((Node.node2VString(startAt.getSubNode(i++, Node.VTYPE_VALUABLE))).getString());
            }
            while (read == null) {
                try {
                    Scanner in = new Scanner(System.in);
                    read = in.nextLine();
                    //in.close();       *** ATTENTION NE PAS FERMER LE FICHIER System.in !!!!
                }
                catch (Exception ex) {
                    read = null;
                    if (Interpreter.isDebugMode()) {
                        ex.printStackTrace();
                    }
                    if (ex instanceof InterpreterException || ex instanceof SilentException) {
                        throw ex;
                    }
                }
            }
        }
        return new Node(read);
    }

}
TOP

Related Classes of abstrasy.pcfx.PCFx_raw_input

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.