aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--src/include/doer.h18
-rw-r--r--src/lexer.c5
-rw-r--r--src/parser.c51
-rw-r--r--src/pp.c15
-rw-r--r--src/tree.c47
6 files changed, 87 insertions, 51 deletions
diff --git a/Makefile b/Makefile
index 4de7e60..6d53b86 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ PREFIX := /usr/local/bin
CC := gcc
REG_CFLAGS := -ansi -O3 -s
DBG_CFLAGS := -ansi -Og -ggdb -pedantic
-DBG_CFLAGS += -Wall -Wextra -Wformat
+DBG_CFLAGS += -Wall -Wextra -Wformat -Werror -Wpedantic
DBG_CFLAGS += -fsanitize=leak,address,undefined -fno-omit-frame-pointer
CFLAGS := $(REG_CFLAGS)
SRCS := $(wildcard src/*.c)
diff --git a/src/include/doer.h b/src/include/doer.h
index f527114..a672f88 100644
--- a/src/include/doer.h
+++ b/src/include/doer.h
@@ -20,14 +20,14 @@ void doer_destroy(doer_t* doer);
void doer_do_blin_print(char* s);
-tree_t* doer_do_block(doer_t* doer);
-tree_t* doer_do_expr(doer_t* doer);
-tree_t* doer_do_lint(doer_t* doer);
-tree_t* doer_do_lstr(doer_t* doer);
-tree_t* doer_do_tag(doer_t* doer);
-tree_t* doer_do_darg(doer_t* doer);
-tree_t* doer_do_carg(doer_t* doer);
-tree_t* doer_do_def(doer_t* doer);
-tree_t* doer_do_call(doer_t* doer);
+void doer_do_block(tree_t* tree);
+void doer_do_expr(tree_t* tree);
+void doer_do_lint(tree_t* tree);
+void doer_do_lstr(tree_t* tree);
+void doer_do_tag(tree_t* tree);
+void doer_do_darg(tree_t* tree);
+void doer_do_carg(tree_t* tree);
+void doer_do_def(tree_t* tree);
+void doer_do_call(tree_t* tree);
#endif
diff --git a/src/lexer.c b/src/lexer.c
index e6a083b..13892a5 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -145,7 +145,7 @@ void lexer_do_str(lexer_t* lexer) {
void lexer_do_int(lexer_t* lexer) {
if (isdigit(*lexer->src)) {
lexer_add_current_char_to_last_token(lexer, TOKEN_INT);
- if (! isdigit(*(lexer->src + 1))) { lexer->state = LEXER_STATE_REG; }
+ ! isdigit(*(lexer->src + 1)) && ( lexer->state = LEXER_STATE_REG );
} else {
log_err("int state at non-int token");
}
@@ -154,7 +154,8 @@ void lexer_do_int(lexer_t* lexer) {
void lexer_do_kwd(lexer_t* lexer) {
if (strchr(SYNTAX_KWD_CHARS, *lexer->src)) {
lexer_add_current_char_to_last_token(lexer, TOKEN_KWD);
- if (! strchr(SYNTAX_KWD_CHARS, *(lexer->src + 1))) { lexer->state = LEXER_STATE_REG; }
+ ! strchr(SYNTAX_KWD_CHARS, *(lexer->src + 1)) &&
+ ( lexer->state = LEXER_STATE_REG );
} else {
log_err("keyword state at non-keyword token");
}
diff --git a/src/parser.c b/src/parser.c
index 7b9dbaa..ac4dfa6 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -86,16 +86,21 @@ tree_t* parser_parse_expr(parser_t* parser) {
}
tree_t* parser_parse_block(parser_t* parser) {
- if (!parser->token || parser->token->type == TOKEN_EXPR_END || parser->token->type == TOKEN_RBLOCK) { return NULL; }
+ if (
+ !parser->token ||
+ parser->token->type == TOKEN_EXPR_END ||
+ parser->token->type == TOKEN_RBLOCK
+ ) { return NULL; }
tree_t* block;
block = tree_init(TREE_TYPE_BLOCK);
block->data.block.val = parser_parse_expr(parser);
- block->data.block.nxt = parser_nxt_token_match(parser, TOKEN_EXPR_END) && parser_nxt_token(parser) ?
- parser_parse_block(parser) :
- NULL;
+ block->data.block.nxt = parser_nxt_token_match(parser, TOKEN_EXPR_END) &&
+ parser_nxt_token(parser) ?
+ parser_parse_block(parser) :
+ NULL;
return block;
}
@@ -109,7 +114,11 @@ tree_t* parser_parse_tag(parser_t* parser) {
tag->data.tag.val = parser->token->val;
parser->token->val = NULL;
- tag->data.tag.nxt = (parser_nxt_token(parser) ? parser_parse_tag(parser) : NULL);
+ tag->data.tag.nxt = (
+ parser_nxt_token(parser) ?
+ parser_parse_tag(parser) :
+ NULL
+ );
return tag;
}
@@ -125,8 +134,12 @@ tree_t* parser_parse_darg(parser_t* parser) {
log_war("%d", parser->token->type);
- if (parser->token->type != TOKEN_LIST_DELIM) { darg->data.darg.nxt = NULL; }
- else { parser_nxt_token(parser) && (darg->data.darg.nxt = parser_parse_darg(parser)); }
+ if (parser->token->type != TOKEN_LIST_DELIM) {
+ darg->data.darg.nxt = NULL;
+ } else {
+ parser_nxt_token(parser) &&
+ (darg->data.darg.nxt = parser_parse_darg(parser));
+ }
return darg;
}
@@ -138,8 +151,12 @@ tree_t* parser_parse_def(parser_t* parser) {
def->data.def.tag = parser_parse_tag(parser);
- parser->token->type == TOKEN_APPLY && parser_nxt_token(parser) && (def->data.def.arg = parser_parse_darg(parser));
- parser->token->type == TOKEN_SET && parser_nxt_token(parser) && (def->data.def.val = parser_parse_expr(parser));
+ parser->token->type == TOKEN_APPLY &&
+ parser_nxt_token(parser) &&
+ ( def->data.def.arg = parser_parse_darg(parser) );
+ parser->token->type == TOKEN_SET &&
+ parser_nxt_token(parser) &&
+ ( def->data.def.val = parser_parse_expr(parser) );
return def;
}
@@ -150,7 +167,12 @@ tree_t* parser_parse_carg(parser_t* parser) {
carg = tree_init(TREE_TYPE_CARG);
carg->data.carg.val = parser_parse_expr(parser);
- carg->data.carg.nxt = (parser_nxt_token_match(parser, TOKEN_LIST_DELIM) && parser_nxt_token(parser) ? parser_parse_carg(parser) : NULL);
+ carg->data.carg.nxt = (
+ parser_nxt_token_match(parser, TOKEN_LIST_DELIM) &&
+ parser_nxt_token(parser) ?
+ parser_parse_carg(parser) :
+ NULL
+ );
return carg;
}
@@ -162,8 +184,13 @@ tree_t* parser_parse_call(parser_t* parser) {
call->data.call.target = parser->token->val;
parser->token->val = NULL;
- parser_nxt_token_match(parser, TOKEN_APPLY) || (call->data.call.arg = NULL);
- call->data.call.arg = (parser_nxt_token(parser) ? parser_parse_carg(parser) : NULL);
+ parser_nxt_token_match(parser, TOKEN_APPLY) ||
+ (call->data.call.arg = NULL);
+ call->data.call.arg = (
+ parser_nxt_token(parser) ?
+ parser_parse_carg(parser) :
+ NULL
+ );
return call;
}
diff --git a/src/pp.c b/src/pp.c
index 6664879..db37118 100644
--- a/src/pp.c
+++ b/src/pp.c
@@ -75,9 +75,18 @@ void pp_do_com(pp_t* pp) {
void pp_run(pp_t* pp) {
while (*pp->src) {
- if (pp->state == PP_STATE_REG) { pp_do_reg(pp); }
- else if (pp->state == PP_STATE_STR || pp->state == PP_STATE_ESC) { pp_do_str(pp); }
- else if (pp->state == PP_STATE_COM) { pp_do_com(pp); }
+ switch (pp->state) {
+ case PP_STATE_REG:
+ pp_do_reg(pp);
+ break;
+ case PP_STATE_STR:
+ case PP_STATE_ESC:
+ pp_do_str(pp);
+ break;
+ case PP_STATE_COM:
+ pp_do_com(pp);
+ break;
+ }
pp->src ++;
}
diff --git a/src/tree.c b/src/tree.c
index 5ae4944..8876e47 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -90,28 +90,27 @@ void tree_destroy(tree_t* tree) {
free(tree);
}
+/*
+ Every time I think there's a problem with the parser, it turns out it's
+ just this stupid tree print function.
+*/
void tree_print(tree_t* tree, int nest) {
- char* spaces;
- int ncolor;
- char* color;
- char* bcolor;
- int i;
-
- /* Aaahhh. */
- for(i=0,spaces=ecalloc(nest+1,sizeof(char)),spaces[nest]='\0';i<=nest-1;spaces[i++]=' ');
- ncolor=31+nest%6;
- color=malloc(9*sizeof(char));
- bcolor=malloc(11*sizeof(char));
- sprintf(color,"\x1b[%dm",ncolor);
- sprintf(bcolor,"\x1b[%d;1m",ncolor);
-
- #define NEST0(TEXT) log_raw("%s%s"TEXT"\x1b[0m\n",bcolor,spaces);
- #define NEST1(TEXT) log_raw("%s%s"TEXT"\x1b[0m\n",color,spaces);
- #define NEST2(TEXT) log_raw("%s \x1b[39;49;4m%s\x1b[0m\n",spaces,TEXT);
- #define NEST3(TEXT) log_raw("%s \x1b[39;49;4m%d\x1b[0m\n",spaces,TEXT);
-
- if (!tree) { NEST2("NULL"); goto end; }
-
+ char*sp;int nc, i;char*c;char*bc;for(i
+ =0,sp=ecalloc(nest+1,sizeof(char)),sp[
+ nest]='\0';i<=nest-1;sp[i++]=' ');nc=0
+ +0x1f+nest%6;c=malloc(9*sizeof(char));
+ ;bc=malloc(11*sizeof(char));sprintf(c,
+ "\x1b[%dm",nc);sprintf(bc,"\x1b[%d;1m"
+ ,nc);NULL;NULL;0x0;0;0;0;0;NULL;0x0;0;
+ #define NEST0(T)log_raw("%s%s"T"\x1b"\
+ """""""""""""""""""""""""[0m\n",bc,sp)
+ #define NEST1(T)log_raw("%s%s"T"\x1b"\
+ """""""""""""""""""""""""[0m\n",c,sp);
+ #define NEST2(T)log_raw("%s \x1b[39;"\
+ """""""""""""""49;4m%s\x1b[0m\n",sp,T)
+ #define NEST3(T)log_raw("%s \x1b[39;"\
+ """""""""""""""49;4m%d\x1b[0m\n",sp,T)
+ if (!tree) { NEST2("NULL"); goto end;}
switch (tree->type) {
case TREE_TYPE_BLOCK:
NEST0("[block]");
@@ -179,8 +178,8 @@ void tree_print(tree_t* tree, int nest) {
}
end:
- free(spaces);
- free(color);
- free(bcolor);
+ free(sp);
+ free(c);
+ free(bc);
return;
}