mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
[poincare] Implement default acceptsLocationInCombination in selector
Change-Id: Ie77fc817f8affc4ca140ef58af755af9e212caa9
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -19,7 +19,7 @@ bool TypeSelector::acceptsLocationInCombination(const Combination * combination,
|
||||
return false;
|
||||
}
|
||||
|
||||
return immediateMatch(combination->expressionForSelectorIndex(location));
|
||||
return Selector::acceptsLocationInCombination(combination, location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user