Commit 9c03ebff authored by Raghav Khanna's avatar Raghav Khanna

Parse json data to make primitive graph.

parent 2cf4353f
import React from 'react' import React from 'react'
import axios from 'axios' import axios from 'axios'
import {array} from "prop-types";
const SERVER_ADDR = "http://192.168.1.67:8080/" const SERVER_ADDR = "http://192.168.1.67:8080/"
const SERVER_ENDPOINT = "" const SERVER_ENDPOINT = ""
const testGraphData = [{ const testGraphData = [{
name: "WACC Program", children: [{ name: "WACC Program", children: [{
name: "BinOP", attributes: { operation: "Add" }, name: "BinOP", attributes: {operation: "Add"},
children: [{ name: "Const", attributes: { value: "1" } }, { name: "VarIdent", attributes: { ident: "x" } }] children: [{name: "Const", attributes: {value: "1"}}, {name: "VarIdent", attributes: {ident: "x"}}]
}] }]
}]; }];
export function astMetaToGraphData(astMeta) { export function astMetaToGraphData(astMeta) {
return testGraphData let firstNode = astMeta.nodes["0"]
let graphData = createGraphNode(firstNode.name, firstNode.value, firstNode.children, astMeta)
return graphData
}
function createGraphNode(name, value, childrenIDs, astMeta){
var children = [];
if(typeof childrenIDs !== "undefined") {
for (var i = 0; i < childrenIDs.length; i++) {
var childID = childrenIDs[i]
var child = astMeta.nodes[childID];
children.push(createGraphNode(child.name, child.value, child.children, astMeta))
}
}
let retObj = {
name: name,
attributes: { value: value },
children: children
}
// console.log(JSON.stringify(retObj))
return retObj
} }
export async function sendWaccCode(code) { export async function sendWaccCode(code) {
let ADDR = SERVER_ADDR + SERVER_ENDPOINT; let ADDR = SERVER_ADDR + SERVER_ENDPOINT;
var data = {isError: true}; var data = {isError: true};
await axios.post(ADDR, {contents: code}, {headers:{'Content-Type': 'application/json'}}) await axios.post(ADDR, {contents: code}, {headers: {'Content-Type': 'application/json'}})
.then(res => { .then(res => {
data = res.data data = res.data
}) })
.catch(error => { .catch(error => {
if(typeof error.response.data.errors !== "undefined" ){ if (typeof error.response.data.errors !== "undefined") {
var errors = error.response.data.errors; var 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