aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-06-21 02:04:37 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-06-21 02:04:37 +0200
commit5e384049170dcb9e7e8aae5e98729bbc26661f90 (patch)
tree26dfca606d4c55ca1917f7dd5da9eb211db82275 /src/parser.c
parent81ad5bea2fab5eec6c4d9a017f1acc5a53dbde47 (diff)
Huge changes to static analysis
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/parser.c b/src/parser.c
index 44888ae..5d9bf9c 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -10,6 +10,7 @@
#include "common.h"
#include "errors.h"
#include "parser.h"
+#include "strview.h"
#if DEBUG
# define AST_DFLT_CAP (8)
@@ -114,16 +115,17 @@ idx_t_
parsedecl(struct ast *ast, struct lexemes toks, bool toplvl)
{
idx_t_ i = astalloc(ast);
- ast->lexemes[i] = toksidx;
bool pub;
- if (toplvl && toks.kinds[toksidx] == LEXIDENT && toks.strs[toksidx].len == 3
- && memcmp("pub", toks.strs[toksidx].p, 3) == 0)
+ if (toplvl && toks.kinds[toksidx] == LEXIDENT
+ && strview_eq(SV("pub"), toks.strs[toksidx]))
{
pub = true;
- toksidx++;
- } else
+ ast->lexemes[i] = ++toksidx;
+ } else {
pub = false;
+ ast->lexemes[i] = toksidx;
+ }
if (toks.kinds[toksidx++] != LEXIDENT)
err("parser: Expected identifier");
@@ -230,7 +232,7 @@ parsestmt(struct ast *ast, struct lexemes toks)
err("parser: Expected identifier");
struct strview sv = toks.strs[toksidx];
- if (sv.len == 6 && memcmp(sv.p, "return", 6) == 0) {
+ if (strview_eq(SV("return"), sv)) {
i = astalloc(ast);
ast->lexemes[i] = toksidx++;
ast->kinds[i] = ASTRET;