blob: c4171919b43ef62d092c29d9ae9c25f81e62f0cd [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;
if (from >= list.length())
return 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);