1840 |
* because it would end up in an endless loop otherwise. |
* because it would end up in an endless loop otherwise. |
1841 |
* |
* |
1842 |
* This solution consumes a lot of memory, but unfortunately there is no other |
* This solution consumes a lot of memory, but unfortunately there is no other |
1843 |
* easy way to solve it. With our grammar and today's memory heap & memory stack |
* easy way to solve it. With our grammar and today's memory heap size & memory |
1844 |
* it should be fine though. |
* stack size it should be fine though. |
1845 |
*/ |
*/ |
1846 |
typedef std::set< std::vector<YYTYPE_INT16> > YYStackHistory; |
typedef std::set< std::vector<YYTYPE_INT16> > YYStackHistory; |
1847 |
|
|
2009 |
* application will only have to show the results of the LSCP server's |
* application will only have to show the results of the LSCP server's |
2010 |
* evaluation to the user on the screen. |
* evaluation to the user on the screen. |
2011 |
* |
* |
2012 |
|
* @param line - the current command line to be evaluated by LSCP parser |
2013 |
|
* @param param = reentrant parser session parameters |
2014 |
|
* @param possibilities - whether all possibilities shall be shown |
2015 |
* @returns LSCP shell response line to be returned to the client |
* @returns LSCP shell response line to be returned to the client |
2016 |
*/ |
*/ |
2017 |
String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param) { |
String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param, bool possibilities) { |
2018 |
// first, determine how many characters (starting from the left) of the |
// first, determine how many characters (starting from the left) of the |
2019 |
// given input line are already syntactically correct |
// given input line are already syntactically correct |
2020 |
std::vector<YYTYPE_INT16> stack; |
std::vector<YYTYPE_INT16> stack; |
2047 |
if (!l.empty()) yyValidCharacters(stack, l, param->bShellAutoCorrect); |
if (!l.empty()) yyValidCharacters(stack, l, param->bShellAutoCorrect); |
2048 |
|
|
2049 |
// generate auto completion suggestion (based on the current parser stack) |
// generate auto completion suggestion (based on the current parser stack) |
2050 |
String sSuggestion = yyAutoComplete(stack); |
std::vector<YYTYPE_INT16> stackCopy = stack; // make a copy, since yyAutoComplete() might alter the stack |
2051 |
|
String sSuggestion = yyAutoComplete(stackCopy); |
2052 |
if (!sSuggestion.empty()) result += LSCP_SHK_SUGGEST_BACK + sSuggestion; |
if (!sSuggestion.empty()) result += LSCP_SHK_SUGGEST_BACK + sSuggestion; |
2053 |
|
|
2054 |
|
if (!possibilities) return result; |
2055 |
|
|
2056 |
|
// finally append all possible terminals and non-terminals according to |
2057 |
|
// current parser state |
2058 |
|
String notUsedHere; |
2059 |
|
std::map<String,BisonSymbolInfo> expectedSymbols; |
2060 |
|
walkAndFillExpectedSymbols(stack, expectedSymbols, notUsedHere); |
2061 |
|
{ |
2062 |
|
// pretend to LSCP shell that the following terminal symbols were |
2063 |
|
// non-terminal symbols (since they are not human visible for auto |
2064 |
|
// completion on the shell's screen) |
2065 |
|
std::set<String> specialNonTerminals; |
2066 |
|
specialNonTerminals.insert("SP"); |
2067 |
|
specialNonTerminals.insert("CR"); |
2068 |
|
specialNonTerminals.insert("LF"); |
2069 |
|
|
2070 |
|
String sPossibilities; |
2071 |
|
int iNonTerminals = 0; |
2072 |
|
int iTerminals = 0; |
2073 |
|
for (std::map<String,BisonSymbolInfo>::const_iterator it = expectedSymbols.begin(); |
2074 |
|
it != expectedSymbols.end(); ++it) |
2075 |
|
{ |
2076 |
|
if (!sPossibilities.empty()) sPossibilities += " | "; |
2077 |
|
if (it->second.isTerminalSymbol && !specialNonTerminals.count(it->first)) { |
2078 |
|
sPossibilities += it->first; |
2079 |
|
iTerminals++; |
2080 |
|
} else { |
2081 |
|
sPossibilities += "<" + it->first + ">"; |
2082 |
|
iNonTerminals++; |
2083 |
|
} |
2084 |
|
} |
2085 |
|
if (!sPossibilities.empty() && (iNonTerminals || iTerminals > 1)) { |
2086 |
|
result += LSCP_SHK_POSSIBILITIES_BACK + sPossibilities; |
2087 |
|
} |
2088 |
|
} |
2089 |
|
|
2090 |
#if DEBUG_SHELL_INTERACTION |
#if DEBUG_SHELL_INTERACTION |
2091 |
printf("%s\n", result.c_str()); |
printf("%s\n", result.c_str()); |
2092 |
#endif |
#endif |