From ea8477bb914553dcefaa9d7e8c7fb80d6d0a9163 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 19 May 2019 10:39:29 -0400 Subject: [PATCH] zasm: accept whitespaces before separating comma --- apps/zasm/tok.asm | 25 ++++++++++++++----------- tools/tests/zasm/test1.asm | 3 ++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/zasm/tok.asm b/apps/zasm/tok.asm index ce85791..4d9479a 100644 --- a/apps/zasm/tok.asm +++ b/apps/zasm/tok.asm @@ -71,6 +71,14 @@ isLabel: pop hl ret +; Read I/O as long as it's whitespace. When it's not, stop and return the last +; read char in A +_eatWhitespace: + call ioGetC + call isSep + ret nz + jr _eatWhitespace + ; Read ioGetC until a word starts, then read ioGetC as long as there is no ; separator and put that contents in (scratchpad), null terminated, for a ; maximum of SCRATCHPAD_SIZE-1 characters. @@ -81,14 +89,9 @@ isLabel: readWord: push bc ; Get to word -.loop1: - call ioGetC + call _eatWhitespace call isLineEndOrComment jr z, .error - call isSep - jr nz, .read - jr .loop1 -.read: ld hl, scratchpad ld b, SCRATCHPAD_SIZE-1 ; A contains the first letter to read @@ -98,7 +101,7 @@ readWord: ; Are we opening a single quote? cp 0x27 ; ' jr z, .singleQuote -.loop2: +.loop: ld (hl), a inc hl call ioGetC @@ -106,7 +109,7 @@ readWord: jr z, .success cp ',' jr z, .success - djnz .loop2 + djnz .loop ; out of space. error. .error: ; We need to put the last char we've read back so that gotoNextLine @@ -129,7 +132,7 @@ readWord: inc hl call ioGetC cp '"' - jr z, .loop2 ; ending the quote ends the word + jr z, .loop ; ending the quote ends the word call isLineEnd jr z, .error ; ending the line without closing the quote, ; nope. @@ -150,12 +153,12 @@ readWord: jr nz, .error inc hl ld (hl), a - jr .loop2 + jr .loop ; Reads the next char in I/O. If it's a comma, Set Z and return. If it's not, ; Put the read char back in I/O and unset Z. readComma: - call ioGetC + call _eatWhitespace cp ',' ret z call ioPutBack diff --git a/tools/tests/zasm/test1.asm b/tools/tests/zasm/test1.asm index 7487ce8..25b905c 100644 --- a/tools/tests/zasm/test1.asm +++ b/tools/tests/zasm/test1.asm @@ -20,7 +20,8 @@ label2: .dw 0x42 ld l, (ix+1) ld hl, 0x100 .equ baz 0x20 - ld b, baz-3 + ; accept space before comma + ld b , baz-3 rl d rr e rlc c