diff --git a/highlight.c b/highlight.c index cea56bf3f..a6178313e 100644 --- a/highlight.c +++ b/highlight.c @@ -884,7 +884,7 @@ void highlight_shell( wchar_t * buff, wchar_t *token; parse_util_token_extent( buff, pos, &tok_begin, &tok_end, 0, 0 ); - if( tok_begin ) + if( tok_begin && tok_end ) { token = halloc_wcsndup( context, tok_begin, tok_end-tok_begin ); diff --git a/parse_util.c b/parse_util.c index f413f7518..551900735 100644 --- a/parse_util.c +++ b/parse_util.c @@ -180,27 +180,27 @@ void parse_util_cmdsubst_extent( const wchar_t *buff, { wchar_t *begin, *end; wchar_t *pos; + const wchar_t *cursor = buff + cursor_pos; CHECK( buff, ); if( a ) - *a=0; + *a = (wchar_t *)buff; if( b ) - *b = 0; - + *b = (wchar_t *)buff+wcslen(buff); + pos = (wchar_t *)buff; while( 1 ) { - int bc, ec; - if( parse_util_locate_cmdsubst( pos, &begin, &end, 1 ) <= 0) { - begin=(wchar_t *)buff; - end = (wchar_t *)buff + wcslen(buff); + /* + No subshell found + */ break; } @@ -209,12 +209,13 @@ void parse_util_cmdsubst_extent( const wchar_t *buff, end = (wchar_t *)buff + wcslen(buff); } - bc = begin-buff; - ec = end-buff; - - if(( bc < cursor_pos ) && (ec >= cursor_pos) ) + if(( begin < cursor ) && (end >= cursor) ) { begin++; + if( a ) + *a = begin; + if( b ) + *b = end; break; } @@ -225,10 +226,7 @@ void parse_util_cmdsubst_extent( const wchar_t *buff, pos = end+1; } - if( a ) - *a = begin; - if( b ) - *b = end; + } /** @@ -359,21 +357,21 @@ void parse_util_token_extent( const wchar_t *buff, if( !end || !begin ) return; - + pos = cursor_pos - (begin - buff); - + a = (wchar_t *)buff + pos; b = a; pa = (wchar_t *)buff + pos; pb = pa; - + assert( begin >= buff ); assert( begin <= (buff+wcslen(buff) ) ); assert( end >= begin ); assert( end <= (buff+wcslen(buff) ) ); - + buffcpy = wcsndup( begin, end-begin ); - + if( !buffcpy ) { DIE_MEM(); diff --git a/parse_util.h b/parse_util.h index 9120ca856..23b9b88f6 100644 --- a/parse_util.h +++ b/parse_util.h @@ -25,7 +25,11 @@ int parse_util_locate_cmdsubst( const wchar_t *in, int flags ); /** - Find the beginning and end of the command substitution under the cursor + Find the beginning and end of the command substitution under the + cursor. If no subshell is found, the entire string is returned. If + the current command substitution is not ended, i.e. the closing + parenthesis is missing, then the string from the beginning of the + substitution to the end of the string is returned. \param buff the string to search for subshells \param cursor_pos the position of the cursor diff --git a/parser.c b/parser.c index 7700367dd..85851c9f0 100644 --- a/parser.c +++ b/parser.c @@ -261,14 +261,17 @@ The fish parser. Contains functions for parsing code. */ struct block_lookup_entry { + /** The block type id. The legal values are defined in parser.h. */ int type; + /** The name of the builtin that creates this type of block, if any. */ const wchar_t *name; + /** A description of this block type */ @@ -3045,10 +3048,11 @@ int parser_test( const wchar_t * buff, error( SYNTAX_ERROR, tok_get_pos( &tok ), ILLEGAL_CMD_ERR_MSG, - cmd ); + tok_last( &tok ) ); print_errors( out, prefix ); - } + } + break; } if( needs_cmd ) @@ -3257,6 +3261,7 @@ int parser_test( const wchar_t * buff, sb_printf( out, L"%s", h ); } } + } else {