示例#1
0
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;
    }

}
示例#2
0
文件: lexer.c 项目: NeilB879/cctools
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;
	}
}
示例#3
0
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;
}
示例#4
0
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;
}
示例#5
0
文件: lexer.c 项目: NeilB879/cctools
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;
}
示例#6
0
文件: lexer.c 项目: NeilB879/cctools
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;
}