Commit a20f30b4 authored by Matej Genci's avatar Matej Genci

Function to generate markers to highlight node

parent 264f6513
...@@ -9,19 +9,27 @@ export function astMetaToGraphData(astMeta) { ...@@ -9,19 +9,27 @@ export function astMetaToGraphData(astMeta) {
return graphData return graphData
} }
function generateMarkerObject(start, end, off = 0) { 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 + off,
endRow: end.lineNum - 1, endRow: end.lineNum - 1,
endCol: end.charNum, endCol: end.charNum,
className: "ast-node-highlight", className: style,
type: "text" type: "text"
} }
} }
function generateArmMarkers(lineNums) { function generateArmMarkers(lineNums, style = "ast-node-highlight") {
return lineNums.map(ln => ({startRow: ln - 1, className: "ast-node-highlight", type: "background"})) return lineNums.map(ln => ({startRow: ln - 1, className: style, type: "background"}))
}
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)],
arm: generateArmMarkers(node.armLineNums, style)
}
} }
function createGraphNode(node, astMeta){ function createGraphNode(node, astMeta){
...@@ -41,11 +49,7 @@ function createGraphNode(node, astMeta){ ...@@ -41,11 +49,7 @@ function createGraphNode(node, astMeta){
return { return {
name: name, name: name,
attributes: {value: value}, attributes: {value: value},
highlighting: { highlighting: highlightNode(node),
wacc: [generateMarkerObject(node.waccStart, node.waccEnd)],
js: typeof node.jsStart === "undefined" ? [{}] : [generateMarkerObject(node.jsStart, node.jsEnd, -1)],
arm: generateArmMarkers(node.armLineNums)
},
children: children children: children
} }
......
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