Beginnings of instance parser work

This commit is contained in:
ridiculousfish 2012-01-16 11:09:19 -08:00
parent c647bed9d5
commit 0073a93079
3 changed files with 163 additions and 161 deletions

View file

@ -783,7 +783,7 @@ static io_data_t *io_transmogrify( io_data_t * in )
*/
static void internal_exec_helper( const wchar_t *def,
int block_type,
enum block_type_t block_type,
io_data_t *io )
{
io_data_t *io_internal = io_transmogrify( io );

View file

@ -2493,7 +2493,7 @@ static void eval_job( tokenizer *tok )
}
int eval( const wchar_t *cmd, io_data_t *io, int block_type )
int eval( const wchar_t *cmd, io_data_t *io, enum block_type_t block_type )
{
size_t forbid_count;
int code;

View file

@ -11,6 +11,7 @@
#include "util.h"
#include "parser.h"
#include "event.h"
#include <vector>
#define PARSER_TEST_ERROR 1
#define PARSER_TEST_INCOMPLETE 2
@ -113,7 +114,7 @@ typedef struct block
/**
Types of blocks
*/
enum block_type
enum block_type_t
{
WHILE, /**< While loop block */
FOR, /**< For loop block */
@ -177,19 +178,21 @@ enum parser_error
Error while evaluating cmdsubst
*/
CMDSUBST_ERROR,
}
;
};
class parser_t {
private:
std::vector<block_t> blocks;
public:
/** The current innermost block */
extern block_t *current_block;
const block_t &current_block(void);
/** Global event blocks */
extern event_block_t *global_event_block;
const block_t &global_event_block(void);
/**
Current block level io redirections
*/
extern io_data_t *block_io;
/** Current block level io redirections */
io_data_t &block_io(void);
/**
Evaluate the expressions contained in cmd.
@ -200,7 +203,7 @@ extern io_data_t *block_io;
\return 0 on success, 1 otherwise
*/
int eval( const wchar_t *cmd, io_data_t *io, int block_type );
int eval( const wcstring &cmd, io_data_t *io, enum block_type_t block_type );
/**
Evaluate line as a list of parameters, i.e. tokenize it and perform parameter expansion and cmdsubst execution on the tokens.
@ -209,8 +212,7 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type );
\param line Line to evaluate
\param output List to insert output to
*/
int eval_args( const wchar_t *line,
array_list_t *output );
int eval_args( const wchar_t *line, array_list_t *output );
/**
Sets the current evaluation error. This function should only be used by libraries that are called by
@ -221,54 +223,53 @@ int eval_args( const wchar_t *line,
*/
void error( int ec, int p, const wchar_t *str, ... );
/**
Returns a string describing the current parser pisition in the format 'FILENAME (line LINE_NUMBER): LINE'.
Example:
init.fish (line 127): ls|grep pancake
*/
const wchar_t *parser_current_line();
const wchar_t *current_line();
/**
Returns the current line number
*/
int parser_get_lineno();
int get_lineno();
/**
Returns the current position in the latest string of the tokenizer.
*/
int parser_get_pos();
int get_pos();
/**
Returns the position where the current job started in the latest string of the tokenizer.
*/
int parser_get_job_pos();
int get_job_pos();
/**
Set the current position in the latest string of the tokenizer.
*/
void parser_set_pos( int p);
void set_pos( int p);
/**
Get the string currently parsed
*/
const wchar_t *parser_get_buffer();
const wchar_t *get_buffer();
/**
Create block of specified type
*/
void parser_push_block( int type);
void push_block( int type);
/**
Remove the outermost block namespace
*/
void parser_pop_block();
void pop_block();
/**
Return a description of the given blocktype
*/
const wchar_t *parser_get_block_desc( int block );
const wchar_t *get_block_desc( int block );
/**
@ -283,7 +284,7 @@ const wchar_t *parser_get_block_desc( int block );
\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
*/
int parser_test( const wchar_t * buff, int *block_level, string_buffer_t *out, const wchar_t *prefix );
int test( const wchar_t * buff, int *block_level, string_buffer_t *out, const wchar_t *prefix );
/**
Test if the specified string can be parsed as an argument list,
@ -291,28 +292,28 @@ int parser_test( const wchar_t * buff, int *block_level, string_buffer_t *out, c
string contains errors, and the second bit is set if the string
contains an unclosed block.
*/
int parser_test_args( const wchar_t * buff, string_buffer_t *out, const wchar_t *prefix );
int test_args( const wchar_t * buff, string_buffer_t *out, const wchar_t *prefix );
/**
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.
*/
void parser_forbid_function( wchar_t *function );
void forbid_function( wchar_t *function );
/**
Undo last call to parser_forbid_function().
*/
void parser_allow_function();
void allow_function();
/**
Initialize static parser data
*/
void parser_init();
void init();
/**
Destroy static parser data
*/
void parser_destroy();
void destroy();
/**
This function checks if the specified string is a help option.
@ -320,22 +321,23 @@ void parser_destroy();
\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.
*/
int parser_is_help( wchar_t *s, int min_match );
int is_help( wchar_t *s, int min_match );
/**
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.
*/
const wchar_t *parser_current_filename();
const wchar_t *current_filename();
/**
Write a stack trace starting at the specified block to the specified string_buffer_t
*/
void parser_stack_trace( block_t *b, string_buffer_t *buff);
void stack_trace( block_t *b, string_buffer_t *buff);
int parser_get_block_type( const wchar_t *cmd );
const wchar_t *parser_get_block_command( int type );
int get_block_type( const wchar_t *cmd );
const wchar_t *get_block_command( int type );
}
#endif