summaryrefslogtreecommitdiff
path: root/lexer.c
diff options
context:
space:
mode:
Diffstat (limited to 'lexer.c')
-rw-r--r--lexer.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/lexer.c b/lexer.c
index 099204e..d27a7f0 100644
--- a/lexer.c
+++ b/lexer.c
@@ -588,19 +588,21 @@ char *parse_escape(char *s, char *code) {
}
}
-uint64_t parse_quote(char **s, char delm, int get_value, uint8_t dbg) {
+uint64_t parse_quote(char **s, char delm, int get_value, uint8_t *buf, uint8_t dbg) {
uint64_t value = 0;
- uint8_t *tmp_val = (uint8_t *)&value;
- char *str = *s+1;
+ uint8_t *tmp_val = (buf != NULL) ? buf : (uint8_t *)&value;
+ const uint8_t has_delm = (delm && **s == delm);
+ char *str = *s+has_delm;
+ int i;
- for (int i = 0; *str; i++) {
+ for (i = 0; *str; i++) {
char c;
/* Are we at the start of an escape character? */
if (*str == '\\') {
str = parse_escape(str, &c);
} else {
c = *str++;
- if (c == delm) {
+ if (delm && c == delm) {
if (*str == delm) {
/* Allow for multiple repeated
* instances of delm to be treated
@@ -612,14 +614,19 @@ uint64_t parse_quote(char **s, char delm, int get_value, uint8_t dbg) {
}
}
}
- if (get_value && i < sizeof(uint64_t)) {
+ if (get_value && (buf != NULL || i < sizeof(uint64_t))) {
tmp_val[i] = c;
}
}
+ if (get_value && buf != NULL) {
+ tmp_val[i] = '\0';
+ }
+ //i = (get_value && buf != NULL && i > len) ? len : i;
+
*s = str;
- return value;
+ return (buf != NULL) ? ++i : value;
}
expr *make_expr(int type, uint64_t value, symbol *sym, uint8_t dbg) {
@@ -732,7 +739,7 @@ int get_expr_type(char **p, uint64_t address, void *val, int *found_reg, char st
break;
case PTOK_SQUOTE:
type = EXPR_CHAR;
- value = parse_quote(&str, *str, 1, dbg);
+ value = parse_quote(&str, *str, 1, NULL, dbg);
*(uint64_t *)val = value;
break;
case PTOK_AT:
@@ -1004,7 +1011,7 @@ uint64_t lex(char *str, uint64_t address, uint16_t bline, uint8_t dbg) {
do {
char *tmp = (str + i);
int get_value = (ptok == PTOK_SQUOTE);
- value = parse_quote(&tmp, str[i], get_value, dbg);
+ value = parse_quote(&tmp, str[i], get_value, NULL, dbg);
tmp--;
i++;
j = tmp - (str + i);