Permalink
Browse files

forgot to add some classes

Ignore-this: c6dae6ca392cd66084fef2cf110e6da3

darcs-hash:20090609164945-04e1b-7e992039f308fd411394d3be100810679e92ab75.gz
  • Loading branch information...
1 parent a72825a commit 2a980483e4e95716b4d958f88befbd36ac916de3 @ttencate ttencate committed Jun 9, 2009
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="INTERNAL/java/src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,69 @@
+package net.sf.eclipsefp.haskell.scion.client;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import net.sf.eclipsefp.haskell.scion.commands.ScionCommand;
+import net.sf.eclipsefp.haskell.scion.lisp.LispExpr;
+
+/**
+ * A simple standalone program that allows for communication with a Scion server
+ * by typing commands in the console.
+ *
+ * @author Thomas ten Cate
+ */
+public class CommandLineClient {
+
+ public static void main(String[] args) {
+ ScionClient.initializeServer();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+ while (true) {
+ String line;
+ try {
+ line = reader.readLine();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+ if (line.length() == 0) {
+ System.out.println("Exit");
+ ScionClient.dispose();
+ return;
+ }
+ RawCommand command = new RawCommand(line);
+ ScionClient.syncRunCommand(command, 10000);
+ if (command.isCompleted()) {
+ System.out.println(command.getResponse().toString());
+ } else {
+ System.out.println("Timeout");
+ }
+ }
+ }
+
+ private static class RawCommand extends ScionCommand {
+
+ private String lisp;
+ private LispExpr response;
+
+ public RawCommand(String lisp) {
+ this.lisp = lisp;
+ }
+
+ @Override
+ protected String internalLisp() {
+ return lisp;
+ }
+
+ @Override
+ protected void parseInternalResponse(LispExpr response) {
+ this.response = response;
+ }
+
+ public LispExpr getResponse() {
+ return response;
+ }
+
+ }
+
+}
@@ -0,0 +1,22 @@
+package net.sf.eclipsefp.haskell.scion.client;
+
+public class ScionParseException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public ScionParseException() {
+ }
+
+ public ScionParseException(String message) {
+ super(message);
+ }
+
+ public ScionParseException(Throwable cause) {
+ super(cause);
+ }
+
+ public ScionParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
@@ -0,0 +1,69 @@
+package net.sf.eclipsefp.haskell.scion.commands;
+
+import net.sf.eclipsefp.haskell.scion.client.ScionParseException;
+import net.sf.eclipsefp.haskell.scion.lisp.LispExpr;
+import net.sf.eclipsefp.haskell.scion.lisp.LispList;
+
+public class NameDefinitionsCommand extends ScionCommand {
+
+ private String name;
+
+ private boolean found = false;
+ private int startLine, startColumn, endLine, endColumn;
+
+ public NameDefinitionsCommand(String name) {
+ this.name = name;
+ }
+
+ @Override
+ protected String internalLisp() {
+ return String.format("(name-definitions \"%s\")", name);
+ }
+
+ @Override
+ protected void parseInternalResponse(LispExpr response) {
+ // if found:
+ // (:ok ((:loc "/home/thomas/gsoc/runtime-workspace/hello-world/src/HelloWorld.hs" 15 0 15 1)))
+ // otherwise:
+ // (:ok nil)
+ try {
+ LispList list = response.asList().get(1).asList();
+ if (list.length() >= 1) {
+ // one or more results
+ // TODO what if more than one?
+ LispList pos = list.get(0).asList();
+ startLine = pos.get(1).asNumber().getInt();
+ startColumn = pos.get(2).asNumber().getInt();
+ endLine = pos.get(3).asNumber().getInt();
+ endColumn = pos.get(4).asNumber().getInt();
+ found = true;
+ } else {
+ // no results
+ found = false;
+ }
+ } catch (ScionParseException ex) {
+ found = false;
+ }
+ }
+
+ public boolean isFound() {
+ return found;
+ }
+
+ public int getStartLine() {
+ return startLine;
+ }
+
+ public int getStartColumn() {
+ return startColumn;
+ }
+
+ public int getEndLine() {
+ return endLine;
+ }
+
+ public int getEndColumn() {
+ return endColumn;
+ }
+
+}

0 comments on commit 2a98048

Please sign in to comment.