From a05ee6680fd8a1a8970548edfe963b3e870b6280 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Thu, 18 Jul 2019 22:35:30 -0400 Subject: [PATCH] update parseHexWords regex to make Verilog binary separate case --- src/pixed/pixeleditor.ts | 10 +++++++--- test/cli/testpixelconvert.js | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/pixed/pixeleditor.ts b/src/pixed/pixeleditor.ts index 655d03ed..3aa3d995 100644 --- a/src/pixed/pixeleditor.ts +++ b/src/pixed/pixeleditor.ts @@ -60,7 +60,7 @@ type PixelEditorMessage = { ///////////////// -var pixel_re = /([0#]?)([bx$%]|\d'[bh])([0-9a-f]+)(?:;.*$)?/gim; +var pixel_re = /([0#]?)([x$%]|\d'h)([0-9a-f]+)|(\d'b)([01]+)/gim; function convertToHexStatements(s:string) : string { // convert 'hex ....' asm format @@ -78,7 +78,9 @@ export function parseHexWords(s:string) : number[] { var m; while (m = pixel_re.exec(s)) { var n; - if (m[2].startsWith('%') || m[2].endsWith("b")) + if (typeof m[4] !== 'undefined') + n = parseInt(m[5],2); + else if (m[2].startsWith('%') || m[2].endsWith("b")) n = parseInt(m[3],2); else if (m[2].startsWith('x') || m[2].startsWith('$') || m[2].endsWith('h')) n = parseInt(m[3],16); @@ -97,7 +99,9 @@ export function replaceHexWords(s:string, words:UintArray) : string { while (m = pixel_re.exec(s)) { result += s.slice(li, pixel_re.lastIndex - m[0].length); li = pixel_re.lastIndex; - if (m[2].startsWith('%')) + if (typeof m[4] !== 'undefined') + result += m[4] + words[i++].toString(2); + else if (m[2].startsWith('%')) result += m[1] + "%" + words[i++].toString(2); else if (m[2].endsWith('b')) result += m[1] + m[2] + words[i++].toString(2); // TODO diff --git a/test/cli/testpixelconvert.js b/test/cli/testpixelconvert.js index eb57031b..4ac65b59 100644 --- a/test/cli/testpixelconvert.js +++ b/test/cli/testpixelconvert.js @@ -60,5 +60,14 @@ describe('Pixel editor', function() { pixed.replaceHexWords(paldatastr, pixed.parseHexWords(paldatastr))); node3.refreshLeft(); assert.deepEqual(node2.images, [[0,0,0,0,14,15,14,15,14,0,0,0,0,0,0,0,14,14,14,14,15,14,14,14,14,0,0,0,0,14,14,13,14,15,14,15,14,13,14,14,0,0,0,14,14,14,13,13,13,13,13,14,14,14,0,0,0,14,14,14,14,13,13,14,14,14,14,14,0,0,0,0,14,14,14,14,13,14,14,14,14,0,0,0,0,0,14,14,14,14,13,14,14,14,14,0,0,0,0,0,0,0,14,13,13,13,14,0,0,0,0,13,13,13,13,13,14,14,14,14,14,13,13,13,13,0,0,13,14,14,14,14,14,14,14,14,14,14,0,0,0,14,14,0,14,14,14,14,14,0,14,14,0,0,0,14,14,0,14,14,14,14,14,0,14,14,0,0,0,14,14,0,13,13,13,13,13,0,13,14,0,0,0,13,0,0,14,14,0,14,14,0,0,13,0,0,0,0,0,0,14,13,0,14,14,0,0,0,0,0,0,0,0,13,13,13,0,13,13,13,0,0,1,8]]); + + var datastr2 = "const char PALETTE[32] = { \n 0x03, // screen color\n\n 0x11,0x30,0x27,0x0, // background palette 0\n 0x1c,0x20,0x2c,0x0, // background palette 1\n};"; + var words2 = pixed.parseHexWords(datastr2); + assert.deepEqual(words2, [0x03,0x11,0x30,0x27,0x00,0x1c,0x20,0x2c,0x00]); + + var datastr3 = " 7'o00: bits = 5'b11111; "; + var words3 = pixed.parseHexWords(datastr3); + assert.deepEqual(words3, [31]); + assert.equal(datastr3, pixed.replaceHexWords(datastr3, pixed.parseHexWords(datastr3))); }); });