aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/parsedecl.c2
-rw-r--r--bootstrap/parsespec.c9
-rw-r--r--bootstrap/parsestmt.c5
-rw-r--r--bootstrap/token.c18
-rw-r--r--bootstrap/token.h1
5 files changed, 23 insertions, 12 deletions
diff --git a/bootstrap/parsedecl.c b/bootstrap/parsedecl.c
index 953d14e..e1ad680 100644
--- a/bootstrap/parsedecl.c
+++ b/bootstrap/parsedecl.c
@@ -74,7 +74,7 @@ void parse_file(FILE *f, const char *basename)
t = tokenize(&li);
switch ((int)t) {
case T_EOL:
- /* E.g. line with only a comment */
+ assert(0); /* tokenizer_next_line skips blank lines */
break;
case T_KW_func:
/* XXX should top-level functions (outside a class) be allowed? */
diff --git a/bootstrap/parsespec.c b/bootstrap/parsespec.c
index 1fa9626..3116d86 100644
--- a/bootstrap/parsespec.c
+++ b/bootstrap/parsespec.c
@@ -126,11 +126,10 @@ void parse_versions_section(void)
for (;;) {
struct LexemeInfo li;
enum Token t = tokenize(&li);
- if (t == T_EOL) {
- if (!tokenizer_next_line()) {
- break; /* EOF */
- }
- continue; /* Blank line */
+ if (t == T_EOL) { /* End of file */
+ bool eof = !tokenizer_next_line();
+ assert(eof);
+ break;
} else if (t != T_Version) {
if (tokenizer_line_is_indented()) {
error("Unexpected token in `versions` section "
diff --git a/bootstrap/parsestmt.c b/bootstrap/parsestmt.c
index d5a94c1..59ab6da 100644
--- a/bootstrap/parsestmt.c
+++ b/bootstrap/parsestmt.c
@@ -186,11 +186,8 @@ static struct Stmt *parse_statement(enum Token t)
}
} else if (t == T_KW_end) {
break;
- } else if (t == T_EOL) {
- /* Empty / comment-only lines are allowed */
- expect_next_line();
- t = tokenize(&li);
} else {
+ assert(t != T_EOL);
error("Expected `case`, `default` or `end` "
"in `switch` block");
}
diff --git a/bootstrap/token.c b/bootstrap/token.c
index 1b63405..07c7416 100644
--- a/bootstrap/token.c
+++ b/bootstrap/token.c
@@ -40,6 +40,20 @@ void tokenizer_init(FILE *file)
s = NULL;
}
+static bool line_has_contents(void)
+{
+ const char *p = line;
+ char c;
+
+ do {
+ c = *(p++);
+ if (c == '\n' || c == '\r' || c == '#') {
+ return false;
+ }
+ } while (c == ' ' && c == '\t');
+ return true;
+}
+
bool tokenizer_next_line(void)
{
int ignorelevel = 0;
@@ -72,7 +86,7 @@ bool tokenizer_next_line(void)
error("Suspiciously deep ignore block. Aborting");
}
ignore_just_started = true;
- } else if (!ignorelevel) {
+ } else if (!ignorelevel && line_has_contents()) {
return true;
} else {
if (!strcmp(line, "end") ||
@@ -480,7 +494,7 @@ void unread_token(void)
void unread_line(void)
{
- has_unread_line = true;
+ has_unread_line = line_has_contents(); /* false on EOF */
s = line;
last_token_start = NULL;
}
diff --git a/bootstrap/token.h b/bootstrap/token.h
index dfa1ca3..61a66e2 100644
--- a/bootstrap/token.h
+++ b/bootstrap/token.h
@@ -134,6 +134,7 @@ struct LexemeInfo {
extern bool tokenize_numbers_as_versions;
void tokenizer_init(FILE *f);
+/** Reads the next line. Skips lines without tokens. Returns false on EOF */
bool tokenizer_next_line(void);
bool tokenizer_line_is_indented(void);
enum Token tokenize(struct LexemeInfo *li_out);