This commit makes the parser accept the following constructs:

- per_frameinit_1=...   (becomes per_frame=)
- per_frame=            (or per_vertex; is ignored)
- per_frame=//...       (or per_vertex; is ignored)
---
 src/compiler/parser.y   |   17 +++++++++++++----
 src/compiler/scanner.re |    3 ++-
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/compiler/parser.y b/src/compiler/parser.y
index 3fe25df..23754c0 100644
--- a/src/compiler/parser.y
+++ b/src/compiler/parser.y
@@ -119,8 +119,8 @@ assignments ::= assignments assignment.
 
 assignments ::= .
 
-assignment ::= context(C) ident(I) TOK_ASSIGN node(N) opt_semi. {
-       state->error = C(state->comm, I->label, N);
+assignment ::= ident(I) TOK_ASSIGN node(N) opt_semi. {
+       state->error = state->comm->assign_default(state->comm, I->label, N);
        if(state->error) {
                syntax_error(state);
                yy_parse_failed(yypParser);
@@ -139,8 +139,17 @@ assignment ::= TOK_IMAGEFILE(I) TOK_ASSIGN TOK_FNAME(N). {
        }
 }
 
-context(C) ::= . {
-       C = state->comm->assign_default;
+assignment ::= context(C). {
+       /*
+        * @@@ Vile madness ahead: a lot of patches have per_frame= or
+        * per_vertex= tags followed by nothing else. We work around the
+        * syntax issue by making these tags "sticky".
+        *
+        * This subtly changes the semantics. Also, changing assign_default
+        * is not a good idea, since the caller may rely on it staying the
+        * same.
+        */
+       state->comm->assign_default = C;
 }
 
 context(C) ::= TOK_PER_FRAME TOK_ASSIGN. {
diff --git a/src/compiler/scanner.re b/src/compiler/scanner.re
index e478f91..d162da9 100644
--- a/src/compiler/scanner.re
+++ b/src/compiler/scanner.re
@@ -116,7 +116,8 @@ int scan(struct scanner *s)
                <N>"sqrt"               { return TOK_SQRT; }
                <N>"tsign"              { return TOK_TSIGN; }
 
-               <N>"per_frame"          { return TOK_PER_FRAME; }
+               <N>"per_frame"[a-z_0-9]*
+                                       { return TOK_PER_FRAME; }
                <N>"per_vertex"         { return TOK_PER_VERTEX; }
                <N>"per_pixel"          { return TOK_PER_PIXEL; }
 
-- 
1.7.1

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to