From 87d73fcc5f6f4025d4c4f910fb3dc68a00a4a1b1 Mon Sep 17 00:00:00 2001 From: Mirko Scholz Date: Sat, 3 Sep 2022 13:58:17 +0200 Subject: [PATCH] lookup to word boundary, fixes issue #54 (cherry picked from commit c59f0259f77a81d393624333cd75c5bfb64b6ed2) --- src/avra.h | 1 + src/directiv.c | 2 +- src/mnemonic.c | 2 +- src/parser.c | 9 +++++++++ tests/regression/issue54-parenthesis/test.asm | 10 ++++++++++ tests/regression/issue54-parenthesis/test.hex.expected | 3 +++ 6 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/regression/issue54-parenthesis/test.asm create mode 100644 tests/regression/issue54-parenthesis/test.hex.expected diff --git a/src/avra.h b/src/avra.h index 363d91f..8aa6d78 100644 --- a/src/avra.h +++ b/src/avra.h @@ -106,6 +106,7 @@ enum { enum { TERM_END = 0, TERM_SPACE, + TERM_WORD, TERM_COMMA, TERM_EQUAL, TERM_DASH, diff --git a/src/directiv.c b/src/directiv.c index 5627516..cff1f63 100644 --- a/src/directiv.c +++ b/src/directiv.c @@ -164,7 +164,7 @@ parse_directive(struct prog_info *pi) struct def *def; struct data_list *incpath, *dl; - next = get_next_token(pi->fi->scratch, TERM_SPACE); + next = get_next_token(pi->fi->scratch + 1, TERM_WORD); my_strupr(pi->fi->scratch); directive = lookup_keyword(directive_list, pi->fi->scratch + 1, True); diff --git a/src/mnemonic.c b/src/mnemonic.c index a51871a..24996fa 100644 --- a/src/mnemonic.c +++ b/src/mnemonic.c @@ -355,7 +355,7 @@ parse_mnemonic(struct prog_info *pi) struct macro *macro; char temp[MAX_MNEMONIC_LEN + 1]; - operand1 = get_next_token(pi->fi->scratch, TERM_SPACE); /* we get the first word on line */ + operand1 = get_next_token(pi->fi->scratch, TERM_WORD); /* we get the first word on line */ mnemonic = get_mnemonic_type(pi); if (mnemonic == -1) { /* if -1 this must be a macro name */ macro = get_macro(pi, pi->fi->scratch); /* and so, we try to get the corresponding macro struct. */ diff --git a/src/parser.c b/src/parser.c index 710f1d6..eb06daa 100644 --- a/src/parser.c +++ b/src/parser.c @@ -336,6 +336,15 @@ get_next_token(char *data, int term) /* Skip to next horizontal space or EOL or start of comment. */ while (!IS_HOR_SPACE(data[i]) && !IS_END_OR_COMMENT(data[i])) i++; break; + case TERM_WORD: + /* Skip to end of word. */ + while (IS_LABEL(data[i]) || data[i] == '.') i++; + if (!isblank(data[i])) { + int k = strlen(data); + for (; k != i-1; k--) data[k+1] = data[k]; + data[i] = ' '; + } + break; case TERM_DASH: /* Skip to next dash or EOL or start of comment. */ while ((data[i] != '-') && !IS_END_OR_COMMENT(data[i])) i++; diff --git a/tests/regression/issue54-parenthesis/test.asm b/tests/regression/issue54-parenthesis/test.asm new file mode 100644 index 0000000..e84a91c --- /dev/null +++ b/tests/regression/issue54-parenthesis/test.asm @@ -0,0 +1,10 @@ +.device atmega168 +.macro DEST + .dw @0 +.endmacro +nop +KEYLOOP: + DEST(KEYLOOP) +.if(1) +nop +.endif diff --git a/tests/regression/issue54-parenthesis/test.hex.expected b/tests/regression/issue54-parenthesis/test.hex.expected new file mode 100644 index 0000000..4f9f946 --- /dev/null +++ b/tests/regression/issue54-parenthesis/test.hex.expected @@ -0,0 +1,3 @@ +:020000020000FC +:06000000000001000000F9 +:00000001FF