aboutsummaryrefslogtreecommitdiffstats
path: root/src/bootstrap/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/main.c')
-rwxr-xr-xsrc/bootstrap/main.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/bootstrap/main.c b/src/bootstrap/main.c
index 113ee48..dadc887 100755
--- a/src/bootstrap/main.c
+++ b/src/bootstrap/main.c
@@ -5,11 +5,18 @@
5 5
6#include "string_view.c" 6#include "string_view.c"
7#include "read_line.c" 7#include "read_line.c"
8#include "errors.c"
8#include "lexer.c" 9#include "lexer.c"
9 10
10void 11void
11process_source(const StringView *source) { 12process_source(const StringView *source) {
12 Tokens tokens = tokenize(source); 13 Tokens tokens = tokenize(source);
14 if (errors_n != 0) {
15 if (tokens.buf != NULL) {
16 free(tokens.buf);
17 }
18 return;
19 }
13 20
14 // Print tokens. 21 // Print tokens.
15 for (size_t i = 0; i < tokens.size; i++) { 22 for (size_t i = 0; i < tokens.size; i++) {
@@ -17,7 +24,9 @@ process_source(const StringView *source) {
17 print_token(tok); 24 print_token(tok);
18 } 25 }
19 26
20 free(tokens.buf); 27 if (tokens.buf != NULL) {
28 free(tokens.buf);
29 }
21} 30}
22 31
23#define REPL_PROMPT "bdl> " 32#define REPL_PROMPT "bdl> "
@@ -32,6 +41,24 @@ run_repl(void) {
32 return; 41 return;
33 } 42 }
34 process_source(&sv); 43 process_source(&sv);
44
45 // Check if there were any errors.
46 if (errors_n != 0) {
47 for (size_t i = 0; i < errors_n; i++) {
48 Error err = errors[i];
49 for (size_t j = 0; j < err.col + sizeof(REPL_PROMPT) - 2; j++) {
50 putchar(' ');
51 }
52 printf("|\n");
53 for (size_t j = 0; j < err.col + sizeof(REPL_PROMPT) - 2; j++) {
54 putchar(' ');
55 }
56 printf("%s\n", error_msgs[err.value]);
57 }
58 errors_n = 0;
59 continue;
60 }
61
35 if (sv.n != 0) { 62 if (sv.n != 0) {
36 printf("\n"); 63 printf("\n");
37 } 64 }
@@ -62,6 +89,19 @@ run_file(char *file_name) {
62 89
63 process_source(&sv); 90 process_source(&sv);
64 91
92 // Check if there were any errors.
93 if (errors_n != 0) {
94 for (size_t i = 0; i < errors_n; i++) {
95 Error err = errors[i];
96 printf("%s", file_name);
97 if (err.line != 0) {
98 printf(":%ld:%ld", err.line, err.col);
99 }
100 printf("%s\n", error_msgs[err.value]);
101 }
102 errors_n = 0;
103 }
104
65 free(source); 105 free(source);
66 fclose(file); 106 fclose(file);
67} 107}
@@ -91,6 +131,19 @@ run_stdin(void) {
91 131
92 process_source(&sv); 132 process_source(&sv);
93 133
134 // Check if there were any errors.
135 if (errors_n != 0) {
136 for (size_t i = 0; i < errors_n; i++) {
137 Error err = errors[i];
138 printf("stdin");
139 if (err.line != 0) {
140 printf(":%ld:%ld: ", err.line, err.col);
141 }
142 printf("%s\n", error_msgs[err.value]);
143 }
144 errors_n = 0;
145 }
146
94 free(source); 147 free(source);
95} 148}
96 149