summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basic.c68
1 files changed, 48 insertions, 20 deletions
diff --git a/src/basic.c b/src/basic.c
index e6eb4bb..d823ec7 100644
--- a/src/basic.c
+++ b/src/basic.c
@@ -28,6 +28,10 @@ static inline enum zx_basic_token_type zx_basic_token_type_get(uint8_t b) {
return ZX81_BASIC_TOKEN_ALNUM;
} else if (codepoint == '"') {
return ZX81_BASIC_TOKEN_QUOTE;
+ } else if (codepoint == '(') {
+ return ZX81_BASIC_TOKEN_PAREN_OPEN;
+ } else if (codepoint == ')') {
+ return ZX81_BASIC_TOKEN_PAREN_CLOSE;
} else {
return ZX81_BASIC_TOKEN_SYMBOL;
}
@@ -43,6 +47,10 @@ static inline enum zx_basic_token_type zx_basic_token_type_get(uint8_t b) {
} else {
return ZX81_BASIC_TOKEN_SYMBOL;
}
+ } else if (ZX81_CHAR_TOKEN_INTEGRAL(b)) {
+ return ZX81_BASIC_TOKEN_INTEGRAL;
+ } else if (ZX81_CHAR_TOKEN_FLOAT(b)) {
+ return ZX81_BASIC_TOKEN_FLOAT;
}
return ZX81_BASIC_TOKEN_UNKNOWN;
@@ -114,22 +122,44 @@ ssize_t zx81_basic_dump(int fd, FILE *stream) {
int space = 0;
- if (type == ZX_BASIC_TOKEN_ALNUM) {
- if (type_last == ZX_BASIC_TOKEN_WORD) {
- space = 1;
- }
- } else if (type == ZX_BASIC_TOKEN_QUOTE) {
- if (type_last == ZX_BASIC_TOKEN_WORD) {
- space = 1;
- }
- } else if (type == ZX_BASIC_TOKEN_SYMBOL) {
- space = 0;
- } else if (type == ZX_BASIC_TOKEN_WORD) {
- if (type_last != ZX_BASIC_TOKEN_SYMBOL) {
- space = 1;
- }
- } else if (ZX81_CHAR_TOKEN_INTEGRAL(c) || ZX81_CHAR_TOKEN_FLOAT(c)) {
- i += 5;
+ switch (type) {
+ case ZX81_BASIC_TOKEN_ALNUM:
+ if (type_last == ZX81_BASIC_TOKEN_WORD)
+ space = 1;
+
+ break;
+
+ case ZX81_BASIC_TOKEN_QUOTE:
+ if (type_last == ZX81_BASIC_TOKEN_WORD)
+ space = 1;
+
+ break;
+
+ case ZX81_BASIC_TOKEN_PAREN_OPEN:
+ if (type_last == ZX81_BASIC_TOKEN_WORD)
+ space = 1;
+
+ break;
+
+ case ZX81_BASIC_TOKEN_PAREN_CLOSE:
+ case ZX81_BASIC_TOKEN_SYMBOL:
+ space = 0;
+ break;
+
+ case ZX81_BASIC_TOKEN_WORD:
+ if (type_last != ZX81_BASIC_TOKEN_SYMBOL
+ && type_last != ZX81_BASIC_TOKEN_PAREN_OPEN)
+ space = 1;
+
+ break;
+
+ case ZX81_BASIC_TOKEN_INTEGRAL:
+ case ZX81_BASIC_TOKEN_FLOAT:
+ i += 5;
+ break;
+
+ case ZX81_BASIC_TOKEN_UNKNOWN:
+ continue;
}
if (space && fputc(' ', stream) < 0) {
@@ -143,10 +173,8 @@ ssize_t zx81_basic_dump(int fd, FILE *stream) {
last = c;
}
- if (!ZX81_CHAR_NEWLINE(((uint8_t *)buf)[i-1])) {
- if (fputc('\n', stream) < 0) {
- goto error_io;
- }
+ if (fputc('\n', stream) < 0) {
+ goto error_io;
}
}