2005-09-20 21:26:39 +08:00
|
|
|
/** \file parser.h
|
2012-11-18 18:23:22 +08:00
|
|
|
The fish parser.
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#ifndef FISH_PARSER_H
|
|
|
|
#define FISH_PARSER_H
|
|
|
|
|
|
|
|
#include <wchar.h>
|
|
|
|
|
|
|
|
#include "proc.h"
|
|
|
|
#include "util.h"
|
2006-02-01 23:49:11 +08:00
|
|
|
#include "event.h"
|
2012-02-08 14:10:35 +08:00
|
|
|
#include "function.h"
|
2012-01-17 03:09:19 +08:00
|
|
|
#include <vector>
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2006-10-02 00:02:58 +08:00
|
|
|
#define PARSER_TEST_ERROR 1
|
|
|
|
#define PARSER_TEST_INCOMPLETE 2
|
|
|
|
|
2006-01-24 04:40:14 +08:00
|
|
|
/**
|
2012-08-27 13:42:29 +08:00
|
|
|
event_blockage_t represents a block on events of the specified type
|
2006-01-24 04:40:14 +08:00
|
|
|
*/
|
2012-08-27 13:42:29 +08:00
|
|
|
struct event_blockage_t
|
2005-12-12 06:21:01 +08:00
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
/**
|
|
|
|
The types of events to block. This is interpreted as a bitset
|
|
|
|
whete the value is 1 for every bit corresponding to a blocked
|
|
|
|
event type. For example, if EVENT_VARIABLE type events should
|
|
|
|
be blocked, (type & 1<<EVENT_BLOCKED) should be set.
|
|
|
|
|
|
|
|
Note that EVENT_ANY can be used to specify any event.
|
|
|
|
*/
|
|
|
|
unsigned int typemask;
|
2012-02-08 13:04:51 +08:00
|
|
|
};
|
|
|
|
|
2012-08-27 13:42:29 +08:00
|
|
|
typedef std::list<event_blockage_t> event_blockage_list_t;
|
2012-02-08 13:04:51 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
inline bool event_block_list_blocks_type(const event_blockage_list_t &ebls, int type)
|
|
|
|
{
|
|
|
|
for (event_blockage_list_t::const_iterator iter = ebls.begin(); iter != ebls.end(); ++iter)
|
|
|
|
{
|
|
|
|
if (iter->typemask & (1<<EVENT_ANY))
|
2012-02-08 13:04:51 +08:00
|
|
|
return true;
|
2012-11-19 08:30:30 +08:00
|
|
|
if (iter->typemask & (1<<type))
|
2012-02-08 13:04:51 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2005-12-12 06:21:01 +08:00
|
|
|
|
|
|
|
|
2012-11-18 18:23:22 +08:00
|
|
|
/**
|
|
|
|
Types of blocks
|
2012-08-27 13:42:29 +08:00
|
|
|
*/
|
|
|
|
enum block_type_t
|
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
WHILE, /**< While loop block */
|
|
|
|
FOR, /**< For loop block */
|
|
|
|
IF, /**< If block */
|
|
|
|
FUNCTION_DEF, /**< Function definition block */
|
|
|
|
FUNCTION_CALL, /**< Function invocation block */
|
|
|
|
FUNCTION_CALL_NO_SHADOW, /**< Function invocation block with no variable shadowing */
|
|
|
|
SWITCH, /**< Switch block */
|
|
|
|
FAKE, /**< Fake block */
|
|
|
|
SUBST, /**< Command substitution scope */
|
|
|
|
TOP, /**< Outermost block */
|
|
|
|
BEGIN, /**< Unconditional block */
|
|
|
|
SOURCE, /**< Block created by the . (source) builtin */
|
|
|
|
EVENT, /**< Block created on event notifier invocation */
|
|
|
|
BREAKPOINT, /**< Breakpoint block */
|
2012-08-27 13:42:29 +08:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
2012-11-18 18:23:22 +08:00
|
|
|
block_t represents a block of commands.
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
2012-08-27 13:42:29 +08:00
|
|
|
struct block_t
|
2005-09-20 21:26:39 +08:00
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
protected:
|
2012-08-27 14:16:20 +08:00
|
|
|
/** Protected constructor. Use one of the subclasses below. */
|
|
|
|
block_t(block_type_t t);
|
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
private:
|
|
|
|
const block_type_t block_type; /**< Type of block. */
|
2012-08-27 14:16:20 +08:00
|
|
|
bool made_fake;
|
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
public:
|
|
|
|
block_type_t type() const
|
|
|
|
{
|
|
|
|
return this->made_fake ? FAKE : this->block_type;
|
|
|
|
}
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-08-27 14:16:20 +08:00
|
|
|
/** Mark a block as fake; this is used by the return statement. */
|
2012-11-19 08:30:30 +08:00
|
|
|
void mark_as_fake()
|
|
|
|
{
|
|
|
|
this->made_fake = true;
|
|
|
|
}
|
2012-08-27 14:16:20 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
bool skip; /**< Whether execution of the commands in this block should be skipped */
|
|
|
|
bool had_command; /**< Set to non-zero once a command has been executed in this block */
|
|
|
|
int tok_pos; /**< The start index of the block */
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
/**
|
|
|
|
Status for the current loop block. Can be any of the values from the loop_status enum.
|
|
|
|
*/
|
|
|
|
int loop_status;
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
/**
|
|
|
|
The job that is currently evaluated in the specified block.
|
|
|
|
*/
|
|
|
|
job_t *job;
|
2012-09-01 16:46:14 +08:00
|
|
|
|
2012-02-08 09:06:45 +08:00
|
|
|
#if 0
|
2012-11-19 08:30:30 +08:00
|
|
|
union
|
|
|
|
{
|
|
|
|
int while_state; /**< True if the loop condition has not yet been evaluated*/
|
|
|
|
wchar_t *for_variable; /**< Name of the variable to loop over */
|
|
|
|
int if_state; /**< The state of the if block, can be one of IF_STATE_UNTESTED, IF_STATE_FALSE, IF_STATE_TRUE */
|
|
|
|
wchar_t *switch_value; /**< The value to test in a switch block */
|
|
|
|
const wchar_t *source_dest; /**< The name of the file to source*/
|
|
|
|
event_t *event; /**<The event that triggered this block */
|
|
|
|
wchar_t *function_call_name;
|
|
|
|
} param1;
|
2012-02-08 09:06:45 +08:00
|
|
|
#endif
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
/**
|
|
|
|
Name of file that created this block
|
|
|
|
*/
|
|
|
|
const wchar_t *src_filename;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
/**
|
|
|
|
Line number where this block was created
|
|
|
|
*/
|
|
|
|
int src_lineno;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-02-08 13:04:51 +08:00
|
|
|
/** Whether we should pop the environment variable stack when we're popped off of the block stack */
|
2012-02-08 09:06:45 +08:00
|
|
|
bool wants_pop_env;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
/** List of event blocks. */
|
|
|
|
event_blockage_list_t event_blocks;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
2012-11-18 18:23:22 +08:00
|
|
|
Next outer block
|
2012-11-19 08:30:30 +08:00
|
|
|
*/
|
|
|
|
block_t *outer;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-02-08 09:06:45 +08:00
|
|
|
/** Destructor */
|
2012-08-27 13:42:29 +08:00
|
|
|
virtual ~block_t();
|
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct if_block_t : public block_t
|
|
|
|
{
|
2012-09-02 03:29:00 +08:00
|
|
|
bool if_expr_evaluated; // whether we've evaluated the if expression
|
2012-09-04 04:24:01 +08:00
|
|
|
bool is_elseif_entry; // whether we're at the beginning of an ELSEIF branch
|
2012-09-01 16:46:14 +08:00
|
|
|
bool any_branch_taken; // whether the clause of the if statement or any elseif has been found to be true
|
2012-08-27 13:42:29 +08:00
|
|
|
bool else_evaluated; // whether we've encountered a terminal else block
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-08-27 14:16:20 +08:00
|
|
|
if_block_t();
|
2012-08-27 13:42:29 +08:00
|
|
|
};
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct event_block_t : public block_t
|
|
|
|
{
|
2012-08-27 13:42:29 +08:00
|
|
|
const event_t * const event;
|
2012-08-27 14:16:20 +08:00
|
|
|
event_block_t(const event_t *evt);
|
2012-08-27 13:42:29 +08:00
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct function_block_t : public block_t
|
|
|
|
{
|
2012-08-27 13:42:29 +08:00
|
|
|
process_t *process;
|
|
|
|
wcstring name;
|
2012-08-27 14:16:20 +08:00
|
|
|
function_block_t(process_t *p, const wcstring &n, bool shadows);
|
2012-08-27 13:42:29 +08:00
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct source_block_t : public block_t
|
|
|
|
{
|
2012-08-27 13:42:29 +08:00
|
|
|
const wchar_t * const source_file;
|
2012-08-27 14:16:20 +08:00
|
|
|
source_block_t(const wchar_t *src);
|
2012-08-27 13:42:29 +08:00
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct for_block_t : public block_t
|
|
|
|
{
|
2012-08-27 13:42:29 +08:00
|
|
|
wcstring variable; // the variable that will be assigned each value in the sequence
|
|
|
|
wcstring_list_t sequence; // the sequence of values
|
2012-08-27 14:16:20 +08:00
|
|
|
for_block_t(const wcstring &var);
|
2012-08-27 13:42:29 +08:00
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct while_block_t : public block_t
|
|
|
|
{
|
2012-08-27 13:42:29 +08:00
|
|
|
int status;
|
2012-08-27 14:16:20 +08:00
|
|
|
while_block_t();
|
2012-08-27 13:42:29 +08:00
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct switch_block_t : public block_t
|
|
|
|
{
|
2012-08-27 13:42:29 +08:00
|
|
|
bool switch_taken;
|
|
|
|
const wcstring switch_value;
|
2012-08-27 14:16:20 +08:00
|
|
|
switch_block_t(const wcstring &sv);
|
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct fake_block_t : public block_t
|
|
|
|
{
|
2012-08-27 14:16:20 +08:00
|
|
|
fake_block_t();
|
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct function_def_block_t : public block_t
|
|
|
|
{
|
2012-08-27 14:30:23 +08:00
|
|
|
function_data_t function_data;
|
2012-08-27 14:16:20 +08:00
|
|
|
function_def_block_t();
|
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct scope_block_t : public block_t
|
|
|
|
{
|
2012-08-27 14:16:20 +08:00
|
|
|
scope_block_t(block_type_t type); //must be BEGIN, TOP or SUBST
|
|
|
|
};
|
|
|
|
|
2012-08-27 14:34:34 +08:00
|
|
|
struct breakpoint_block_t : public block_t
|
|
|
|
{
|
2012-08-27 14:16:20 +08:00
|
|
|
breakpoint_block_t();
|
2012-08-27 13:42:29 +08:00
|
|
|
};
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Possible states for a loop
|
|
|
|
*/
|
2012-11-18 18:23:22 +08:00
|
|
|
enum loop_status
|
2005-09-20 21:26:39 +08:00
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
LOOP_NORMAL, /**< Current loop block executed as normal */
|
|
|
|
LOOP_BREAK, /**< Current loop block should be removed */
|
|
|
|
LOOP_CONTINUE, /**< Current loop block should be skipped */
|
2005-09-20 21:26:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Possible states for a while block
|
|
|
|
*/
|
|
|
|
enum while_status
|
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
WHILE_TEST_FIRST, /**< This is the first command of the first lap of a while loop */
|
|
|
|
WHILE_TEST_AGAIN, /**< This is not the first lap of the while loop, but it is the first command of the loop */
|
|
|
|
WHILE_TESTED, /**< This is not the first command in the loop */
|
2005-09-20 21:26:39 +08:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Errors that can be generated by the parser
|
|
|
|
*/
|
2012-11-18 18:23:22 +08:00
|
|
|
enum parser_error
|
2005-09-20 21:26:39 +08:00
|
|
|
{
|
2012-11-19 08:30:30 +08:00
|
|
|
/**
|
|
|
|
No error
|
|
|
|
*/
|
|
|
|
NO_ERR=0,
|
|
|
|
/**
|
|
|
|
An error in the syntax
|
|
|
|
*/
|
|
|
|
SYNTAX_ERROR,
|
|
|
|
/**
|
|
|
|
Error occured while evaluating commands
|
|
|
|
*/
|
|
|
|
EVAL_ERROR,
|
|
|
|
/**
|
|
|
|
Error while evaluating cmdsubst
|
|
|
|
*/
|
|
|
|
CMDSUBST_ERROR,
|
2012-01-17 03:09:19 +08:00
|
|
|
};
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
enum parser_type_t
|
|
|
|
{
|
2012-01-17 04:10:08 +08:00
|
|
|
PARSER_TYPE_NONE,
|
|
|
|
PARSER_TYPE_GENERAL,
|
|
|
|
PARSER_TYPE_FUNCTIONS_ONLY,
|
2012-01-31 02:28:30 +08:00
|
|
|
PARSER_TYPE_COMPLETIONS_ONLY,
|
2012-11-19 08:30:30 +08:00
|
|
|
PARSER_TYPE_ERRORS_ONLY
|
2012-01-17 04:10:08 +08:00
|
|
|
};
|
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
struct profile_item_t
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
Time spent executing the specified command, including parse time for nested blocks.
|
|
|
|
*/
|
|
|
|
int exec;
|
|
|
|
/**
|
|
|
|
Time spent parsing the specified command, including execution time for command substitutions.
|
|
|
|
*/
|
|
|
|
int parse;
|
|
|
|
/**
|
|
|
|
The block level of the specified command. nested blocks and command substitutions both increase the block level.
|
|
|
|
*/
|
|
|
|
size_t level;
|
|
|
|
/**
|
|
|
|
If the execution of this command was skipped.
|
|
|
|
*/
|
|
|
|
int skipped;
|
|
|
|
/**
|
|
|
|
The command string.
|
|
|
|
*/
|
|
|
|
wcstring cmd;
|
2012-01-21 03:24:43 +08:00
|
|
|
};
|
2012-01-20 02:28:44 +08:00
|
|
|
|
2012-11-22 09:48:35 +08:00
|
|
|
struct tokenizer_t;
|
2012-01-23 12:47:13 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
class parser_t
|
|
|
|
{
|
|
|
|
private:
|
2012-01-23 13:40:08 +08:00
|
|
|
enum parser_type_t parser_type;
|
2012-01-17 03:09:19 +08:00
|
|
|
std::vector<block_t> blocks;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-05-07 04:36:51 +08:00
|
|
|
/** Whether or not we output errors */
|
|
|
|
const bool show_errors;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:57:30 +08:00
|
|
|
/** Last error code */
|
|
|
|
int error_code;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:57:30 +08:00
|
|
|
/** Position of last error */
|
|
|
|
int err_pos;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:57:30 +08:00
|
|
|
/** Description of last error */
|
2012-02-10 10:43:36 +08:00
|
|
|
wcstring err_buff;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:57:30 +08:00
|
|
|
/** Pointer to the current tokenizer */
|
2012-11-22 09:48:35 +08:00
|
|
|
tokenizer_t *current_tokenizer;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:57:30 +08:00
|
|
|
/** String for representing the current line */
|
2012-02-23 02:51:06 +08:00
|
|
|
wcstring lineinfo;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:57:30 +08:00
|
|
|
/** This is the position of the beginning of the currently parsed command */
|
|
|
|
int current_tokenizer_pos;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:57:30 +08:00
|
|
|
/** List of called functions, used to help prevent infinite recursion */
|
2012-01-30 14:06:58 +08:00
|
|
|
wcstring_list_t forbidden_function;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:57:30 +08:00
|
|
|
/** String index where the current job started. */
|
|
|
|
int job_start_pos;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** The jobs associated with this parser */
|
|
|
|
job_list_t my_job_list;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:57:30 +08:00
|
|
|
/**
|
|
|
|
Keeps track of how many recursive eval calls have been made. Eval
|
|
|
|
doesn't call itself directly, recursion happens on blocks and on
|
|
|
|
command substitutions.
|
|
|
|
*/
|
|
|
|
int eval_level;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-17 04:10:08 +08:00
|
|
|
/* No copying allowed */
|
|
|
|
parser_t(const parser_t&);
|
|
|
|
parser_t& operator=(const parser_t&);
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-11-22 09:48:35 +08:00
|
|
|
void parse_job_argument_list(process_t *p, job_t *j, tokenizer_t *tok, std::vector<completion_t>&, bool);
|
|
|
|
int parse_job(process_t *p, job_t *j, tokenizer_t *tok);
|
2012-11-19 08:30:30 +08:00
|
|
|
void skipped_exec(job_t * j);
|
2012-11-22 09:48:35 +08:00
|
|
|
void eval_job(tokenizer_t *tok);
|
2012-11-19 08:30:30 +08:00
|
|
|
int parser_test_argument(const wchar_t *arg, wcstring *out, const wchar_t *prefix, int offset);
|
|
|
|
void print_errors(wcstring &target, const wchar_t *prefix);
|
2012-01-23 13:57:30 +08:00
|
|
|
void print_errors_stderr();
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
public:
|
2012-01-20 02:28:44 +08:00
|
|
|
std::vector<profile_item_t> profile_items;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-04-22 11:08:08 +08:00
|
|
|
/**
|
|
|
|
Returns the name of the currently evaluated function if we are
|
|
|
|
currently evaluating a function, null otherwise. This is tested by
|
|
|
|
moving down the block-scope-stack, checking every block if it is of
|
|
|
|
type FUNCTION_CALL.
|
|
|
|
*/
|
|
|
|
const wchar_t *is_function() const;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-23 13:40:08 +08:00
|
|
|
/** Get the "principal" parser, whatever that is */
|
|
|
|
static parser_t &principal_parser();
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-06-05 05:20:01 +08:00
|
|
|
/** Indicates that execution of all blocks in the principal parser should stop.
|
|
|
|
This is called from signal handlers!
|
|
|
|
*/
|
|
|
|
static void skip_all_blocks();
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-17 04:10:08 +08:00
|
|
|
/** Create a parser of the given type */
|
2012-05-07 04:36:51 +08:00
|
|
|
parser_t(enum parser_type_t type, bool show_errors);
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-02-08 09:06:45 +08:00
|
|
|
/** The current innermost block, allocated with new */
|
2012-01-17 04:10:08 +08:00
|
|
|
block_t *current_block;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/** Global event blocks */
|
2012-08-27 13:42:29 +08:00
|
|
|
event_blockage_list_t global_event_blocks;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/** Current block level io redirections */
|
2012-08-15 15:57:56 +08:00
|
|
|
io_chain_t block_io;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Evaluate the expressions contained in cmd.
|
2005-12-08 00:06:47 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
\param cmd the string to evaluate
|
|
|
|
\param io io redirections to perform on all started jobs
|
|
|
|
\param block_type The type of block to push on the block stack
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
\return 0 on success, 1 otherwise
|
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
int eval(const wcstring &cmdStr, const io_chain_t &io, enum block_type_t block_type);
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Evaluate line as a list of parameters, i.e. tokenize it and perform parameter expansion and cmdsubst execution on the tokens.
|
|
|
|
The output is inserted into output, and should be freed by the caller.
|
|
|
|
|
|
|
|
\param line Line to evaluate
|
|
|
|
\param output List to insert output to
|
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
/**
|
|
|
|
\param line Line to evaluate
|
|
|
|
\param output List to insert output to
|
|
|
|
*/
|
|
|
|
int eval_args(const wchar_t *line, std::vector<completion_t> &output);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
2012-11-18 18:23:22 +08:00
|
|
|
Sets the current evaluation error. This function should only be used by libraries that are called by
|
2012-01-17 03:09:19 +08:00
|
|
|
|
|
|
|
\param ec The new error code
|
|
|
|
\param p The character offset at which the error occured
|
|
|
|
\param str The printf-style error message filter
|
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
void error(int ec, int p, const wchar_t *str, ...);
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Returns a string describing the current parser pisition in the format 'FILENAME (line LINE_NUMBER): LINE'.
|
2012-11-18 18:23:22 +08:00
|
|
|
Example:
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
init.fish (line 127): ls|grep pancake
|
|
|
|
*/
|
2012-01-23 12:47:13 +08:00
|
|
|
const wchar_t *current_line();
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Returns the current line number */
|
2012-01-17 03:16:12 +08:00
|
|
|
int get_lineno() const;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-08-05 08:44:14 +08:00
|
|
|
/** Returns the line number for the character at the given index */
|
|
|
|
int line_number_of_character_at_offset(size_t idx) const;
|
2006-01-26 22:48:10 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Returns the current position in the latest string of the tokenizer. */
|
2012-01-17 03:16:12 +08:00
|
|
|
int get_pos() const;
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Returns the position where the current job started in the latest string of the tokenizer. */
|
2012-01-17 03:16:12 +08:00
|
|
|
int get_job_pos() const;
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Set the current position in the latest string of the tokenizer. */
|
2012-11-19 08:30:30 +08:00
|
|
|
void set_pos(int p);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Get the string currently parsed */
|
2012-01-17 03:16:12 +08:00
|
|
|
const wchar_t *get_buffer() const;
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Get the list of jobs */
|
2012-11-19 08:30:30 +08:00
|
|
|
job_list_t &job_list()
|
|
|
|
{
|
|
|
|
return my_job_list;
|
|
|
|
}
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-08-27 13:42:29 +08:00
|
|
|
/** Pushes the block. pop_block will call delete on it. */
|
2012-11-19 08:30:30 +08:00
|
|
|
void push_block(block_t *newv);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Remove the outermost block namespace */
|
2012-01-17 03:09:19 +08:00
|
|
|
void pop_block();
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Return a description of the given blocktype */
|
2012-11-19 08:30:30 +08:00
|
|
|
const wchar_t *get_block_desc(int block) const;
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Create a job */
|
|
|
|
job_t *job_create();
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Removes a job */
|
|
|
|
bool job_remove(job_t *job);
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Promotes a job to the front of the list */
|
|
|
|
void job_promote(job_t *job);
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Return the job with the specified job id. If id is 0 or less, return the last job used. */
|
|
|
|
job_t *job_get(int job_id);
|
2012-11-18 18:23:22 +08:00
|
|
|
|
2012-02-28 10:43:24 +08:00
|
|
|
/** Returns the job with the given pid */
|
2012-11-19 08:30:30 +08:00
|
|
|
job_t *job_get_from_pid(int pid);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Test if the specified string can be parsed, or if more bytes need
|
|
|
|
to be read first. The result will have the PARSER_TEST_ERROR bit
|
|
|
|
set if there is a syntax error in the code, and the
|
|
|
|
PARSER_TEST_INCOMPLETE bit set if the code contains unclosed
|
|
|
|
blocks.
|
|
|
|
|
|
|
|
\param buff the text buffer to test
|
|
|
|
\param block_level if non-null, the block nesting level will be filled out into this array
|
|
|
|
\param out if non-null, any errors in the command will be filled out into this buffer
|
|
|
|
\param prefix the prefix string to prepend to each error message written to the \c out buffer
|
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
int test(const wchar_t * buff, int *block_level, wcstring *out, const wchar_t *prefix);
|
2006-05-22 03:25:24 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Test if the specified string can be parsed as an argument list,
|
|
|
|
e.g. sent to eval_args. The result has the first bit set if the
|
|
|
|
string contains errors, and the second bit is set if the string
|
|
|
|
contains an unclosed block.
|
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
int test_args(const wchar_t * buff, wcstring *out, const wchar_t *prefix);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Tell the parser that the specified function may not be run if not
|
|
|
|
inside of a conditional block. This is to remove some possibilities
|
|
|
|
of infinite recursion.
|
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
void forbid_function(const wcstring &function);
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Undo last call to parser_forbid_function().
|
|
|
|
*/
|
|
|
|
void allow_function();
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Initialize static parser data
|
|
|
|
*/
|
|
|
|
void init();
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Destroy static parser data
|
|
|
|
*/
|
|
|
|
void destroy();
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
2012-11-18 18:23:22 +08:00
|
|
|
This function checks if the specified string is a help option.
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
\param s the string to test
|
|
|
|
\param min_match is the minimum number of characters that must match in a long style option, i.e. the longest common prefix between --help and any other option. If less than 3, 3 will be assumed.
|
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
int is_help(const wchar_t *s, int min_match) const;
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
|
|
|
Returns the file currently evaluated by the parser. This can be
|
|
|
|
different than reader_current_filename, e.g. if we are evaulating a
|
|
|
|
function defined in a different file than the one curently read.
|
|
|
|
*/
|
2012-01-17 03:16:12 +08:00
|
|
|
const wchar_t *current_filename() const;
|
2006-01-26 23:47:22 +08:00
|
|
|
|
2012-01-17 03:09:19 +08:00
|
|
|
/**
|
2012-02-23 02:51:06 +08:00
|
|
|
Write a stack trace starting at the specified block to the specified wcstring
|
2012-01-17 03:09:19 +08:00
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
void stack_trace(block_t *b, wcstring &buff);
|
2006-01-31 01:54:26 +08:00
|
|
|
|
2012-11-19 08:30:30 +08:00
|
|
|
int get_block_type(const wchar_t *cmd) const;
|
|
|
|
const wchar_t *get_block_command(int type) const;
|
2012-01-17 03:16:12 +08:00
|
|
|
};
|
2006-09-06 04:43:47 +08:00
|
|
|
|
2006-01-26 23:47:22 +08:00
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#endif
|