[poincare] Implement default acceptsLocationInCombination in selector

Change-Id: Ie77fc817f8affc4ca140ef58af755af9e212caa9
This commit is contained in:
Émilie Feral
2017-10-02 16:18:47 +02:00
parent d4e5f60b5c
commit 8abbc66dce
6 changed files with 12 additions and 22 deletions

View File

@@ -15,7 +15,6 @@ products += $(rulesets)
objs += $(addprefix $(prefix)/,\
expression_simplify.o \
rule.o \
selector/any_selector.o \
selector/combination.o \
selector/selector.o \
selector/type_and_identifier_selector.o \

View File

@@ -1,18 +0,0 @@
#include "any_selector.h"
#include "combination.h"
namespace Poincare {
namespace Simplification {
bool AnySelector::acceptsLocationInCombination(const Combination * combination, int location) const {
// Yes, if no other slot in the combination before me is the same
for (int i=0; i<location; i++) {
if (combination->expressionIndexForSelectorIndex(i) == combination->expressionIndexForSelectorIndex(location)) {
return false;
}
}
return immediateMatch(combination->expressionForSelectorIndex(location));
}
}
}

View File

@@ -9,7 +9,6 @@ namespace Simplification {
class AnySelector : public Selector {
public:
using Selector::Selector;
bool acceptsLocationInCombination(const Combination * combination, int location) const override;
bool immediateMatch(const Expression * e) const override {
return true;
}

View File

@@ -5,6 +5,16 @@
namespace Poincare {
namespace Simplification {
bool Selector::acceptsLocationInCombination(const Combination * combination, int location) const {
// Yes, if no other slot in the combination before me is the same
for (int i=0; i<location; i++) {
if (combination->expressionIndexForSelectorIndex(i) == combination->expressionIndexForSelectorIndex(location)) {
return false;
}
}
return immediateMatch(combination->expressionForSelectorIndex(location));
}
bool Selector::match(const Expression * e, Expression ** captures, int captureLength) const {
// Test that root selector match root expression
if (!immediateMatch(e)) {

View File

@@ -12,7 +12,7 @@ class Selector {
public:
constexpr Selector(int captureIndex = -1, const Selector * const * children = nullptr, int numberOfChildren = 0, bool childrenPartialMatch = true) :
m_captureIndex(captureIndex), m_children(children), m_numberOfChildren(numberOfChildren), m_childrenPartialMatch(childrenPartialMatch) {}
virtual bool acceptsLocationInCombination(const Combination * combination, int location) const = 0;
virtual bool acceptsLocationInCombination(const Combination * combination, int location) const;
virtual bool immediateMatch(const Expression * e) const = 0;
bool match(const Expression * e, Expression ** captures, int captureLength) const;
private:

View File

@@ -19,7 +19,7 @@ bool TypeSelector::acceptsLocationInCombination(const Combination * combination,
return false;
}
return immediateMatch(combination->expressionForSelectorIndex(location));
return Selector::acceptsLocationInCombination(combination, location);
}
}