From 7e486e3b5c5e1a3a6936322fde487260d3058042 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 20 Jan 2012 11:24:43 -0800 Subject: [PATCH] More work towards instanced parser --- complete.cpp | 4 ++-- env.cpp | 15 ++++----------- expand.cpp | 12 ++++++------ expand.h | 2 +- fish.cpp | 5 +++-- parser.cpp | 23 ----------------------- parser.h | 23 ++++++++++++++++++++++- 7 files changed, 38 insertions(+), 46 deletions(-) diff --git a/complete.cpp b/complete.cpp index d10886b6d..8b353eed2 100644 --- a/complete.cpp +++ b/complete.cpp @@ -1243,9 +1243,9 @@ static void complete_from_args( const wchar_t *str, array_list_t possible_comp; al_init( &possible_comp ); - + parser_t parser(PARSER_TYPE_COMPLETIONS_ONLY); proc_push_interactive(0); - eval_args( args, &possible_comp ); + parser.eval_args( args, &possible_comp ); proc_pop_interactive(); complete_strings( comp_out, str, desc, 0, &possible_comp, flags ); diff --git a/env.cpp b/env.cpp index f9de33449..d2d1aab0d 100644 --- a/env.cpp +++ b/env.cpp @@ -247,11 +247,7 @@ static void clear_hash_entry( void *key, void *data ) */ static void start_fishd() { - string_buffer_t cmd; - struct passwd *pw; - - sb_init( &cmd ); - pw = getpwuid(getuid()); + struct passwd *pw = getpwuid(getuid()); debug( 3, L"Spawning new copy of fishd" ); @@ -261,12 +257,9 @@ static void start_fishd() return; } - sb_printf( &cmd, FISHD_CMD, pw->pw_name ); - - eval( (wchar_t *)cmd.buff, - 0, - TOP ); - sb_destroy( &cmd ); + wcstring cmd = format_string(FISHD_CMD, pw->pw_name); + parser_t parser(PARSER_TYPE_GENERAL); + parser.eval( cmd.c_str(), 0, TOP ); } /** diff --git a/expand.cpp b/expand.cpp index cf0030c3f..7ec94ce51 100644 --- a/expand.cpp +++ b/expand.cpp @@ -731,7 +731,7 @@ static int expand_pid2( const wcstring &in, int flags, std::vector &ou } -void expand_variable_error( const wchar_t *token, int token_pos, int error_pos ) +void expand_variable_error( parser_t &parser, const wchar_t *token, int token_pos, int error_pos ) { int stop_pos = token_pos+1; @@ -758,7 +758,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos ) if( is_var ) { - error( SYNTAX_ERROR, + parser.error( SYNTAX_ERROR, error_pos, COMPLETE_VAR_BRACKET_DESC, cpy, @@ -767,7 +767,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos ) } else { - error( SYNTAX_ERROR, + parser.error( SYNTAX_ERROR, error_pos, COMPLETE_VAR_BRACKET_DESC, L"", @@ -781,7 +781,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos ) case INTERNAL_SEPARATOR: { - error( SYNTAX_ERROR, + parser.error( SYNTAX_ERROR, error_pos, COMPLETE_VAR_PARAN_DESC ); break; @@ -789,7 +789,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos ) case 0: { - error( SYNTAX_ERROR, + parser.error( SYNTAX_ERROR, error_pos, COMPLETE_VAR_NULL_DESC ); break; @@ -797,7 +797,7 @@ void expand_variable_error( const wchar_t *token, int token_pos, int error_pos ) default: { - error( SYNTAX_ERROR, + parser.error( SYNTAX_ERROR, error_pos, COMPLETE_VAR_DESC, token[stop_pos] ); diff --git a/expand.h b/expand.h index 82fdc688d..4887c06b6 100644 --- a/expand.h +++ b/expand.h @@ -204,7 +204,7 @@ int expand_is_clean( const wchar_t *in ); \param token_pos The position where the expansion begins \param error_pos The position on the line to report to the error function. */ -void expand_variable_error( const wchar_t *token, int token_pos, int error_pos ); +void expand_variable_error( parser_t &parser, const wchar_t *token, int token_pos, int error_pos ); #endif diff --git a/fish.cpp b/fish.cpp index 118652559..54a444949 100644 --- a/fish.cpp +++ b/fish.cpp @@ -77,9 +77,10 @@ static int read_init() wchar_t *config_dir_escaped; void *context; string_buffer_t *eval_buff; + parser_t parser(); - eval( L"builtin . " DATADIR "/fish/config.fish 2>/dev/null", 0, TOP ); - eval( L"builtin . " SYSCONFDIR L"/fish/config.fish 2>/dev/null", 0, TOP ); + parser.eval( L"builtin . " DATADIR "/fish/config.fish 2>/dev/null", 0, TOP ); + parser.eval( L"builtin . " SYSCONFDIR L"/fish/config.fish 2>/dev/null", 0, TOP ); /* We need to get the configuration directory before we can source the user configuration file diff --git a/parser.cpp b/parser.cpp index 7d273b2ff..30313d631 100644 --- a/parser.cpp +++ b/parser.cpp @@ -428,29 +428,6 @@ typedef struct wchar_t *cmd; } profile_element_t; -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. - */ - int level; - /** - If the execution of this command was skipped. - */ - int skipped; - /** - The command string. - */ - wcstring cmd; -}; - /** Return the current number of block nestings */ diff --git a/parser.h b/parser.h index 8c465d0af..db26398e0 100644 --- a/parser.h +++ b/parser.h @@ -187,7 +187,28 @@ enum parser_type_t { PARSER_TYPE_COMPLETIONS_ONLY }; -struct profile_item_t; +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. + */ + int level; + /** + If the execution of this command was skipped. + */ + int skipped; + /** + The command string. + */ + wcstring cmd; +}; class parser_t { private: