From d4da1b2c1b7b85968da608dde03e054cc0b1f7ca Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 22 Feb 2022 13:12:02 -0700 Subject: Add context-sensitive field name completion to Ada parser This updates the Ada expression parser to implement context-sensitive field name completion. This is PR ada/28727. This is somewhat complicated due to some choices in the Ada lexer -- it chooses to represent a sequence of "."-separated identifiers as a single token, so the parser must partially recreate the completer's logic to find the completion word boundaries. Despite the minor warts in this patch, though, it is a decent improvement. It's possible that the DWARF reader rewrite will help fix the package completion problem pointed out in this patch as well. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28727 --- gdb/ada-lex.l | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'gdb/ada-lex.l') diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index ea35c7a..3980889 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -108,8 +108,6 @@ static bool returned_complete = false; pstate->lexptr += 1; \ } -static int find_dot_all (const char *); - /* Depth of parentheses. */ static int paren_depth; @@ -289,12 +287,20 @@ false { return FALSEKEYWORD; } } } -"."{WHITE}*{ID} { +"."{WHITE}*{ID}{COMPLETE}? { yylval.sval = processId (yytext+1, yyleng-1); + if (yytext[yyleng - 1] == COMPLETE_CHAR) + return DOT_COMPLETE; return DOT_ID; } -{ID}({WHITE}*"."{WHITE}*({ID}|\"{OPER}\"))*(" "*"'")? { +"."{WHITE}*{COMPLETE} { + yylval.sval.ptr = ""; + yylval.sval.length = 0; + return DOT_COMPLETE; + } + +{ID}({WHITE}*"."{WHITE}*({ID}|\"{OPER}\"))*(" "*"'"|{COMPLETE})? { int all_posn = find_dot_all (yytext); if (all_posn == -1 && yytext[yyleng-1] == '\'') @@ -304,8 +310,9 @@ false { return FALSEKEYWORD; } } else if (all_posn >= 0) yyless (all_posn); + bool is_completion = yytext[yyleng - 1] == COMPLETE_CHAR; yylval.sval = processId (yytext, yyleng); - return NAME; + return is_completion ? NAME_COMPLETE : NAME; } @@ -541,7 +548,12 @@ processId (const char *name0, int len) i = i0 = 0; while (i0 < len) { - if (in_quotes) + if (name0[i0] == COMPLETE_CHAR) + { + /* Just ignore. */ + ++i0; + } + else if (in_quotes) name[i++] = name0[i0++]; else if (isalnum (name0[i0])) { -- cgit v1.1