Files
fart/src/fart.propane
T
2026-11-03 22:14:41 -05:00

135 lines
2.6 KiB
Plaintext

tree;
tree_prefix P;
ptype double;
<<header
/* User terminate codes. */
#define PARSER_TERMINATE_NUMBER_RANGE 1u
>>
<<
#include <charconv>
/* Store the numeric value of the matched text in *out. Returns false if the
* value cannot be represented. */
static bool parse_number(uint8_t const * match_text, size_t match_length, double * out)
{
const char * first = (const char *)match_text;
const char * last = first + match_length;
std::from_chars_result r = std::from_chars(first, last, *out);
return (r.ec == std::errc()) && (r.ptr == last);
}
>>
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 /</;
token material;
token options;
token plane;
token position;
token rcurly /\}/;
token rotate;
token scale;
token size;
token sphere;
token subtract;
token target;
token translate;
token union;
token up;
token width;
token uint /\d+/ <<
if (!parse_number(match_text, match_length, &$$))
{
$terminate(PARSER_TERMINATE_NUMBER_RANGE);
}
>>
token number /-?\d+(\.\d+)?/ <<
if (!parse_number(match_text, match_length, &$$))
{
$terminate(PARSER_TERMINATE_NUMBER_RANGE);
}
>>
start Scene;
Background -> background Vector;
Color -> color Vector;
Height -> height uint;
Number -> uint;
Number -> number;
Options -> options lcurly OptionsItems rcurly;
OptionsItems -> ;
OptionsItems -> OptionsItem OptionsItems;
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;
Width -> width uint;