Skip to content

Commit

Permalink
Make tok_last_type return an enum token_type instead of int
Browse files Browse the repository at this point in the history
  • Loading branch information
ridiculousfish committed Sep 30, 2013
1 parent 6c70ed7 commit cbe6152
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
6 changes: 5 additions & 1 deletion builtin_commandline.cpp
Expand Up @@ -169,7 +169,11 @@ static void write_part(const wchar_t *begin,
out.push_back(L'\n');
break;
}


default:
{
break;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions complete.cpp
Expand Up @@ -1915,6 +1915,11 @@ void complete(const wcstring &cmd, std::vector<completion_t> &comps, completion_
end_loop=1;
break;
}

default:
{
break;
}
}

if (tok_get_pos(&tok) >= (long)pos)
Expand Down
5 changes: 5 additions & 0 deletions parse_util.cpp
Expand Up @@ -381,6 +381,11 @@ static void job_or_process_extent(const wchar_t *buff,

break;
}

default:
{
break;
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions parser.cpp
Expand Up @@ -154,7 +154,7 @@ The fish parser. Contains functions for parsing and evaluating code.
/**
Error message for Posix-style assignment
*/
#define COMMAND_ASSIGN_ERR_MSG _( L"Unknown command '%ls'. Did you mean 'set %ls %ls'? For information on assigning values to variables, see the help section on the set command by typing 'help set'.")
#define COMMAND_ASSIGN_ERR_MSG _( L"Unknown command '%ls'. Did you mean 'set %ls %ls'? See the help section on the set command by typing 'help set'.")

/**
Error for invalid redirection token
Expand Down Expand Up @@ -2012,8 +2012,9 @@ int parser_t::parse_job(process_t *p,
if (! has_command && ! use_implicit_cd)
{

int tmp;
const wchar_t *cmd = args.at(0).completion.c_str();

fprintf(stderr, "arg count: %lu\n", args.size());

/*
We couldn't find the specified command.
Expand Down Expand Up @@ -2095,7 +2096,7 @@ int parser_t::parse_job(process_t *p,
event_fire_generic(L"fish_command_not_found", &event_args);
}

tmp = current_tokenizer_pos;
int tmp = current_tokenizer_pos;
current_tokenizer_pos = tok_get_pos(tok);

fwprintf(stderr, L"%ls", parser_t::current_line());
Expand Down
7 changes: 7 additions & 0 deletions reader.cpp
Expand Up @@ -2331,6 +2331,13 @@ static void handle_token_history(int forward, int reset)

}
}
break;

default:
{
break;
}

}
}
}
Expand Down
14 changes: 7 additions & 7 deletions tokenizer.cpp
Expand Up @@ -93,7 +93,7 @@ int tok_get_error(tokenizer_t *tok)
}


tokenizer_t::tokenizer_t(const wchar_t *b, tok_flags_t flags) : buff(NULL), orig_buff(NULL), last_type(0), last_pos(0), has_next(false), accept_unfinished(false), show_comments(false), last_quote(0), error(0), squash_errors(false), cached_lineno_offset(0), cached_lineno_count(0)
tokenizer_t::tokenizer_t(const wchar_t *b, tok_flags_t flags) : buff(NULL), orig_buff(NULL), last_type(TOK_NONE), last_pos(0), has_next(false), accept_unfinished(false), show_comments(false), last_quote(0), error(0), squash_errors(false), cached_lineno_offset(0), cached_lineno_count(0)
{

/* We can only generate error messages on the main thread due to wgettext() thread safety issues. */
Expand All @@ -116,7 +116,7 @@ tokenizer_t::tokenizer_t(const wchar_t *b, tok_flags_t flags) : buff(NULL), orig
tok_next(this);
}

int tok_last_type(tokenizer_t *tok)
enum token_type tok_last_type(tokenizer_t *tok)
{
CHECK(tok, TOK_ERROR);
CHECK(tok->buff, TOK_ERROR);
Expand Down Expand Up @@ -440,7 +440,7 @@ static void read_comment(tokenizer_t *tok)
*/
static void read_redirect(tokenizer_t *tok, int fd)
{
int mode = -1;
enum token_type redirection_mode = TOK_NONE;

if ((*tok->buff == L'>') ||
(*tok->buff == L'^'))
Expand All @@ -449,11 +449,11 @@ static void read_redirect(tokenizer_t *tok, int fd)
if (*tok->buff == *(tok->buff-1))
{
tok->buff++;
mode = 1;
redirection_mode = TOK_REDIRECT_APPEND;
}
else
{
mode = 0;
redirection_mode = TOK_REDIRECT_OUT;
}

if (*tok->buff == L'|')
Expand All @@ -472,7 +472,7 @@ static void read_redirect(tokenizer_t *tok, int fd)
else if (*tok->buff == L'<')
{
tok->buff++;
mode = 2;
redirection_mode = TOK_REDIRECT_IN;
}
else
{
Expand All @@ -493,7 +493,7 @@ static void read_redirect(tokenizer_t *tok, int fd)
}
else
{
tok->last_type = TOK_REDIRECT_OUT + mode;
tok->last_type = redirection_mode;
}
}

Expand Down
5 changes: 2 additions & 3 deletions tokenizer.h
Expand Up @@ -77,7 +77,7 @@ struct tokenizer_t
wcstring last_token;

/** Type of last token*/
int last_type;
enum token_type last_type;

/** Offset of last token*/
size_t last_pos;
Expand Down Expand Up @@ -123,7 +123,7 @@ void tok_next(tokenizer_t *tok);
/**
Returns the type of the last token. Must be one of the values in the token_type enum.
*/
int tok_last_type(tokenizer_t *tok);
enum token_type tok_last_type(tokenizer_t *tok);

/**
Returns the last token string. The string should not be freed by the caller.
Expand All @@ -150,7 +150,6 @@ int tok_get_pos(tokenizer_t *tok);
*/
const wchar_t *tok_string(tokenizer_t *tok);


/**
Returns only the first token from the specified string. This is a
convenience function, used to retrieve the first token of a
Expand Down

0 comments on commit cbe6152

Please sign in to comment.