Commit 5b6a75f5 authored by Raghav Khanna's avatar Raghav Khanna

Correctly handle larger blocks

parent 84d4becc
......@@ -15,7 +15,7 @@
// Fixes for printing with new lines.
let waccPrintingBuffer = ""
function waccPrint(str) {
printing_buffer += str
waccPrintingBuffer += str
}
function waccPrintLn(str) {
......
......@@ -9,7 +9,7 @@ import Terminal from 'terminal-in-react';
import Card from "./components/Card/Card.js";
import CardBody from "./components/Card/CardBody.js";
import {sendWaccCode, astMetaToGraphData} from './Comm'
import {sendWaccCode, astMetaToGraphData, highlightNode} from './Comm'
import GridItem from "./components/Grid/GridItem";
import GridContainer from "./components/Grid/GridContainer";
......@@ -117,19 +117,28 @@ class App extends React.Component {
proccesLine = () => {
if (this.state.statementIndex < this.state.mainStatements.length) {
let current = this.state.currentNode;
let jsLines = this.state.js.code.split(/;\n(?!})/);
// console.log(jsLines)
// console.log(current)
let codeLine = jsLines[current.highlighting.js[0].startRow];
codeLine = codeLine.replace("var ", "window.");
let jsLines = this.state.js.code.split("\n");
let startLine = current.highlighting.js[0].startRow;
let endLine = current.highlighting.js[0].endRow;
let codeLine = "";
if(startLine == endLine){
codeLine = jsLines[startLine];
} else {
for(let i = startLine; i < endLine; i++){
codeLine = codeLine.concat(jsLines[i], "\n")
}
}
codeLine = codeLine.replace("let ", "window.");
eval(codeLine);
;
let newIndex = this.state.statementIndex + 1;
// let highlightData = highlightNode(current);
this.setState({
currentNode: this.state.mainStatements[newIndex],
statementIndex: newIndex
})
} else {
eval(" waccPrintFinished()");
eval("waccPrintingBuffer = \"\"")
console.log("Finished executing code")
}
};
......
......@@ -12,7 +12,7 @@ export function astMetaToGraphData(astMeta) {
function generateMarkerObject(start, end, off = 0, style="ast-node-highlight") {
return {
startRow: start.lineNum - 1,
startCol: start.charNum + off,
startCol: start.charNum,
endRow: end.lineNum - 1,
endCol: end.charNum,
className: style,
......@@ -24,7 +24,7 @@ function generateArmMarkers(lineNums, style = "ast-node-highlight") {
return lineNums.map(ln => ({startRow: ln - 1, className: style, type: "background"}))
}
function highlightNode(node, style = "ast-node-highlight") {
export function highlightNode(node, style = "ast-node-highlight") {
return {
wacc: [generateMarkerObject(node.waccStart, node.waccEnd, style)],
js: typeof node.jsStart === "undefined" ? [{}] : [generateMarkerObject(node.jsStart, node.jsEnd, -1, style)],
......@@ -64,7 +64,7 @@ export async function sendWaccCode(code) {
})
.catch(error => {
if (typeof error.response.data.errors !== "undefined") {
var errors = error.response.data.errors;
let errors = error.response.data.errors;
for (let entry of errors.keys()) {
console.log(errors[entry])
}
......
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