mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-12 09:09:12 +01:00
6246f6e815
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.
74 lines
1.4 KiB
C++
74 lines
1.4 KiB
C++
|
|
#ifndef _EXPRESSIONPARSER_H_
|
|
#define _EXPRESSIONPARSER_H_
|
|
|
|
#include <string>
|
|
#include "Device.h"
|
|
|
|
namespace ciface
|
|
{
|
|
namespace ExpressionParser
|
|
{
|
|
|
|
class ControlQualifier
|
|
{
|
|
public:
|
|
bool has_device;
|
|
Core::DeviceQualifier device_qualifier;
|
|
std::string control_name;
|
|
|
|
ControlQualifier() : has_device(false) {}
|
|
|
|
operator std::string()
|
|
{
|
|
if (has_device)
|
|
return device_qualifier.ToString() + ":" + control_name;
|
|
else
|
|
return control_name;
|
|
}
|
|
};
|
|
|
|
class ControlFinder
|
|
{
|
|
public:
|
|
ControlFinder(const Core::DeviceContainer &container_, const Core::DeviceQualifier &default_, const bool is_input_) : container(container_), default_device(default_), is_input(is_input_) {}
|
|
Core::Device::Control *FindControl(ControlQualifier qualifier);
|
|
|
|
private:
|
|
Core::Device *FindDevice(ControlQualifier qualifier);
|
|
const Core::DeviceContainer &container;
|
|
const Core::DeviceQualifier &default_device;
|
|
bool is_input;
|
|
};
|
|
|
|
class Parser;
|
|
class ExpressionNode;
|
|
class Expression
|
|
{
|
|
friend class Parser;
|
|
|
|
public:
|
|
Expression() : expr(NULL) {}
|
|
~Expression();
|
|
ControlState GetValue();
|
|
void SetValue (ControlState state);
|
|
int num_controls;
|
|
|
|
private:
|
|
ExpressionNode *expr;
|
|
};
|
|
|
|
enum ExpressionParseStatus
|
|
{
|
|
EXPRESSION_PARSE_SUCCESS = 0,
|
|
EXPRESSION_PARSE_SYNTAX_ERROR,
|
|
EXPRESSION_PARSE_NO_DEVICE,
|
|
};
|
|
|
|
ExpressionParseStatus ParseExpression(std::string expr, ControlFinder &finder, Expression **expr_out);
|
|
|
|
}
|
|
}
|
|
|
|
#endif
|