blob: 84aee1585e7d56018ef880709ae22c9e1bbaa1ea [file] [log] [blame]
#pragma once
#include "Token.h"
#include "VarContext.h"
struct MatchResult {
bool success;
VarContext context;
};
template <typename T>
bool listStartsWith(const QList<T> &haystack, const QList<T> &needle) {
if (needle.length() > haystack.length())
return false;
for (int i = 0; i < needle.length(); i++) {
if (haystack[i] != needle[i])
return false;
}
return true;
}
template <typename T>
void listDrop(QList<T> &list, int n) {
for (; n; n--) {
list.removeFirst();
}
}
template <typename T>
QList<T> listSlice(QList<T> &list, int from, int to) {
QList<T> prime;
// I guess we'll just panic if it's too long
// TODO: ERROR HANDLING
for (int i = 0; i < to - from; i++) {
prime.append(list[from + i]);
}
return prime;
}
MatchResult match(QList<Token> data, QList<Token> pattern, VarContext context);