Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .vscode/log-compiler.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"request": "launch",
"preLaunchTask": "CMake build Debug",
"program": "${workspaceFolder}/out/Debug/Debug/log-compiler.exe",
"args": [ "out/input.md", "-o", "out/out.json", "--debug", "--verbose" ],
"args": [ "out/input.md", "--render", "--debug", "--verbose" ],
"cwd": "${workspaceFolder}",
// "environment": [
// {
Expand Down Expand Up @@ -225,7 +225,23 @@
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"iomanip": "cpp"
"iomanip": "cpp",
"chrono": "cpp",
"variant": "cpp",
"charconv": "cpp",
"format": "cpp",
"forward_list": "cpp",
"locale": "cpp",
"mutex": "cpp",
"optional": "cpp",
"ratio": "cpp",
"regex": "cpp",
"stop_token": "cpp",
"thread": "cpp",
"xlocbuf": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xloctime": "cpp"
},
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"C_Cpp_Runner.cCompilerPath": "gcc",
Expand Down
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ file(GLOB_RECURSE SOURCES
"src/*.cpp"
)

add_executable (${TARGET_NAME} ${SOURCES})
add_executable (${TARGET_NAME} ${SOURCES})

execute_process(
COMMAND git rev-parse HEAD
OUTPUT_VARIABLE LOG_COMPILER_GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
target_compile_definitions(${TARGET_NAME} PUBLIC LOG_COMPILER_GIT_COMMIT_HASH="${LOG_COMPILER_GIT_COMMIT_HASH}")
message(STATUS "GIT_COMMIT_HASH=${LOG_COMPILER_GIT_COMMIT_HASH}")

include(third-party/third-party.cmake)
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ For more information on how to use the Log Compiler, refer to the project's docu

The Log Compiler accepts the following command-line arguments:

**Usage :** `log-compiler InputFile [-o outputFile] [--format json|(markdown|md)|c] [--verbose] [--debug] [-v] [-h]`
**Usage :** `log-compiler InputFile [--output outputFile] [--format json|(markdown|md)|c] [--render] [--version] [--help] [--verbose] [--debug]`

**Positional arguments:**
- `InputFile` : Specifies the input log file to be compiled.

**Optional arguments:**
- `-o`, `--output` : Specifies the output file path (default=./a.{format}).
- `-f`, `--format` : Specifies the output format as `JSON`, `Markdown` or `C + RayGui` format : `[json|(markdown|md)|c]` (default=json).
- `--verbose` : Enables verbose mode for detailed output.
- `--debug` : Enables debug mode for debugging information.
- `-v`, `--version` : display compiler version, then exit.
- `--verbose` : Enables verbose mode for detailed output.
- `-d`, `--debug` : Enables debug mode for debugging information.
- `-h`, `--help` : display this message, then exit.

## Exemple Input File
Expand Down Expand Up @@ -138,13 +138,13 @@ while (!WindowShouldClose())
BeginDrawing();

GuiRenderTitle(1, "Section 1");

GuiBeginBlock();
GuiRenderText("This is a single line zone, and this text is its content.");
GuiEndBlock();

GuiRenderText("This is a plain text Wow what a text ! ");
GuiRenderTextNoPaddingTop("Wow what a second text !");
GuiRenderTextNoPaddingTop("Wow what a second text !");

GuiRenderTitle(1, "Section 2");

Expand Down Expand Up @@ -178,7 +178,7 @@ TitleLevel <- "#" ("#" / "#" / "#" / "#" / "#" / "#")?
Blockquote <- BlockquoteLine+
BlockquoteLine <- ">" Line BlockquoteLineEnd?
SpacingChar <- "\"
Line <- (!EndLine .)* SpacingChar? EndLine
Line <- (!EndLine .)* SpacingChar? EndLine
Text <- (!EndLine .)+
EmptyLine <- (" " / "\n" / "\r" / "\t")*
EndLine <- "\n" / "\r" / "\r\n"
Expand Down
40 changes: 24 additions & 16 deletions src/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const char* OutputFormatsToCstr(CompilerOptions::OutputFormats tokenType)

void StdOutInputFileInfo(const std::string_view& inputFilePath, const std::stringstream& fileContent)
{
std::cout
std::cout
<< "Input file : " << inputFilePath
<< std::endl;
}
Expand All @@ -40,41 +40,44 @@ void StdOutProgram(const ProgramRoot& program)
std::cout << "Program tokens : \n";
for(auto& tokenVariant : program.content)
{
std::visit([](auto&& token)
{
std::visit([](auto&& token)
{
using Type = std::decay_t<decltype(token)>;

if constexpr (!std::is_same_v<NodeToken, Type>)
if constexpr (!std::is_same_v<NodeToken, Type>)
{
std::cout << " " << token << '\n';
std::cout << " " << token << '\n';
}
else
{
std::cout << token << '\n';
std::cout << token << '\n';
}
},
},
tokenVariant);
}

std::cout << std::endl;
}

ParsedCLIParameters ProcessCLIArgs(int argc, const char** argv)
{
{
InputParser inputParser(argc, argv);

if(inputParser.CmdOptionExists("--help") || inputParser.CmdOptionExists("-h"))
{
std::cout
<< ShortCLIUsageStr << '\n'
<< CompleteCLIUsageStr
std::cout
<< ShortCLIUsageStr << '\n'
<< CompleteCLIUsageStr
<< std::endl;
exit(EXIT_SUCCESS);
}

if(inputParser.CmdOptionExists("--version") || inputParser.CmdOptionExists("-v"))
{
std::cout << "LogCompiler " << 'v' << VERSION_MAJOR << '.' << VERSION_MINOR << '.' << VERSION_PATCH << '-' << VERSION_TYPE << std::endl;
std::cout
<< "LogCompiler " << 'v' << LOG_COMPILER_VERSION_MAJOR << '.' << LOG_COMPILER_VERSION_MINOR << '.' << LOG_COMPILER_VERSION_PATCH << '-' << LOG_COMPILER_VERSION_NAME
<< '\n' << "Git rev: " << LOG_COMPILER_GIT_COMMIT_HASH
<< std::endl;
exit(EXIT_SUCCESS);
}

Expand All @@ -88,7 +91,7 @@ ParsedCLIParameters ProcessCLIArgs(int argc, const char** argv)
ParsedCLIParameters params;
params.inputFilePath = inputParser[0];

if(inputParser.CmdOptionExists("--debug"))
if(inputParser.CmdOptionExists("--debug") || inputParser.CmdOptionExists("-d"))
{
CompilerOptions::Debug = true;
std::cout << "You are un debug mode" << std::endl;
Expand All @@ -109,7 +112,7 @@ ParsedCLIParameters ProcessCLIArgs(int argc, const char** argv)
auto format = inputParser.GetCmdOptions("--format", "-f");
std::transform(format.begin(), format.end(), format.begin(),
[](unsigned char c){ return std::tolower(c); });

if(format == "json")
CompilerOptions::OutputFormat = CompilerOptions::OutputFormats::JSON;
else if(format == "markdown" || format == "md")
Expand All @@ -118,15 +121,20 @@ ParsedCLIParameters ProcessCLIArgs(int argc, const char** argv)
CompilerOptions::OutputFormat = CompilerOptions::OutputFormats::C;
else
{
std::cerr
std::cerr
<< "ERROR : invalid --format `" << format << "` is not a valid format. "
<< "Accepted formats are [json|(markdown|md)|c]\n"
<< ShortCLIUsageStr << std::endl;

exit(EXIT_FAILURE);
}
}

if(inputParser.CmdOptionExists("--render") || inputParser.CmdOptionExists("-r"))
{
CompilerOptions::RenderMode = true;
}

if(CompilerOptions::Verbose)
{
std::cout
Expand Down
14 changes: 7 additions & 7 deletions src/CLI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@

const char* OutputFormatsToCstr(CompilerOptions::OutputFormats tokenType);

constexpr const char* ShortCLIUsageStr = "Usage : log-compiler InputFile [-o outputFile] [--format json|(markdown|md)|c] [--verbose] [--debug] [-v] [-h]";
constexpr const char* ShortCLIUsageStr = "Usage : log-compiler InputFile [--output outputFile] [--format json|(markdown|md)|c] [--render] [--version] [--help] [--verbose] [--debug]";

constexpr const char* CompleteCLIUsageStr =
constexpr const char* CompleteCLIUsageStr =
R"(positional arguments:
InputFile Specifies the input log file to be compiled.

optional arguments:
-o, --output Specifies the output file path (optional, default=./a.{format}).
--format Specifies the output format as `JSON`, `Markdown` or `C + RayGui` format : `[json|(markdown|md)|c]` (optional, default=json).
--verbose Enables verbose mode for detailed output (optional).
--debug Enables debug mode for debugging information (optional).
-o, --output Specifies the output file path (default=./a.{format}).
-f, --format Specifies the output format as `JSON`, `Markdown` or `C + RayGui` format : `[json|(markdown|md)|c]` (default=json).
-v, --version display compiler version, then exit.
--verbose Enables verbose mode for detailed output.
-d, --debug Enables debug mode for debugging information.
-h, --help display this message, then exit.
)";

void StdOutInputFileInfo(const std::string_view& inputFilePath, const std::stringstream& fileContent);
void StdOutTokens(const std::vector<Token>& tokens);
void StdOutProgram(const ProgramRoot& program);

struct ParsedCLIParameters
struct ParsedCLIParameters
{
std::string inputFilePath;
std::string outputFilePath;
Expand Down
117 changes: 117 additions & 0 deletions src/Compilation/RenderMode/RenderModeGui.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#pragma once

#include <raylib.h>
#include <raygui.h>
#include <concepts>

#include "../ProgramTokens.hpp"

class RenderVisitor
{
public:
RenderVisitor() = default;

template<typename TToken>
void operator()(const TToken& value);

private:
float Offset = 0;
};

void RenderModeContent(RenderVisitor& visitor, const NodeContent &nodeContent);

template <> void RenderVisitor::operator()<NodeToken>(const NodeToken& value);
template <> void RenderVisitor::operator()<TextBlockToken>(const TextBlockToken& value);
template <> void RenderVisitor::operator()<QuoteBlockToken>(const QuoteBlockToken& value);

template <class TToken>
inline void RenderVisitor::operator()(const TToken &value)
{
static_assert(assert_false_v<TToken>, "Unhandled Token Type, please add a visitor specialisation for this type");
}

#define MARGIN_X 10
#define MARGIN_Y 3
#define HEIGHT 15

template <>
void RenderVisitor::operator()(const NodeToken &token)
{
Rectangle rect = {
.x = MARGIN_X,
.y = Offset + MARGIN_Y,
.width = (float)GetScreenWidth(),
.height = HEIGHT
};

GuiLabel(rect, token.title.text.c_str());
Offset += rect.height;

RenderModeContent(*this, token.content);
}

template <>
void RenderVisitor::operator()(const TextBlockToken &value)
{
for(auto& line : value.lines)
{
Rectangle rect = {
.x = MARGIN_X,
.y = Offset + MARGIN_Y,
.width = (float)GetScreenWidth(),
.height = HEIGHT
};

GuiLabel(rect, line.c_str());
Offset += rect.height;
}
}

template <>
void RenderVisitor::operator()(const QuoteBlockToken &value)
{
for(auto& line : value.lines)
{
Rectangle rect = {
.x = MARGIN_X,
.y = Offset + MARGIN_Y,
.width = (float)GetScreenWidth(),
.height = HEIGHT
};

GuiLabel(rect, line.c_str());
Offset += rect.height;
}
}

void RenderModeContent(RenderVisitor& visitor, const NodeContent &nodeContent)
{
for(auto& node : nodeContent)
{
std::visit([&](auto&& token)
{
visitor(token);
}, node);
}
}

void RenderMode(ProgramRoot& programRoot)
{
SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
InitWindow(1080, 720, "Hello Raylib !");
SetTargetFPS(144);

// GuiSetStyle(DEFAULT, TEXT_SIZE, 25);

while(!WindowShouldClose())
{
RenderVisitor visitor;

BeginDrawing();
ClearBackground(WHITE);
RenderModeContent(visitor, programRoot.content);
EndDrawing();
}

CloseWindow();
}
Loading
Loading