package nl.utwente.group10.ghcj;

import nl.utwente.group10.haskell.expr.Binding;
import java.util.List;

/**
 * Represents an Environment, that is, a collection of Bindings that lives in
 * a Haskell session, and has methods for querying that collection.
 */
public class GhciEnvironment {
    /** Our parent GhciSession instance. */
    private final GhciSession ghci;

    /**
     * Constructs a fresh GhciEnvironment.
     * @param ghci The parent GhciSession instance.
     */
    public GhciEnvironment(GhciSession ghci) {
        this.ghci = ghci;
    }

    public final List<Binding> getBindings() throws GhciException {
        System.out.println(ghci.eval(":browse"));
        return null;
    }

    @Override
    public final String toString() {
        return "GhciEnvironment{" + "ghci=" + this.ghci + '}';
    }
}

@@ -27,16 +27,56 @@
 .ghcj;%0A%0A
+import com.google.common.base.Splitter;%0A
 import n
@@ -114,16 +114,45 @@
 Binding;
+%0A%0Aimport java.util.ArrayList;
 %0Aimport 
@@ -572,16 +572,22 @@
 ronment(
+final 
 GhciSess
@@ -639,121 +639,836 @@
     
-public final List%3CBinding%3E getBindings() throws GhciException %7B%0A        System.out.println(ghci.eval(%22:browse%22));
+/**%0A     * Query the parent GHCI instance for a list of known functions.%0A     * @return all functions known to GHCI as Binding instances.%0A     * @throws GhciException when GHCI is not ready for our query.%0A     */%0A    public final List%3CBinding%3E getBindings() throws GhciException %7B%0A        String input = this.ghci.eval(%22:browse%22);%0A        List%3CBinding%3E out = new ArrayList%3CBinding%3E();%0A%0A        for (String line : Splitter.on('%5Cn').split(input)) %7B%0A            out.add(this.parseBinding(line));%0A        %7D%0A%0A        return out;%0A    %7D%0A%0A    /**%0A     * Parses a Haskell type into a Binding.%0A     * @param line A Haskell type declaration.%0A     * @throws GhciException when the line is not valid.%0A     * @return A Binding object matching the declaration.%0A     */%0A    private Binding parseBinding(final String line) throws GhciException %7B
 %0A   

Add parseBinding