frontend: move token printing code to a separate file
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#include "../debug.h"
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
|
|
||||||
#include <blue/cmd.h>
|
#include <blue/cmd.h>
|
||||||
@@ -46,64 +47,7 @@ static int compile_file(const char *path)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (tok->t_type) {
|
print_lex_token(tok);
|
||||||
case IVY_TOK_KEYWORD:
|
|
||||||
b_fputs("[magenta]", stdout);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_SYMBOL:
|
|
||||||
b_fputs("[blue]", stdout);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_ATOM:
|
|
||||||
b_fputs("[yellow]", stdout);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_NUMBER:
|
|
||||||
b_fputs("[yellow]", stdout);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_LABEL:
|
|
||||||
b_fputs("[red]", stdout);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_IDENT:
|
|
||||||
b_fputs("[cyan]", stdout);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_STRING:
|
|
||||||
b_fputs("[green]", stdout);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_STR_START:
|
|
||||||
b_fputs("[green]", stdout);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_STR_END:
|
|
||||||
b_fputs("[green]", stdout);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_LINEFEED:
|
|
||||||
b_fputs("[bright,black]", stdout);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%s", ivy_lex_token_type_to_string(tok->t_type));
|
|
||||||
|
|
||||||
switch (tok->t_type) {
|
|
||||||
case IVY_TOK_IDENT:
|
|
||||||
case IVY_TOK_LABEL:
|
|
||||||
case IVY_TOK_STRING:
|
|
||||||
case IVY_TOK_ATOM:
|
|
||||||
printf("(%s)", tok->t_str);
|
|
||||||
break;
|
|
||||||
case IVY_TOK_SYMBOL:
|
|
||||||
printf("(%s)", ivy_symbol_to_string(tok->t_symbol));
|
|
||||||
break;
|
|
||||||
case IVY_TOK_KEYWORD:
|
|
||||||
printf("(%s)", ivy_keyword_to_string(tok->t_keyword));
|
|
||||||
break;
|
|
||||||
case IVY_TOK_NUMBER:
|
|
||||||
printf("(%llu)", tok->t_number);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
b_fputs("[reset]\n", stdout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = (status == IVY_OK || status == IVY_ERR_EOF) ? 0 : -1;
|
int r = (status == IVY_OK || status == IVY_ERR_EOF) ? 0 : -1;
|
||||||
|
|||||||
65
frontend/debug.c
Normal file
65
frontend/debug.c
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#include <blue/term.h>
|
||||||
|
#include <ivy/lang/lex.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern void print_lex_token(struct ivy_token *tok)
|
||||||
|
{
|
||||||
|
switch (tok->t_type) {
|
||||||
|
case IVY_TOK_KEYWORD:
|
||||||
|
b_fputs("[magenta]", stdout);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_SYMBOL:
|
||||||
|
b_fputs("[blue]", stdout);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_ATOM:
|
||||||
|
b_fputs("[yellow]", stdout);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_NUMBER:
|
||||||
|
b_fputs("[yellow]", stdout);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_LABEL:
|
||||||
|
b_fputs("[red]", stdout);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_IDENT:
|
||||||
|
b_fputs("[cyan]", stdout);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_STRING:
|
||||||
|
b_fputs("[green]", stdout);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_STR_START:
|
||||||
|
b_fputs("[green]", stdout);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_STR_END:
|
||||||
|
b_fputs("[green]", stdout);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_LINEFEED:
|
||||||
|
b_fputs("[bright,black]", stdout);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s", ivy_lex_token_type_to_string(tok->t_type));
|
||||||
|
|
||||||
|
switch (tok->t_type) {
|
||||||
|
case IVY_TOK_IDENT:
|
||||||
|
case IVY_TOK_LABEL:
|
||||||
|
case IVY_TOK_STRING:
|
||||||
|
case IVY_TOK_ATOM:
|
||||||
|
printf("(%s)", tok->t_str);
|
||||||
|
break;
|
||||||
|
case IVY_TOK_SYMBOL:
|
||||||
|
printf("(%s)", ivy_symbol_to_string(tok->t_symbol));
|
||||||
|
break;
|
||||||
|
case IVY_TOK_KEYWORD:
|
||||||
|
printf("(%s)", ivy_keyword_to_string(tok->t_keyword));
|
||||||
|
break;
|
||||||
|
case IVY_TOK_NUMBER:
|
||||||
|
printf("(%llu)", tok->t_number);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
b_fputs("[reset]\n", stdout);
|
||||||
|
}
|
||||||
8
frontend/debug.h
Normal file
8
frontend/debug.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef DEBUG_H_
|
||||||
|
#define DEBUG_H_
|
||||||
|
|
||||||
|
struct ivy_token;
|
||||||
|
|
||||||
|
extern void print_lex_token(struct ivy_token *tok);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user