Commit 3ca98642 authored by Andrew Gibiansky's avatar Andrew Gibiansky

parsec working! all cleaned up

parent f07febc3
......@@ -18,12 +18,7 @@ import IHaskell.Display
instance Show a => IHaskellDisplay (Parser a) where
display renderable = return $ Display [html dom]
where
dom =
[i|
<script src="/static/components/codemirror/addon/lint/lint.js" charset="utf-8"></script>
<form><textarea id="parsec-editor">Insert parser text here...</textarea></form>
<pre id="parsec-output"></pre>
|]
dom = [hereFile|widget.html|]
-- | Text to parse.
data ParseText = ParseText String
......
<!-- CodeMirror component -->
<link rel="stylesheet" href="/static/components/codemirror/addon/lint/lint.css">
<script src="/static/components/codemirror/addon/lint/lint.js" charset="utf-8"></script>
<!-- Parsec widget -->
<script>
console.log("Registered: ", window.parsecWidgetRegistered);
var kernel = IPython.notebook.kernel;
var initialized = kernel !== undefined && kernel != null;
if (initialized && window.parsecWidgetRegistered === undefined) {
window.parsecWidgetRegistered = true;
console.log("Initializing Parsec widget.");
// Register the comm target.
var ParsecWidget = function (comm) {
this.comm = comm;
this.comm.on_msg($.proxy(this.handler, this));
// Get the cell that was probably executed.
// The msg_id:cell mapping will make this possible without guessing.
this.cell = IPython.notebook.get_cell(IPython.notebook.get_selected_index()-1);
// Store this widget so we can use it from callbacks.
var widget = this;
// Editor options.
var options = {
lineNumbers: true,
// Show parsec errors as lint errors.
gutters: ["CodeMirror-lint-markers"],
lintWith: {
"getAnnotations": function(cm, update, opts) {
var errs = [];
if (widget.hasError) {
var col = widget.error["col"];
var line = widget.error["line"];
errs = [{
from: CodeMirror.Pos(line - 1, col - 1),
to: CodeMirror.Pos(line - 1, col),
message: widget.error["msg"],
severity: "error"
}];
}
update(cm, errs);
},
"async": true,
}
};
// Create the editor.
var out = this.cell.output_area.element;
this.textarea = out.find("#parsec-editor")[0];
this.output = out.find("#parsec-output")[0];
var editor = CodeMirror.fromTextArea(this.textarea, options);
var editor = editor;
// Update every key press.
editor.on("keyup", function() {
var text = editor.getDoc().getValue();
comm.send({"text": text});
});
};
ParsecWidget.prototype.handler = function(msg) {
var data = msg.content.data;
this.hasError = data["status"] == "error";
if (this.hasError) {
out = data["msg"];
this.error = data;
} else {
out = data["result"];
}
// Update viewed output.
this.output.innerHTML = out;
};
// Register this widget.
IPython.notebook.kernel.comm_manager.register_target('parsec', IPython.utils.always_new(ParsecWidget));
console.log("Registering parsec widget.");
}
</script>
<!-- Parsec widget DOM -->
<form><textarea id="parsec-editor">Insert parser text here...</textarea></form>
<pre id="parsec-output"></pre>
This diff is collapsed.
......@@ -374,7 +374,6 @@ replyTo _ ObjectInfoRequest{objectName = oname} replyHeader state = do
handleComm :: (Message -> IO ()) -> KernelState -> Message -> MessageHeader -> IO KernelState
handleComm replier kernelState req replyHeader = do
print req
let widgets = openComms kernelState
uuid = commUuid req
dat = commData req
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment