make error messages a little less idoitic

This commit is contained in:
icst 2024-06-21 20:03:59 -04:00
parent 07c5f2fc15
commit 0ab9807349

39
lapis.c
View file

@ -4,6 +4,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
struct lapis_node_s;
@ -363,7 +364,7 @@ lapis_node_t *lapis_parse_expr(size_t *nnodes, FILE *f) {
switch (prod) {
default:
fputs("ERROR: unknown priority for operator '", stderr);
fprintf(stderr, "ERROR[%d]: unknown priority for operator '", __LINE__);
fwrite(tokens[n].str, 1, tokens[n].len, stderr);
fputs("'\n", stderr);
goto ERROR;
@ -530,14 +531,23 @@ lapis_node_t *lapis_parse_expr(size_t *nnodes, FILE *f) {
}
if ( n == max_prior_idx || tokens[n].type == LAPIS_TTYPE_NONE ) {
printf("ERROR: bad logic line #%d\n", __LINE__);
fprintf(stderr, "ERROR[%d]: Found no valid LHS operand for operator: ", __LINE__);
fwrite(tokens[max_prior_idx].str, 1, tokens[max_prior_idx].len, stderr);
fputc('\n', stderr);
goto ERROR;
}
if ( tokens[n].type == LAPIS_TTYPE_OPER ) {
if ( oper_priorities[n] >= -1 ) {
printf("ERROR: bad logic line #%d\n", __LINE__);
fprintf(stderr, "ERROR[%d]: Attempted to take LHS as operand before evaluation!", __LINE__);
fputs(" lhs=", stderr);
fwrite(tokens[n].str, 1, tokens[n].len, stderr);
fputs(" operator=", stderr);
fwrite(tokens[max_prior_idx].str, 1, tokens[max_prior_idx].len, stderr);
fputc('\n', stderr);
goto ERROR;
}
@ -548,10 +558,7 @@ lapis_node_t *lapis_parse_expr(size_t *nnodes, FILE *f) {
// later lower priority dependent operators can find its node.
int64_t node_idx = -(oper_priorities[n] + 2);
if ( node_idx < 0 ) {
printf("ERROR: bad logic line #%d\n", __LINE__);
goto ERROR;
}
assert( node_idx > 0 );
node.lhs_idx = node_idx;
@ -583,14 +590,23 @@ lapis_node_t *lapis_parse_expr(size_t *nnodes, FILE *f) {
}
if ( n == max_prior_idx || tokens[n].type == LAPIS_TTYPE_NONE ) {
printf("ERROR: bad logic line #%d\n", __LINE__);
fprintf(stderr, "ERROR[%d]: Found no valid RHS operand for operator: ", __LINE__);
fwrite(tokens[max_prior_idx].str, 1, tokens[max_prior_idx].len, stderr);
fputc('\n', stderr);
goto ERROR;
}
if ( tokens[n].type == LAPIS_TTYPE_OPER ) {
if ( oper_priorities[n] >= -1 ) {
printf("ERROR: bad logic line #%d\n", __LINE__);
fprintf(stderr, "ERROR[%d]: Attempted to take RHS as operand before evaluation!", __LINE__);
fputs(" rhs=", stderr);
fwrite(tokens[n].str, 1, tokens[n].len, stderr);
fputs(" operator=", stderr);
fwrite(tokens[max_prior_idx].str, 1, tokens[max_prior_idx].len, stderr);
fputc('\n', stderr);
goto ERROR;
}
@ -601,10 +617,7 @@ lapis_node_t *lapis_parse_expr(size_t *nnodes, FILE *f) {
// later lower priority dependent operators can find its node.
int64_t node_idx = -(oper_priorities[n] + 2);
if ( node_idx < 0 ) {
printf("ERROR: bad logic line #%d\n", __LINE__);
goto ERROR;
}
assert( node_idx > 0 );
node.rhs_idx = node_idx;