accept_t lexer_read_line(struct lexer_book * bk) { char c = lexer_next_peek(bk); int colon, equal; bk->substitution_mode = ROOT; switch (c) { case CHAR_EOF: /* Found end of file */ lexer_next_char(bk); return YES; break; case '#': lexer_discard_comments(bk); return YES; break; case '\t': bk->substitution_mode = COMMAND; return lexer_read_command(bk); break; case ' ': /* Eat whitespace and try again */ lexer_discard_white_space(bk); return lexer_read_line(bk); break; case '\n': /* Ignore empty lines and try again */ lexer_next_char(bk); return lexer_read_line(bk); break; case '@': /* Jump @ */ bk->substitution_mode = SYNTAX; lexer_next_char(bk); return lexer_read_syntax(bk); break; default: /* Either makeflow keyword (e.g. export), a file list, or variable assignment */ lexer_discard_white_space(bk); colon = lexer_unquoted_look_ahead_count(bk, ":"); equal = lexer_unquoted_look_ahead_count(bk, "="); fprintf(stderr, "%d %d %c\n", colon, equal, c); if((colon != -1) && (equal == -1 || colon < equal)) { bk->substitution_mode = FILES; return lexer_read_file_list(bk); } else { bk->substitution_mode = SYNTAX; return lexer_read_syntax(bk); } break; } }
int lexer_read_line(struct lexer * lx) { char c = lexer_next_peek(lx); int colon, equal; switch (c) { case CHAR_EOF: /* Found end of file */ return lexer_next_char(lx); break; case '#': lexer_discard_comments(lx); return 1; break; case '\t': return lexer_read_command(lx); break; case '\n': /* Ignore empty lines and try again */ lexer_next_char(lx); return lexer_read_line(lx); break; case '@': /* Jump @ */ lexer_next_char(lx); return lexer_read_syntax_or_variable(lx); break; default: /* Either makeflow keyword (e.g. export), a file list, or variable assignment */ lexer_discard_white_space(lx); colon = lexer_unquoted_look_ahead_count(lx, ":"); equal = lexer_unquoted_look_ahead_count(lx, "="); /* If there is a colon and it appears before any existing * equal sign read the line as a file list. */ if((colon != -1) && (equal == -1 || colon < equal)) { lexer_read_file_list(lx); } else if(c == ' ' && equal == -1) { /* A command starting with a space.. for backwards compatibility. */ return lexer_read_command(lx); } else { lexer_read_syntax_or_variable(lx); } return 1; break; } }
accept_t lexer_read_syntax(struct lexer_book * bk) { lexer_discard_white_space(bk); struct token *name = lexer_read_syntax_name(bk); if(strcmp("export", name->lexeme) == 0) return lexer_read_syntax_export(bk, name); else if(lexer_unquoted_look_ahead_count(bk, "=") > -1) return lexer_read_variable(bk, name); else { lexer_roll_back(bk, strlen(name->lexeme)); lexer_report_error(bk, "Unrecognized keyword: %s.", name->lexeme); } return NO; }
accept_t lexer_read_syntax_export(struct lexer_book *bk, struct token *name) { lexer_discard_white_space(bk); name->type = SYNTAX; lexer_push_token(bk, name); if(lexer_unquoted_look_ahead_count(bk, "=") > -1) return lexer_read_variable(bk, lexer_read_syntax_name(bk)); else return lexer_read_variable_list(bk); return YES; }
int lexer_read_syntax_or_variable(struct lexer * lx) { lexer_discard_white_space(lx); struct token *name = lexer_read_syntax_name(lx); if(strcmp("export", name->lexeme) == 0) return lexer_read_syntax_export(lx, name); else if(lexer_unquoted_look_ahead_count(lx, "=") > -1) return lexer_read_variable(lx, name); else { lexer_roll_back(lx, strlen(name->lexeme)); lexer_report_error(lx, "Unrecognized keyword: %s.", name->lexeme); } return 1; }
int lexer_read_syntax_export(struct lexer *lx, struct token *name) { lexer_discard_white_space(lx); //name->lexeme is "export" name->type = TOKEN_SYNTAX; lexer_push_token(lx, name); if(lexer_unquoted_look_ahead_count(lx, "=") > -1) lexer_read_variable(lx, lexer_read_syntax_name(lx)); else lexer_read_variable_list(lx); lexer_push_token(lx, lexer_pack_token(lx, TOKEN_NEWLINE)); return 1; }