diff --git a/public/index.html b/public/index.html index 15bc47680ed64f42ec5fb68f476b7ef293ce6a2f..deeb515d471f5b90ed59ff110e24b790a9af4da6 100644 --- a/public/index.html +++ b/public/index.html @@ -15,7 +15,7 @@ // Fixes for printing with new lines. let waccPrintingBuffer = "" function waccPrint(str) { - printing_buffer += str + waccPrintingBuffer += str } function waccPrintLn(str) { diff --git a/src/App.js b/src/App.js index b28b667c84937c09d098085a409dd4f8a3593401..8989728c26d1d7d3f674f22477d23cb1b4b68d0a 100644 --- a/src/App.js +++ b/src/App.js @@ -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") } }; diff --git a/src/Comm.js b/src/Comm.js index 216fdbdd6278102d991b7b442a81591ddc6924c5..c229ddc79fab2a138b6061d5ef44e891220d9835 100644 --- a/src/Comm.js +++ b/src/Comm.js @@ -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]) }