InputCommon: Add a new ExpressionParser to replace the old hack language

This contains a new, hand-written expression parser to replace the old
hack language based on string munging. The new approach is a simple
AST-based evaluation approach, instead of the "list of operations"
infix-based hack that there was before.

The new language for configuration has support for parentheses, and
counts "!" as a unary operator instead of the binary "NOT OR" operator
it was before. A simple example:

  (X & Y) | !B

Explicit device references, and complex device names ("Right Y+") are
handled with backticks and colons:

  (`SDL/0/6 axis joystick:Right X+` & `DInput/0/Keyboard Mouse:A`)

The basic editor UI that inserts tokens has not been updated to reflect
the new language.
This commit is contained in:
Jasper St. Pierre
2013-06-13 23:09:55 -04:00
parent 877106b027
commit 6246f6e815
7 changed files with 634 additions and 130 deletions

View File

@ -9,6 +9,7 @@
#include "Common.h"
#include "Thread.h"
#include "ExpressionParser.h"
#include "Device.h"
// enable disable sources
@ -53,30 +54,28 @@ public:
class ControlReference
{
friend class ControllerInterface;
public:
virtual ~ControlReference() {}
virtual ControlState State(const ControlState state = 0) = 0;
virtual Device::Control* Detect(const unsigned int ms, Device* const device) = 0;
size_t BoundCount() const { return m_controls.size(); }
ControlState range;
ControlState range;
std::string expression;
const bool is_input;
virtual ~ControlReference() {
delete parsed_expression;
}
int BoundCount() {
if (parsed_expression)
return parsed_expression->num_controls;
else
return 0;
}
protected:
ControlReference(const bool _is_input) : range(1), is_input(_is_input) {}
struct DeviceControl
{
DeviceControl() : control(NULL), mode(0) {}
Device::Control* control;
int mode;
};
std::vector<DeviceControl> m_controls;
ControlReference(const bool _is_input) : range(1), is_input(_is_input), parsed_expression(NULL) {}
ciface::ExpressionParser::Expression *parsed_expression;
};
//