Invoke propane to parse input file
This commit is contained in:
1 parent
88bfc29323
commit
0a979c487c
5 files changed
+74
-1
No files matched your search
@@ -1,4 +1,5 @@
|
|||||||
tree;
|
tree;
|
||||||
|
tree_prefix P;
|
||||||
|
|
||||||
drop /\s+/;
|
drop /\s+/;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <fart/Engine.h>
|
#include <fart/Engine.h>
|
||||||
|
#include <fart/Parser.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -8,6 +9,11 @@ Engine::Engine(const RenderParams & params)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Engine::~Engine()
|
||||||
|
{
|
||||||
|
delete scene;
|
||||||
|
}
|
||||||
|
|
||||||
int Engine::run(string_view input_file, opt<string_view> output_file)
|
int Engine::run(string_view input_file, opt<string_view> output_file)
|
||||||
{
|
{
|
||||||
string output_path;
|
string output_path;
|
||||||
@@ -49,5 +55,12 @@ int Engine::run(string_view input_file, opt<string_view> output_file)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete scene;
|
||||||
|
scene = Parser::load_scene(input_file);
|
||||||
|
if (!scene)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2,15 +2,18 @@
|
|||||||
|
|
||||||
#include <fart/ImageWriter.h>
|
#include <fart/ImageWriter.h>
|
||||||
#include <fart/RenderParams.h>
|
#include <fart/RenderParams.h>
|
||||||
|
#include <fart/Scene.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class Engine
|
class Engine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Engine(const RenderParams & params);
|
Engine(const RenderParams & params);
|
||||||
|
~Engine();
|
||||||
int run(string_view input_file, opt<string_view> output_file);
|
int run(string_view input_file, opt<string_view> output_file);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RenderParams params;
|
RenderParams params;
|
||||||
std::unique_ptr<ImageWriter> image_writer;
|
std::unique_ptr<ImageWriter> image_writer;
|
||||||
|
Scene * scene = nullptr;
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#include <fart/Parser.h>
|
#include <fart/Parser.h>
|
||||||
|
#include <fart/propane.h>
|
||||||
#include <fart/read_file.h>
|
#include <fart/read_file.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
Scene * Parser::load_scene(const string_view & input_file)
|
Scene * Parser::load_scene(const string_view & input_file)
|
||||||
{
|
{
|
||||||
@@ -8,5 +10,59 @@ Scene * Parser::load_scene(const string_view & input_file)
|
|||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p_context_t * context = p_context_new(input->data(), input->size());
|
||||||
|
size_t result = p_parse(context);
|
||||||
|
p_position_t pos = p_position(context);
|
||||||
|
int fname_len = (int)input_file.size();
|
||||||
|
const char * fname = input_file.data();
|
||||||
|
bool success = false;
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case P_SUCCESS:
|
||||||
|
success = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case P_DECODE_ERROR:
|
||||||
|
fprintf(stderr, "%.*s:%u:%u: error: invalid UTF-8 encoding\n",
|
||||||
|
fname_len, fname, pos.row, pos.col);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case P_UNEXPECTED_INPUT:
|
||||||
|
fprintf(stderr, "%.*s:%u:%u: error: unexpected input\n",
|
||||||
|
fname_len, fname, pos.row, pos.col);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case P_UNEXPECTED_TOKEN:
|
||||||
|
{
|
||||||
|
p_token_t token = p_token(context);
|
||||||
|
if (token == TOKEN___EOF)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%.*s:%u:%u: error: unexpected end of input\n",
|
||||||
|
fname_len, fname, pos.row, pos.col);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%.*s:%u:%u: error: unexpected token '%s'\n",
|
||||||
|
fname_len, fname, pos.row, pos.col, p_token_names[token]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "%.*s:%u:%u: internal error: unknown parser result %zu\n",
|
||||||
|
fname_len, fname, pos.row, pos.col, result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
p_context_delete(context);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: populate the Scene from p_result(context). */
|
||||||
|
Scene * scene = new Scene();
|
||||||
|
p_context_delete(context);
|
||||||
|
return scene;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <fart/propane.h>
|
#include <fart/Scene.h>
|
||||||
|
|
||||||
class Parser
|
class Parser
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user