Compare commits
No commits in common. "ba65c1929c2621ea81ffbeb2f478e7a351daa96f" and "474bbf696441c34353977a04bdad236b038ad0c0" have entirely different histories.
ba65c1929c
...
474bbf6964
4 changed files with 41 additions and 128 deletions
|
|
@ -15,37 +15,19 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="page-container">
|
<div class="page-container">
|
||||||
<div class="panel-top grammar-title">
|
<div class="grammar-container">
|
||||||
Write Your Grammar Here
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="panel grammar-container">
|
|
||||||
<textarea id="grammar" name="grammar" class="main-textarea"></textarea>
|
<textarea id="grammar" name="grammar" class="main-textarea"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="status">
|
||||||
<div class="panel status">
|
|
||||||
<span id="status-line">Loading python...</span>
|
<span id="status-line">Loading python...</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="panel-top input-title">
|
<div class="input-container">
|
||||||
Write In Your Language Here
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="panel input-container">
|
|
||||||
<textarea id="input" name="input" class="main-textarea"></textarea>
|
<textarea id="input" name="input" class="main-textarea"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="panel-top result-selector">
|
<div class="results-container">
|
||||||
<span>Results</span>
|
<div id="output-root" />
|
||||||
<span class="result-selector-buttons">
|
|
||||||
<button id="tree-button">Tree</button>
|
|
||||||
<button id="errors-button">Errors</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="panel results-container">
|
|
||||||
<pre id="error-root"></pre>
|
|
||||||
<div id="tree-root"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,4 @@
|
||||||
const STATUS = document.getElementById("status-line");
|
const STATUS = document.getElementById("status-line");
|
||||||
const ERRORS = document.getElementById("error-root");
|
|
||||||
const TREE = document.getElementById("tree-root");
|
|
||||||
|
|
||||||
function show_tree() {
|
|
||||||
ERRORS.classList.add("hidden");
|
|
||||||
TREE.classList.remove("hidden");
|
|
||||||
}
|
|
||||||
|
|
||||||
function show_errors() {
|
|
||||||
ERRORS.classList.remove("hidden");
|
|
||||||
TREE.classList.add("hidden");
|
|
||||||
}
|
|
||||||
|
|
||||||
const DOC_CHAINS = {};
|
const DOC_CHAINS = {};
|
||||||
function chain_document_submit(kind, editor, on_success) {
|
function chain_document_submit(kind, editor, on_success) {
|
||||||
|
|
@ -46,10 +34,6 @@ function chain_document_submit(kind, editor, on_success) {
|
||||||
if (message.status === "ok" && on_success) {
|
if (message.status === "ok" && on_success) {
|
||||||
on_success(message);
|
on_success(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.status === "error") {
|
|
||||||
render_errors(message.errors);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
DOC_CHAINS[kind] = on_result;
|
DOC_CHAINS[kind] = on_result;
|
||||||
|
|
||||||
|
|
@ -87,11 +71,9 @@ worker.onmessage = (e) => {
|
||||||
let grammar_editor = null;
|
let grammar_editor = null;
|
||||||
let input_editor = null;
|
let input_editor = null;
|
||||||
|
|
||||||
function render_errors(errors) {
|
|
||||||
ERRORS.innerText = errors.join("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
function render_parse_results(message) {
|
function render_parse_results(message) {
|
||||||
|
console.log("WHAT?");
|
||||||
|
|
||||||
function render_tree_node(parent, node) {
|
function render_tree_node(parent, node) {
|
||||||
const tree_div = document.createElement("div");
|
const tree_div = document.createElement("div");
|
||||||
tree_div.classList.add("parsed-node");
|
tree_div.classList.add("parsed-node");
|
||||||
|
|
@ -107,12 +89,8 @@ function render_parse_results(message) {
|
||||||
{scroll: true},
|
{scroll: true},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
if (node.start == node.end) {
|
|
||||||
node_label.classList.add("parsed-error-node");
|
|
||||||
}
|
|
||||||
tree_div.appendChild(node_label);
|
tree_div.appendChild(node_label);
|
||||||
|
|
||||||
|
|
||||||
if (node.kind === "tree") {
|
if (node.kind === "tree") {
|
||||||
tree_div.classList.add("parsed-tree");
|
tree_div.classList.add("parsed-tree");
|
||||||
for (const child of node.children) {
|
for (const child of node.children) {
|
||||||
|
|
@ -124,10 +102,9 @@ function render_parse_results(message) {
|
||||||
parent.appendChild(tree_div);
|
parent.appendChild(tree_div);
|
||||||
}
|
}
|
||||||
|
|
||||||
const root = document.getElementById("tree-root");
|
const root = document.getElementById("output-root");
|
||||||
root.innerHTML = "";
|
root.innerHTML = "";
|
||||||
render_tree_node(root, message.tree);
|
render_tree_node(root, message.tree);
|
||||||
render_errors(message.errors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_editors() {
|
function setup_editors() {
|
||||||
|
|
|
||||||
|
|
@ -8,92 +8,60 @@ body {
|
||||||
.page-container {
|
.page-container {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
grid-template-rows: 4rem 2rem 1fr 2rem;
|
grid-template-rows: 4rem 1fr 2em;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel {
|
.grammar-container {
|
||||||
|
grid-column: 1;
|
||||||
|
grid-row: 2;
|
||||||
padding: 0.25rem;
|
padding: 0.25rem;
|
||||||
|
|
||||||
/* Establishing minimum sizes here causes the codemirror CSS to work */
|
/* Establishing minimum sizes here causes the codemirror CSS to work */
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
overflow-y: scroll;
|
|
||||||
border-left: 1px solid;
|
|
||||||
border-right: 1px solid;
|
|
||||||
border-bottom: 1px solid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-top {
|
.status {
|
||||||
padding: 0.5rem;
|
grid-column: 1 / 3;
|
||||||
border-bottom: 1px dashed;
|
|
||||||
border-right: 1px solid;
|
|
||||||
border-left: 1px solid;
|
|
||||||
border-top: 1px solid;
|
|
||||||
}
|
|
||||||
|
|
||||||
.grammar-title {
|
|
||||||
grid-column: 1;
|
|
||||||
grid-row: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.grammar-container {
|
|
||||||
grid-column: 1;
|
|
||||||
grid-row: 3;
|
grid-row: 3;
|
||||||
}
|
padding: 0.25rem;
|
||||||
|
|
||||||
.input-title {
|
|
||||||
grid-column: 2;
|
|
||||||
grid-row: 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-container {
|
.input-container {
|
||||||
grid-column: 2;
|
grid-column: 2;
|
||||||
grid-row: 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.result-selector {
|
|
||||||
position: relative;
|
|
||||||
grid-column: 3;
|
|
||||||
grid-row: 2;
|
grid-row: 2;
|
||||||
|
padding: 0.25rem;
|
||||||
|
|
||||||
|
/* Establishing minimum sizes here causes the codemirror CSS to work */
|
||||||
|
min-height: 0;
|
||||||
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.result-selector-buttons {
|
.input-status {
|
||||||
position: absolute;
|
grid-column: 2;
|
||||||
top: 0.25rem;
|
grid-row: 3;
|
||||||
right: 1rem;
|
padding: 0.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.results-container {
|
.results-container {
|
||||||
grid-column: 3;
|
grid-column: 3;
|
||||||
grid-row: 3;
|
grid-row: 2;
|
||||||
}
|
|
||||||
|
|
||||||
.status {
|
|
||||||
grid-column: 1 / 4;
|
|
||||||
grid-row: 4;
|
|
||||||
padding: 0.25rem;
|
padding: 0.25rem;
|
||||||
border: 1px solid;
|
|
||||||
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
.parsed-node {
|
.parsed-node {
|
||||||
margin-left: 1rem;
|
margin-left: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.parsed-error-node {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
.main-textarea {
|
.main-textarea {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hidden {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.CodeMirror {
|
.CodeMirror {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,15 +31,9 @@ const dingus_module = {
|
||||||
postMessage({kind: "grammar", status: "ok", message: msg});
|
postMessage({kind: "grammar", status: "ok", message: msg});
|
||||||
},
|
},
|
||||||
|
|
||||||
post_grammar_error: function(errors) {
|
post_grammar_error: function(error) {
|
||||||
errors = data_to_js(errors);
|
console.log("Grammar Error:", error);
|
||||||
console.log("Grammar Error:", errors);
|
postMessage({kind:"grammar", status: "error", message: error});
|
||||||
postMessage({
|
|
||||||
kind:"grammar",
|
|
||||||
status: "error",
|
|
||||||
message: "An error occurred loading the grammar",
|
|
||||||
errors: errors,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
post_doc_parse: function(tree, errors) {
|
post_doc_parse: function(tree, errors) {
|
||||||
|
|
@ -56,15 +50,9 @@ const dingus_module = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
post_doc_error: function(errors) {
|
post_doc_error: function(error) {
|
||||||
errors = data_to_js(errors);
|
console.log("Doc Error:", error);
|
||||||
console.log("Doc Error:", errors);
|
postMessage({kind:"input", status: "error", message: error});
|
||||||
postMessage({
|
|
||||||
kind:"input",
|
|
||||||
status: "error",
|
|
||||||
message: "An error occurred parsing the document",
|
|
||||||
errors: errors,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -92,23 +80,23 @@ import parser.runtime as runtime
|
||||||
import pyodide.code
|
import pyodide.code
|
||||||
import pyodide.ffi as ffi
|
import pyodide.ffi as ffi
|
||||||
|
|
||||||
|
GRAMMAR_GLOBALS = {}
|
||||||
GRAMMAR = None
|
GRAMMAR = None
|
||||||
PARSE_TABLE = None
|
PARSE_TABLE = None
|
||||||
LEXER = None
|
LEXER = None
|
||||||
|
|
||||||
def eval_grammar(code):
|
def eval_grammar(code):
|
||||||
|
global GRAMMAR_GLOBALS
|
||||||
global GRAMMAR
|
global GRAMMAR
|
||||||
global PARSE_TABLE
|
global PARSE_TABLE
|
||||||
global LEXER
|
global LEXER
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dingus.post_grammar_status("Evaluating grammar...")
|
dingus.post_grammar_status("Evaluating grammar...")
|
||||||
print("Hey?")
|
pyodide.code.eval_code(code, globals=GRAMMAR_GLOBALS)
|
||||||
grammar_globals={}
|
|
||||||
pyodide.code.eval_code(code, globals=grammar_globals)
|
|
||||||
|
|
||||||
grammar = None
|
grammar = None
|
||||||
for key, value in grammar_globals.items():
|
for key, value in GRAMMAR_GLOBALS.items():
|
||||||
if isinstance(value, type) and issubclass(value, parser.Grammar) and value is not parser.Grammar:
|
if isinstance(value, type) and issubclass(value, parser.Grammar) and value is not parser.Grammar:
|
||||||
value = value()
|
value = value()
|
||||||
|
|
||||||
|
|
@ -132,9 +120,8 @@ def eval_grammar(code):
|
||||||
dingus.post_grammar_loaded(grammar.name)
|
dingus.post_grammar_loaded(grammar.name)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ohno = traceback.format_exc()
|
traceback.print_exc()
|
||||||
print(f"grammar: {ohno}")
|
dingus.post_grammar_error(f"{e}")
|
||||||
dingus.post_grammar_error(ohno.splitlines())
|
|
||||||
|
|
||||||
def tree_to_js(tree):
|
def tree_to_js(tree):
|
||||||
if tree is None:
|
if tree is None:
|
||||||
|
|
@ -165,9 +152,8 @@ def eval_document(code):
|
||||||
tree, errors = runtime.parse(PARSE_TABLE, LEXER, code)
|
tree, errors = runtime.parse(PARSE_TABLE, LEXER, code)
|
||||||
dingus.post_doc_parse(tree_to_js(tree), errors)
|
dingus.post_doc_parse(tree_to_js(tree), errors)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ohno = traceback.format_exc()
|
traceback.print_exc()
|
||||||
print(f"doc: {ohno}")
|
dingus.post_doc_error(f"{e}")
|
||||||
dingus.post_doc_error(ohno.splitlines())
|
|
||||||
`);
|
`);
|
||||||
|
|
||||||
dingus_module.post_grammar_status("Ready.");
|
dingus_module.post_grammar_status("Ready.");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue