mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
restrutured removing the go source
This commit is contained in:
7
src/include/api.h
Normal file
7
src/include/api.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "result.h"
|
||||
#include "parser.h"
|
||||
|
||||
Result<ParseInfo> transpile(std::string fileContent, bool isDebug);
|
||||
|
||||
std::string escapeText(std::string text);
|
||||
std::string wrapText(std::string text, size_t width);
|
||||
4
src/include/config.h
Normal file
4
src/include/config.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
extern bool debug;
|
||||
|
||||
32
src/include/lexer.h
Normal file
32
src/include/lexer.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "result.h"
|
||||
|
||||
enum class TokenType {
|
||||
TextFragment,
|
||||
QuestionEnd,
|
||||
MatchGroupEnd,
|
||||
ElementDashStart,
|
||||
ElementPlusStart,
|
||||
ElementOrderModifier,
|
||||
Cooldown,
|
||||
CooldownStart,
|
||||
CooldownEnd,
|
||||
StartOfFile,
|
||||
EndOfFile
|
||||
};
|
||||
|
||||
struct Token {
|
||||
TokenType tokenType;
|
||||
std::string content;
|
||||
int32_t row;
|
||||
int32_t column;
|
||||
|
||||
std::string ToString() const;
|
||||
static std::string ToString(const TokenType* ttype);
|
||||
};
|
||||
|
||||
Result<std::vector<Token>> tokenizeMdem(const std::string& fileRunes);
|
||||
53
src/include/parser.h
Normal file
53
src/include/parser.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "lexer.h"
|
||||
#include "result.h"
|
||||
|
||||
|
||||
struct Question {
|
||||
double Cooldown;
|
||||
std::string QuestionText;
|
||||
std::string Section;
|
||||
|
||||
virtual std::string ToString() const = 0;
|
||||
virtual ~Question() = default;
|
||||
};
|
||||
|
||||
struct Choice {
|
||||
std::string Answer;
|
||||
bool IsCorrect;
|
||||
};
|
||||
|
||||
enum MultiElementType {
|
||||
Regular = 0,
|
||||
MultiChoice,
|
||||
Order
|
||||
};
|
||||
|
||||
struct MultiElementQuestion : public Question {
|
||||
std::vector<Choice> Choices;
|
||||
MultiElementType type;
|
||||
|
||||
std::string ToString() const override;
|
||||
};
|
||||
|
||||
struct Group {
|
||||
std::string name;
|
||||
std::vector<std::string> elements;
|
||||
};
|
||||
|
||||
struct GroupQuestion : public Question {
|
||||
std::vector<Group> Groups;
|
||||
|
||||
std::string ToString() const override;
|
||||
};
|
||||
|
||||
struct ParseInfo {
|
||||
std::vector<Question*> questions;
|
||||
time_t lastTrainedAt;
|
||||
};
|
||||
|
||||
Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens);
|
||||
13
src/include/result.h
Normal file
13
src/include/result.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
struct NoneType {};
|
||||
|
||||
template <typename T>
|
||||
struct Result {
|
||||
T value;
|
||||
std::string error = "";
|
||||
int row = -1;
|
||||
int column = -1;
|
||||
};
|
||||
4
src/include/stringUtils.h
Normal file
4
src/include/stringUtils.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
std::string cleanContent(std::string answer);
|
||||
10
src/include/trainWindow.h
Normal file
10
src/include/trainWindow.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
extern QMainWindow *trainWindow;
|
||||
|
||||
void initTrainWindow();
|
||||
void setQuestions(std::vector<Question*> questions);
|
||||
Reference in New Issue
Block a user