const fs=require('fs');
const path='d:/Sites/Work/RadioCast/src/main.js';
const s=fs.readFileSync(path,'utf8');
const lines=s.split(/\r?\n/);
const stack=[];
for(let i=0;i<lines.length;i++){
  const line=lines[i];
  for(let j=0;j<line.length;j++){
    const ch=line[j];
    if(ch==='{' ) stack.push({line:i+1,col:j+1});
    else if(ch==='}'){
      if(stack.length>0) stack.pop(); else console.log('Unmatched closing } at',i+1,j+1);
    }
  }
}
console.log('Unmatched openings left:', stack.length);
if(stack.length>0) console.log('First unmatched opening at', stack[0]);
if(stack.length>0) console.log('Last unmatched opening at', stack[stack.length-1]);
if(stack.length>0){
  const sidx=Math.max(1, stack[stack.length-1].line-5);
  const eidx=Math.min(lines.length, stack[stack.length-1].line+5);
  console.log('\nContext:');
  for(let i=sidx;i<=eidx;i++) console.log(i+': '+lines[i-1]);
}
