forked from teamnwah/openmw-tes3coop
backend for tab completion: keywords
This commit is contained in:
parent
940554b5fc
commit
6848115c18
6 changed files with 80 additions and 31 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#include "console.hpp"
|
#include "console.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <components/compiler/exception.hpp>
|
#include <components/compiler/exception.hpp>
|
||||||
|
|
||||||
#include "../mwscript/extensions.hpp"
|
#include "../mwscript/extensions.hpp"
|
||||||
|
@ -26,6 +28,12 @@ namespace MWGui
|
||||||
|
|
||||||
bool Console::compile (const std::string& cmd, Compiler::Output& output)
|
bool Console::compile (const std::string& cmd, Compiler::Output& output)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
listNames();
|
||||||
|
for (std::vector<std::string>::iterator iter (mNames.begin()); iter!=mNames.end(); ++iter)
|
||||||
|
std::cout << *iter << ", ";
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ErrorHandler::reset();
|
ErrorHandler::reset();
|
||||||
|
@ -67,6 +75,20 @@ namespace MWGui
|
||||||
printError ((type==ErrorMessage ? "error: " : "warning: ") + message);
|
printError ((type==ErrorMessage ? "error: " : "warning: ") + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Console::listNames()
|
||||||
|
{
|
||||||
|
if (mNames.empty())
|
||||||
|
{
|
||||||
|
std::istringstream input ("");
|
||||||
|
|
||||||
|
Compiler::Scanner scanner (*this, input, mCompilerContext.getExtensions());
|
||||||
|
|
||||||
|
scanner.listKeywords (mNames);
|
||||||
|
|
||||||
|
std::sort (mNames.begin(), mNames.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Console::Console(int w, int h, MWWorld::Environment& environment,
|
Console::Console(int w, int h, MWWorld::Environment& environment,
|
||||||
const Compiler::Extensions& extensions)
|
const Compiler::Extensions& extensions)
|
||||||
: Layout("openmw_console_layout.xml"),
|
: Layout("openmw_console_layout.xml"),
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace MWGui
|
||||||
|
|
||||||
MWScript::CompilerContext mCompilerContext;
|
MWScript::CompilerContext mCompilerContext;
|
||||||
MWWorld::Environment& mEnvironment;
|
MWWorld::Environment& mEnvironment;
|
||||||
|
std::vector<std::string> mNames;
|
||||||
|
|
||||||
bool compile (const std::string& cmd, Compiler::Output& output);
|
bool compile (const std::string& cmd, Compiler::Output& output);
|
||||||
|
|
||||||
|
@ -33,6 +34,10 @@ namespace MWGui
|
||||||
/// Report a file related error
|
/// Report a file related error
|
||||||
virtual void report (const std::string& message, Type type);
|
virtual void report (const std::string& message, Type type);
|
||||||
|
|
||||||
|
void listNames();
|
||||||
|
///< Write all valid identifiers and keywords into mNames and sort them.
|
||||||
|
/// \note If mNames is not empty, this function is a no-op.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyGUI::EditPtr command;
|
MyGUI::EditPtr command;
|
||||||
MyGUI::EditPtr history;
|
MyGUI::EditPtr history;
|
||||||
|
|
|
@ -207,4 +207,11 @@ namespace Compiler
|
||||||
throw std::logic_error ("unsupported code segment");
|
throw std::logic_error ("unsupported code segment");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Extensions::listKeywords (std::vector<std::string>& keywords) const
|
||||||
|
{
|
||||||
|
for (std::map<std::string, int>::const_iterator iter (mKeywords.begin());
|
||||||
|
iter!=mKeywords.end(); ++iter)
|
||||||
|
keywords.push_back (iter->first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,9 @@ namespace Compiler
|
||||||
void generateInstructionCode (int keyword, std::vector<Interpreter::Type_Code>& code,
|
void generateInstructionCode (int keyword, std::vector<Interpreter::Type_Code>& code,
|
||||||
Literals& literals, const std::string& id, int optionalArguments) const;
|
Literals& literals, const std::string& id, int optionalArguments) const;
|
||||||
///< Append code for function to \a code.
|
///< Append code for function to \a code.
|
||||||
|
|
||||||
|
void listKeywords (std::vector<std::string>& keywords) const;
|
||||||
|
///< Append all known keywords to \æ kaywords.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,8 +230,6 @@ namespace Compiler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Scanner::scanName (char c, Parser& parser, bool& cont)
|
|
||||||
{
|
|
||||||
static const char *keywords[] =
|
static const char *keywords[] =
|
||||||
{
|
{
|
||||||
"begin", "end",
|
"begin", "end",
|
||||||
|
@ -251,6 +249,8 @@ namespace Compiler
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool Scanner::scanName (char c, Parser& parser, bool& cont)
|
||||||
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
if (!scanName (c, name))
|
if (!scanName (c, name))
|
||||||
|
@ -513,4 +513,13 @@ namespace Compiler
|
||||||
mPutbackCode = keyword;
|
mPutbackCode = keyword;
|
||||||
mPutbackLoc = loc;
|
mPutbackLoc = loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scanner::listKeywords (std::vector<std::string>& keywords)
|
||||||
|
{
|
||||||
|
for (int i=0; Compiler::keywords[i]; ++i)
|
||||||
|
keywords.push_back (Compiler::keywords[i]);
|
||||||
|
|
||||||
|
if (mExtensions)
|
||||||
|
mExtensions->listKeywords (keywords);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "tokenloc.hpp"
|
#include "tokenloc.hpp"
|
||||||
|
|
||||||
|
@ -116,6 +117,8 @@ namespace Compiler
|
||||||
void putbackKeyword (int keyword, const TokenLoc& loc);
|
void putbackKeyword (int keyword, const TokenLoc& loc);
|
||||||
///< put back a keyword token
|
///< put back a keyword token
|
||||||
|
|
||||||
|
void listKeywords (std::vector<std::string>& keywords);
|
||||||
|
///< Append all known keywords to \æ kaywords.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue