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

Correctly handle larger blocks

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