Add shapes to grammar

This commit is contained in:
josh committed 2026-11-03 22:14:41 -05:00
1 parent fa77c0af29
commit d8a37c6e9a
3 files changed
+69 -5

No files matched your search

+63 -1
View File
@@ -22,15 +22,33 @@ static bool parse_number(uint8_t const * match_text, size_t match_length, double
>> >>
drop /\s+/; drop /\s+/;
drop /#.*/;
token background; token background;
token box;
token camera;
token color;
token comma /,/; token comma /,/;
token cyl;
token gt />/; token gt />/;
token height; token height;
token intersect;
token lcurly /\{/; token lcurly /\{/;
token lt /</; token lt /</;
token material;
token options; token options;
token plane;
token position;
token rcurly /\}/; token rcurly /\}/;
token rotate;
token scale;
token size;
token sphere;
token subtract;
token target;
token translate;
token union;
token up;
token width; token width;
token uint /\d+/ << token uint /\d+/ <<
@@ -46,10 +64,12 @@ token number /-?\d+(\.\d+)?/ <<
} }
>> >>
Start -> Options? SceneItems; start Scene;
Background -> background Vector; Background -> background Vector;
Color -> color Vector;
Height -> height uint; Height -> height uint;
Number -> uint; Number -> uint;
@@ -64,7 +84,49 @@ OptionsItem -> Background;
OptionsItem -> Height; OptionsItem -> Height;
OptionsItem -> Width; OptionsItem -> Width;
Position -> position Vector;
Rotate -> rotate Number comma Vector;
Rotate -> rotate Number comma Vector lcurly SceneItems rcurly;
Scale -> scale Number;
Scale -> scale Number lcurly SceneItems rcurly;
Scale -> scale Vector;
Scale -> scale Vector lcurly SceneItems rcurly;
SceneItemBlock -> SceneItemName lcurly SceneItems rcurly;
Scene -> Options? SceneItems;
SceneItems -> ; SceneItems -> ;
SceneItems -> SceneItem SceneItems;
SceneItem -> Color;
SceneItem -> Position;
SceneItem -> Rotate;
SceneItem -> Scale;
SceneItem -> SceneItemBlock;
SceneItem -> Size;
SceneItem -> Target;
SceneItem -> Translate;
SceneItem -> Up;
SceneItemName -> box;
SceneItemName -> camera;
SceneItemName -> cyl;
SceneItemName -> material;
SceneItemName -> plane;
SceneItemName -> sphere;
Size -> size Number;
Size -> size Vector;
Target -> target Vector;
Translate -> translate Vector;
Translate -> translate Vector lcurly SceneItems rcurly;
Up -> up Vector;
Vector -> lt Number comma Number comma Number gt; Vector -> lt Number comma Number comma Number gt;
Vector -> lt Number comma Number comma Number comma Number gt; Vector -> lt Number comma Number comma Number comma Number gt;
+4 -2
View File
@@ -112,13 +112,15 @@ static Color vector_to_color(PVector vector)
return color; return color;
} }
Scene * Parser::build_scene(const string_view & input_file, PStart start) Scene * Parser::build_scene(const string_view & input_file, PScene pscene)
{ {
Scene * scene = new Scene(); Scene * scene = new Scene();
/* If the options block is absent, pOptions() returns a null node and so /* If the options block is absent, pOptions() returns a null node and so
* does pOptionsItems() on it, so the loop body is skipped. */ * does pOptionsItems() on it, so the loop body is skipped. */
for (POptionsItems items = start.pOptions().pOptionsItems(); p_node_valid(items); items = items.pOptionsItems()) for (POptionsItems items = pscene.pOptions().pOptionsItems();
p_node_valid(items);
items = items.pOptionsItems())
{ {
POptionsItem item = items.pOptionsItem(); POptionsItem item = items.pOptionsItem();
bool ok = true; bool ok = true;
+2 -2
View File
@@ -2,7 +2,7 @@
#include <fart/Scene.h> #include <fart/Scene.h>
struct PStart; struct PScene;
class Parser class Parser
{ {
@@ -10,5 +10,5 @@ public:
static Scene * load_scene(const string_view & input_file); static Scene * load_scene(const string_view & input_file);
private: private:
static Scene * build_scene(const string_view & input_file, PStart start); static Scene * build_scene(const string_view & input_file, PScene pscene);
}; };