Beispiel #1
0
accept_t lexer_read_variable(struct lexer_book * bk, struct token * name)
{
    lexer_discard_white_space(bk);

    if(lexer_next_peek(bk) == '=') {
        lexer_next_char(bk);
        lexer_add_to_lexeme(bk, '=');
    } else {
        int c = lexer_next_char(bk);
        if(lexer_next_peek(bk) != '=')
            return NO;
        lexer_add_to_lexeme(bk, c);
        lexer_next_char(bk);	/* Jump = */
    }

    lexer_push_token(bk, lexer_pack_token(bk, VARIABLE));
    lexer_push_token(bk, name);

    lexer_discard_white_space(bk);

    lexer_read_expandable(bk, '\n');
    lexer_roll_back(bk, 1);	//Recover '\n'

    lexer_discard_white_space(bk);

    if(lexer_next_char(bk) != '\n')
        return NO;

    return YES;
}
Beispiel #2
0
accept_t lexer_read_file_list(struct lexer_book *bk)
{
    int count = 0;

    lexer_discard_white_space(bk);

    struct token *t;
    do {
        t = lexer_read_file(bk);
        if(t->type == NEWLINE && count == 0) {
            return NO;
        } else if(t->type != NEWLINE && count == 0) {
            /* Add file list start marker */
            lexer_push_token(bk, lexer_pack_token(bk, FILES));
        }

        lexer_push_token(bk, t);
        count++;
    } while(t->type != NEWLINE);

    if(count > 1)
        return YES;
    else {
        return NO;
    }
}
Beispiel #3
0
accept_t lexer_read_command(struct lexer_book *bk)
{
    if(lexer_next_peek(bk) != '\t')
        return NO;

    int count = 0;

    lexer_discard_white_space(bk);

    struct token *t;
    do {
        t = lexer_read_command_argument(bk);
        if(!t)
            break;
        if(t->type == NEWLINE && count == 0) {
            lexer_report_error(bk, "Missing command line.\n");
        } else if(t->type != NEWLINE && count == 0) {
            /* Add command start marker */
            lexer_push_token(bk, lexer_pack_token(bk, COMMAND));
        }
        lexer_push_token(bk, t);
        count++;
    } while(t->type != NEWLINE);

    if(count > 1)
        return YES;
    else {
        return NO;
    }
}
Beispiel #4
0
int lexer_read_expandable_recursive(struct lexer_book *bk, char end_marker)
{
    int count = 0;
    lexer_discard_white_space(bk);

    while(!bk->eof) {
        int c = lexer_next_peek(bk);

        if(c == '$') {
            count++;
            lexer_push_token(bk, lexer_read_substitution(bk));
        }
        if(c == '\'') {
            lexer_read_literal(bk);
            lexer_push_token(bk, lexer_pack_token(bk, LITERAL));
        } else if(c == end_marker) {
            lexer_next_char(bk);	/* Jump end_marker */
            return count;
        } else if(c == '"')
            count += lexer_read_expandable_recursive(bk, '"');
        else if(c == '#' && end_marker != '"') {
            lexer_discard_comments(bk);
            return count;
        } else {
            count++;
            lexer_push_token(bk, lexer_read_literal_in_expandable_until(bk, end_marker));
        }
    }
    /* Found eof before end_marker */
    abort();
}
Beispiel #5
0
int lexer_read_variable(struct lexer *lx, struct token *name)
{
	lexer_discard_white_space(lx);

	if(lexer_next_peek(lx) == '=') {
		lexer_next_char(lx);
		lexer_add_to_lexeme(lx, '=');
	} else {
		int c = lexer_next_char(lx);
		if(lexer_next_peek(lx) != '=')
			lexer_report_error(lx, "Missing = in variable definition.");
		lexer_add_to_lexeme(lx, c);
		lexer_next_char(lx);	/* Jump = */
	}

	lexer_push_token(lx, lexer_pack_token(lx, TOKEN_VARIABLE));
	lexer_push_token(lx, name);

	lexer_discard_white_space(lx);

	//Read variable value
	lexer_push_token(lx, lexer_read_expandable(lx, '\n'));
	lexer_roll_back(lx, 1);	//Recover '\n'

	lexer_discard_white_space(lx);

	if(lexer_next_char(lx) != '\n')
		lexer_report_error(lx, "Missing newline at end of variable definition.");

	return 1;
}
Beispiel #6
0
struct token *lexer_read_expandable(struct lexer_book *bk, char end_marker)
{
    struct token *start = lexer_pack_token(bk, LEXPANDABLE);
    lexer_push_token(bk, start);
    lexer_read_expandable_recursive(bk, end_marker);
    lexer_push_token(bk, lexer_pack_token(bk, REXPANDABLE));

