Aria

A low-level systems programming language
git clone git://git.m21c.me/Aria.git
Log | Files | Refs | LICENSE

commit e2273e5e06a0711763181533fc20568c3b2aeb9a
parent b17812965514313b0181ea905a1fe09f3fe3f7bb
Author: m21c  <ho*******@gmail.com>
Date:   Sat, 18 Sep 2021 20:43:56 +0200

fixed delimiter check

Diffstat:
Mcompiler.c | 62++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 34 insertions(+), 28 deletions(-)

diff --git a/compiler.c b/compiler.c @@ -1405,6 +1405,21 @@ skipwhite: #define skipnewline(source) \ ((source)->tok.kind == '\n' ? (void) gettok(source) : (void) 0) +static bool +isbasicdelimiter(Kind kind) { + switch ((int) kind) { + case 0: + case '\n': case ',': case ';': + case ':': + case ')': case ']': case '}': + case KELSE: + case KUNTIL: + return true; + } + + return false; +} + static Kind getunary(Source *source) { Kind kind = source->tok.kind; @@ -1423,6 +1438,20 @@ getunary(Source *source) { } } +static bool +isdelimiter(Kind kind) { + if (isbasicdelimiter(kind)) + return true; + + if (getunary(kind)) + return false; + + if (getnumops(kind)) + return true; + + return false; +} + static Kind getunarysuffix(Source *source) { Kind kind = source->tok.kind; @@ -1430,13 +1459,10 @@ getunarysuffix(Source *source) { if (getprec(kind) == PUNSUF) return kind; - /* TODO(m21c): check if this is correct: */ - switch (source->lastkind) { - case '\n': case ';': + /* NOTE(m21c): fixes parsing unary suffix across multiple lines. + * (which shouldn't happen) */ + if (isbasicdelimiter(source->lastkind)) return 0; - default: - break; - } switch (kind) { case '(': return OCALL; @@ -1844,24 +1870,6 @@ finish: } static bool -isnotatom(Source *source) { - switch ((int) getkind(source)) { - case 0: - case '\n': case ',': case ';': - case ':': - case ')': case ']': case '}': - case KELSE: - case KUNTIL: - return true; - } - - if (getnumops(getkind(source)) && getprec(getkind(source)) != PUNARY) - return true; - - return false; -} - -static bool checkend(Source *source, bool hastail, int needindent, const char *expecterrmsg) { @@ -1885,7 +1893,7 @@ checkend(Source *source, bool hastail, int needindent, } } - if (isnotatom(source)) + if (isdelimiter(source)) return true; if (hastail && source->lastkind != '\n' && source->lastkind != ';') @@ -2151,9 +2159,7 @@ readident(Source *source, int flags) { gettok(source); if (source->currenv->kind == SRECORD && !decl) { - int kind = getkind(source); - if (kind != ',' && kind != ';' && kind != '\n' && - kind != '\0' && kind != ')' && kind != ']' && kind != '}') { + if (isbasicdelimiter(getkind(source))) { decl = defertypedeclaration(source, key); decl->loc = loc; }