All files parser.js

87.8% Statements 72/82
100% Branches 17/17
80% Functions 4/5
87.8% Lines 72/82

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 831x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 8x 8x 9x 9x 7x 7x 9x 3x 3x 2x 2x 1x 1x 1x 1x 10x 10x 3x 3x 10x 1x 1x 1x 1x 1x                     1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
// assembler file parser
// gets a text file, returns an array of parsed lines
 
import { prepro, unroll } from "./preprocessor.js";
import { parseLine } from "./parseLine.js";
 
const norm = (xs) => xs.map((lx) => {
    let l = lx.line;
    l = l.replace("&lt;", "<");
    l = l.replace("&gt;", ">");
    while (l[l.length - 1] == " ") {
      l = l.substr(0, l.length - 1);
    }
    lx.line = l;
    if (l[0] != " ") {
      return lx;
    }
    while (l[0] == " ") {
      l = l.substr(1);
    }
    lx.line = " " + l;
    return lx;
  });
 
  //remove empty lines
const nonempty = (xs) => xs.filter((lx) => {
    let l = lx.line;
    while (l[0] == " ") {
      l = l.substr(1);
    }
    return l.length ? true : false;
  });
 
 
  //beautify helper
const emptymask = (xs) => xs.map((lx) => {
    let l = lx.line;
    let lx2 = {
      addr: 0,
      line: ";;;EMPTYLINE",
      numline: lx.numline
    };
    while (l[0] == " ") {
      l = l.substr(1);
    }
    return l.length ? lx : lx2;
  });
 
 
  //convert lines to internal structure
 
export const toInternal = (xs) => {
    var numLine = 1;
    return xs.map((line) => ({
      line: line, //original line
      numline: numLine++, //line number
      addr: null, //address in code
      bytes: 0, //number of bytes of this instruction
    }));
  };
 
 
export const parse = (s, asm) => {
  /*
  assembler = asm;
  if (asm.endian) endian = asm.endian;
  */
  //includedFiles = {};
  var i = toInternal(s.split(/\n/));
  i = nonempty(i);
  i = norm(i);
 
  //macro processing and expansion
  
  var prei = prepro(i);
  //console.log(prei)
  i = prei[0].map((line) => parseLine(line, prei[1]));
  i = unroll(i, prei[1]);
  
  //console.log("prei",i)
  return i;
};