    return start;
}
Beispiel #7
0
int lexer_read_command(struct lexer *lx)
{
	struct list *tokens = lexer_read_command_aux(lx);

	struct token *t;

	if(list_size(tokens) < 2) {
		/* If the only token in the list is a NEWLINE, then this is an empty line. */
		while((t = list_pop_head(tokens)))
			lexer_free_token(t);

		list_delete(tokens);
		return 1;
	}

	/* Add command start marker.*/
	lexer_push_token(lx, lexer_pack_token(lx, TOKEN_COMMAND));


	/* Merge command tokens into main queue. */
	/* First merge command modifiers, if any. */
	list_first_item(tokens);
	while((t = list_peek_head(tokens))) {
		if(t->type == TOKEN_LITERAL &&
		   ((strcmp(t->lexeme, "LOCAL")    == 0) ||
			(strcmp(t->lexeme, "MAKEFLOW") == 0)    )) {
			t = list_pop_head(tokens);
			lexer_push_token(lx, t);
		} else if(t->type == TOKEN_SPACE) {
			//Discard spaces between modifiers.
			t = list_pop_head(tokens);
			lexer_free_token(t);
		} else {
			break;
		}
	}

	/* Mark end of modifiers. */
	lexer_push_token(lx, lexer_pack_token(lx, TOKEN_COMMAND_MOD_END));

	/* Now merge tha actual command tokens */

	/* Gives the number of actual command tokens, not taking into account command modifiers. */
	int count = 0;

	while((t = list_pop_head(tokens))) {
		count++;
		lexer_push_token(lx, t);
	}

	list_delete(tokens);

	if(count < 1)
		lexer_report_error(lx, "Command is empty.\n");

	return count;
}
Beispiel #8
0
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;
}
Beispiel #9
0
int lexer_read_variable_list(struct lexer * lx)
{
	int c;

	while((c = lexer_next_peek(lx)) != '\n') {
		lexer_discard_white_space(lx);
		if(c == '#') {
			lexer_discard_comments(lx);
			lexer_roll_back(lx, 1);	//Recover the newline
			break;
		}

		lexer_push_token(lx, lexer_read_syntax_name(lx));
	}

	lexer_add_to_lexeme(lx, lexer_next_char(lx));	//Drop the newline
	lexer_push_token(lx, lexer_pack_token(lx, TOKEN_NEWLINE));

	return 1;
}
Beispiel #10
0
accept_t lexer_read_variable_list(struct lexer_book * bk)
{
    int c;

    while((c = lexer_next_peek(bk)) != '\n') {
        lexer_discard_white_space(bk);
        if(c == '#') {
            lexer_discard_comments(bk);
            lexer_roll_back(bk, 1);	//Recover the newline
            break;
        }

        lexer_push_token(bk, lexer_read_syntax_name(bk));

    }

    lexer_add_to_lexeme(bk, lexer_next_char(bk));	//Drop the newline
    lexer_push_token(bk, lexer_pack_token(bk, NEWLINE));

    return YES;
}
Beispiel #11
0
int lexer_append_tokens(struct lexer *lx, struct list *tokens)
{
	struct token *t;
	int count = 0;

	list_first_item(tokens);
	while((t = list_pop_head(tokens))) {
		lexer_push_token(lx, t);
		count++;
	}

	return count;
}
Beispiel #12
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;
}
Beispiel #13
0
int lexer_read_file_list(struct lexer *lx)
{
	/* Add file list start marker */
	lexer_push_token(lx, lexer_pack_token(lx, TOKEN_FILES));

	struct list *tokens = lexer_read_file_list_aux(lx);

	lexer_concatenate_consecutive_literals(tokens);

	int count = lexer_append_tokens(lx, tokens);

	if(count < 1)
		lexer_report_error(lx, "Rule files specification is empty.\n");

	list_delete(tokens);

	return count;
}
Beispiel #14
0
void lexer_append_all_tokens(struct lexer_book *bk, struct lexer_book *bk_s)
{
	struct token *head_s;
	
	bk_s->substitution_mode = bk->substitution_mode;
	while( !bk_s->eof )
	{
		if(lexer_next_peek(bk_s) == CHAR_EOF)
		{
			/* Found end of string while completing command */
			bk_s->lexeme_end++;
			bk_s->eof = 1;
		}
		else
		{
			switch(bk_s->substitution_mode)
			{
			case CHAR_EOF:
			case COMMAND:
				head_s = lexer_read_command_argument(bk_s);
				break;
			case FILES:
				head_s = lexer_read_file(bk_s);
				break;
			case SYNTAX:
				lexer_read_expandable(bk_s, CHAR_EOF);
				head_s = lexer_pack_token(bk_s, LITERAL);
				break;
			default:
				lexer_read_line(bk_s);
				continue;
				break;
			}

			if(head_s)
				lexer_push_token(bk_s, head_s);
		}
	}

	while( (head_s = list_pop_tail(bk_s->token_queue)) != NULL )
		list_push_head(bk->token_queue, head_s);
}