summaryrefslogtreecommitdiffstats
path: root/dimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-02-25 02:10:26 -0500
committerTavian Barnes <tavianator@gmail.com>2010-02-25 02:10:26 -0500
commita893d72c2caf3b8dc457115f6409b6bf66a5adbc (patch)
tree2f54bd0774cf91189be2f7afd7ae1a8fd8c9c113 /dimension
parent21794278ae305acd5dc13d0cd6a491f420b69880 (diff)
downloaddimension-a893d72c2caf3b8dc457115f6409b6bf66a5adbc.tar.xz
Parse interiors.
Diffstat (limited to 'dimension')
-rw-r--r--dimension/common.nonterminals4
-rw-r--r--dimension/common.rules19
-rw-r--r--dimension/common.terminals4
-rw-r--r--dimension/directives.rules1
-rw-r--r--dimension/grammar.epilogue3
-rw-r--r--dimension/lexer.l2
-rw-r--r--dimension/parse.h3
-rw-r--r--dimension/realize.c44
8 files changed, 73 insertions, 7 deletions
diff --git a/dimension/common.nonterminals b/dimension/common.nonterminals
index 7513f9c..c3b2b3f 100644
--- a/dimension/common.nonterminals
+++ b/dimension/common.nonterminals
@@ -59,6 +59,10 @@
%type <astnode> REFLECTION
%type <astnode> REFLECTION_ITEMS
+/* Interiors */
+%type <astnode> INTERIOR
+%type <astnode> INTERIOR_ITEMS
+
/* Floats */
%type <astnode> FLOAT
%type <astnode> FLOAT_LITERAL
diff --git a/dimension/common.rules b/dimension/common.rules
index f0e8eae..7b4c609 100644
--- a/dimension/common.rules
+++ b/dimension/common.rules
@@ -153,6 +153,7 @@ OBJECT_MODIFIER: TRANSFORMATION
| PIGMENT {
$$ = dmnsn_new_astnode1(DMNSN_AST_TEXTURE, @$, $1);
}
+ | INTERIOR
;
/* Textures */
@@ -259,6 +260,24 @@ REFLECTION_ITEMS: /* empty */ {
}
;
+/* Interiores */
+INTERIOR: "interior" "{"
+ INTERIOR_ITEMS
+ "}"
+ { $$ = $3; }
+;
+
+INTERIOR_ITEMS: /* empty */ {
+ $$ = dmnsn_new_astnode(DMNSN_AST_INTERIOR, @$);
+ }
+ | INTERIOR_ITEMS "ior" FLOAT {
+ dmnsn_astnode diffuse = dmnsn_new_astnode1(DMNSN_AST_IOR,
+ @2, $3);
+ $$ = $1;
+ dmnsn_array_push($$.children, &diffuse);
+ }
+;
+
/* Floats */
FLOAT: ARITH_EXPR {
diff --git a/dimension/common.terminals b/dimension/common.terminals
index c50c7a9..fbe1eb2 100644
--- a/dimension/common.terminals
+++ b/dimension/common.terminals
@@ -233,14 +233,14 @@
%token DMNSN_T_INSIDE
%token DMNSN_T_INSIDE_VECTOR
%token DMNSN_T_INT
-%token DMNSN_T_INTERIOR
+%token DMNSN_T_INTERIOR "interior"
%token DMNSN_T_INTERIOR_TEXTURE
%token DMNSN_T_INTERNAL
%token DMNSN_T_INTERPOLATE
%token DMNSN_T_INTERSECTION
%token DMNSN_T_INTERVALS
%token DMNSN_T_INVERSE
-%token DMNSN_T_IOR
+%token DMNSN_T_IOR "ior"
%token DMNSN_T_IRID
%token DMNSN_T_IRID_WAVELENGTH
%token DMNSN_T_ISOSURFACE
diff --git a/dimension/directives.rules b/dimension/directives.rules
index 6f8a812..f3f3e7a 100644
--- a/dimension/directives.rules
+++ b/dimension/directives.rules
@@ -85,6 +85,7 @@ RVALUE: ARITH_EXPR ";" %dprec 2 {
| TEXTURE
| PIGMENT
| FINISH
+ | INTERIOR
| CAMERA
| TRANSFORMATION
diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue
index 6ea4e28..877b876 100644
--- a/dimension/grammar.epilogue
+++ b/dimension/grammar.epilogue
@@ -152,6 +152,9 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type)
dmnsn_astnode_map(DMNSN_AST_REFLECTION_ITEMS, "reflection-items");
dmnsn_astnode_map(DMNSN_AST_FALLOFF, "falloff");
+ dmnsn_astnode_map(DMNSN_AST_INTERIOR, "interior");
+ dmnsn_astnode_map(DMNSN_AST_IOR, "ior");
+
dmnsn_astnode_map(DMNSN_AST_FLOAT, "float");
dmnsn_astnode_map(DMNSN_AST_INTEGER, "integer");
diff --git a/dimension/lexer.l b/dimension/lexer.l
index 77320c5..6531e0c 100644
--- a/dimension/lexer.l
+++ b/dimension/lexer.l
@@ -179,6 +179,8 @@ unsigned long wchar;
"gray" RETURN_TOKEN(DMNSN_T_GRAY);
"grey" RETURN_TOKEN(DMNSN_T_GRAY);
"green" RETURN_TOKEN(DMNSN_T_GREEN);
+"interior" RETURN_TOKEN(DMNSN_T_INTERIOR);
+"ior" RETURN_TOKEN(DMNSN_T_IOR);
"location" RETURN_TOKEN(DMNSN_T_LOCATION);
"look_at" RETURN_TOKEN(DMNSN_T_LOOK_AT);
"light_source" RETURN_TOKEN(DMNSN_T_LIGHT_SOURCE);
diff --git a/dimension/parse.h b/dimension/parse.h
index 9db4981..9511eab 100644
--- a/dimension/parse.h
+++ b/dimension/parse.h
@@ -66,6 +66,9 @@ typedef enum {
DMNSN_AST_REFLECTION_ITEMS,
DMNSN_AST_FALLOFF,
+ DMNSN_AST_INTERIOR,
+ DMNSN_AST_IOR,
+
DMNSN_AST_FLOAT,
DMNSN_AST_INTEGER,
diff --git a/dimension/realize.c b/dimension/realize.c
index 810d86e..b20ec9f 100644
--- a/dimension/realize.c
+++ b/dimension/realize.c
@@ -504,18 +504,18 @@ dmnsn_realize_texture(dmnsn_astnode astnode)
unsigned int i;
for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
- dmnsn_astnode modifier;
- dmnsn_array_get(astnode.children, i, &modifier);
+ dmnsn_astnode item;
+ dmnsn_array_get(astnode.children, i, &item);
- switch (modifier.type) {
+ switch (item.type) {
case DMNSN_AST_PIGMENT:
dmnsn_delete_pigment(texture->pigment);
- texture->pigment = dmnsn_realize_pigment(modifier);
+ texture->pigment = dmnsn_realize_pigment(item);
break;
case DMNSN_AST_FINISH:
dmnsn_delete_finish(texture->finish);
- texture->finish = dmnsn_realize_finish(modifier);
+ texture->finish = dmnsn_realize_finish(item);
break;
default:
@@ -526,6 +526,35 @@ dmnsn_realize_texture(dmnsn_astnode astnode)
return texture;
}
+static dmnsn_interior *
+dmnsn_realize_interior(dmnsn_astnode astnode)
+{
+ dmnsn_assert(astnode.type == DMNSN_AST_INTERIOR, "Expected a texture.");
+
+ dmnsn_interior *interior = dmnsn_new_interior();
+ if (!interior) {
+ dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't allocate interior.");
+ }
+
+ unsigned int i;
+ for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ dmnsn_astnode item, child;
+ dmnsn_array_get(astnode.children, i, &item);
+
+ switch (item.type) {
+ case DMNSN_AST_IOR:
+ dmnsn_array_get(item.children, 0, &child);
+ interior->ior = dmnsn_realize_float(child);
+ break;
+
+ default:
+ dmnsn_assert(false, "Invalid interior item.");
+ }
+ }
+
+ return interior;
+}
+
static void
dmnsn_realize_object_modifiers(dmnsn_astnode astnode, dmnsn_object *object)
{
@@ -562,6 +591,11 @@ dmnsn_realize_object_modifiers(dmnsn_astnode astnode, dmnsn_object *object)
object->texture = dmnsn_realize_texture(modifier);
break;
+ case DMNSN_AST_INTERIOR:
+ dmnsn_delete_interior(object->interior);
+ object->interior = dmnsn_realize_interior(modifier);
+ break;
+
default:
dmnsn_assert(false, "Invalid object modifier.");
}