From d8a37c6e9aedaa7b3a1872b2fc8cf8f74882c330 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 3 Nov 2026 21:44:43 -0500 Subject: [PATCH] Add shapes to grammar --- src/fart.propane | 64 ++++++++++++++++++++++++++++++++++++++++++++- src/fart/Parser.cpp | 6 +++-- src/fart/Parser.h | 4 +-- 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/fart.propane b/src/fart.propane index 5ad6515..bcc7cbc 100644 --- a/src/fart.propane +++ b/src/fart.propane @@ -22,15 +22,33 @@ static bool parse_number(uint8_t const * match_text, size_t match_length, double >> drop /\s+/; +drop /#.*/; token background; +token box; +token camera; +token color; token comma /,/; +token cyl; token gt />/; token height; +token intersect; token lcurly /\{/; token lt /> -Start -> Options? SceneItems; +start Scene; Background -> background Vector; +Color -> color Vector; + Height -> height uint; Number -> uint; @@ -64,7 +84,49 @@ OptionsItem -> Background; OptionsItem -> Height; 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 -> 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 comma Number gt; diff --git a/src/fart/Parser.cpp b/src/fart/Parser.cpp index 15f8267..e821138 100644 --- a/src/fart/Parser.cpp +++ b/src/fart/Parser.cpp @@ -112,13 +112,15 @@ static Color vector_to_color(PVector vector) 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(); /* If the options block is absent, pOptions() returns a null node and so * 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(); bool ok = true; diff --git a/src/fart/Parser.h b/src/fart/Parser.h index f3bb243..2bd188f 100644 --- a/src/fart/Parser.h +++ b/src/fart/Parser.h @@ -2,7 +2,7 @@ #include -struct PStart; +struct PScene; class Parser { @@ -10,5 +10,5 @@ public: static Scene * load_scene(const string_view & input_file); private: - static Scene * build_scene(const string_view & input_file, PStart start); + static Scene * build_scene(const string_view & input_file, PScene pscene); };