[gtk+/wip/otte/shader: 23/55] gsksl: Introduce gsk_sl_preprocessor_sync()



commit 735693cf1ef6fcbba0e68650cbb416e39b856825
Author: Benjamin Otte <otte redhat com>
Date:   Thu Sep 28 13:34:46 2017 +0200

    gsksl: Introduce gsk_sl_preprocessor_sync()
    
    Instead of just returning after an error an continuing to parse
    wherever, use gsk_sl_preprocessor_sync() to find the next point in the
    token stream that looks like a useful way to continue parsing.

 gsk/gskslfunction.c            |    6 +++---
 gsk/gskslnode.c                |    8 +++++---
 gsk/gskslpointertype.c         |    8 +++++---
 gsk/gskslpreprocessor.c        |   32 ++++++++++++++++++++++++++++++++
 gsk/gskslpreprocessorprivate.h |    2 ++
 gsk/gskslprogram.c             |    8 +++++---
 6 files changed, 52 insertions(+), 12 deletions(-)
---
diff --git a/gsk/gskslfunction.c b/gsk/gskslfunction.c
index f51aeac..dd91425 100644
--- a/gsk/gskslfunction.c
+++ b/gsk/gskslfunction.c
@@ -389,7 +389,7 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
   if (!gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
     {
       gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected a closing \")\"");
-      return (GskSlFunction *) function;
+      gsk_sl_preprocessor_sync (preproc, GSK_SL_TOKEN_RIGHT_PAREN);
     }
   gsk_sl_preprocessor_consume (preproc, (GskSlNode *) function);
 
@@ -421,8 +421,8 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
 
   if (!gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_BRACE))
     {
-      gsk_sl_preprocessor_error (preproc, SYNTAX, "Missing closing \"}\" at end.");
-      return (GskSlFunction *) function;
+      gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected closing \"}\" at end of function.");
+      gsk_sl_preprocessor_sync (preproc, GSK_SL_TOKEN_RIGHT_BRACE);
     }
   gsk_sl_preprocessor_consume (preproc, (GskSlNode *) function);
 
diff --git a/gsk/gskslnode.c b/gsk/gskslnode.c
index 2d34332..9eb5574 100644
--- a/gsk/gskslnode.c
+++ b/gsk/gskslnode.c
@@ -472,9 +472,11 @@ gsk_sl_node_parse_statement (GskSlScope        *scope,
 
   token = gsk_sl_preprocessor_get (preproc);
   if (!gsk_sl_token_is (token, GSK_SL_TOKEN_SEMICOLON))
-    gsk_sl_preprocessor_error (preproc, SYNTAX, "No semicolon at end of statement.");
-  else
-    gsk_sl_preprocessor_consume (preproc, (GskSlNode *) node);
+    {
+      gsk_sl_preprocessor_error (preproc, SYNTAX, "No semicolon at end of statement.");
+      gsk_sl_preprocessor_sync (preproc, GSK_SL_TOKEN_SEMICOLON);
+    }
+  gsk_sl_preprocessor_consume (preproc, (GskSlNode *) node);
 
   return node;
 }
diff --git a/gsk/gskslpointertype.c b/gsk/gskslpointertype.c
index c3f38b5..2df1379 100644
--- a/gsk/gskslpointertype.c
+++ b/gsk/gskslpointertype.c
@@ -332,9 +332,11 @@ gsk_sl_decoration_list_parse (GskSlScope        *scope,
 
           token = gsk_sl_preprocessor_get (preproc);
           if (gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
-            gsk_sl_preprocessor_consume (preproc, NULL);
-          else
-            gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected closing \")\" at end of layout specifier");
+            {
+              gsk_sl_preprocessor_error (preproc, SYNTAX, "Expected closing \")\" at end of layout 
specifier");
+              gsk_sl_preprocessor_sync (preproc, GSK_SL_TOKEN_RIGHT_PAREN);
+            }
+          gsk_sl_preprocessor_consume (preproc, NULL);
           break;
 
         default:
diff --git a/gsk/gskslpreprocessor.c b/gsk/gskslpreprocessor.c
index 487800e..09aee75 100644
--- a/gsk/gskslpreprocessor.c
+++ b/gsk/gskslpreprocessor.c
@@ -377,6 +377,38 @@ gsk_sl_preprocessor_consume (GskSlPreprocessor *preproc,
 }
 
 void
+gsk_sl_preprocessor_sync (GskSlPreprocessor *preproc,
+                          GskSlTokenType     token_type)
+{
+  const GskSlToken *token;
+
+  for (token = gsk_sl_preprocessor_get (preproc);
+       !gsk_sl_token_is (token, GSK_SL_TOKEN_EOF) && !gsk_sl_token_is (token, token_type);
+       token = gsk_sl_preprocessor_get (preproc))
+    {
+      if (gsk_sl_token_is (token, GSK_SL_TOKEN_LEFT_BRACE))
+        {
+          gsk_sl_preprocessor_consume (preproc, NULL);
+          gsk_sl_preprocessor_sync (preproc, GSK_SL_TOKEN_RIGHT_BRACE);
+        }
+      else if (gsk_sl_token_is (token, GSK_SL_TOKEN_LEFT_BRACKET))
+        {
+          gsk_sl_preprocessor_consume (preproc, NULL);
+          gsk_sl_preprocessor_sync (preproc, GSK_SL_TOKEN_RIGHT_BRACKET);
+        }
+      else if (gsk_sl_token_is (token, GSK_SL_TOKEN_LEFT_PAREN))
+        {
+          gsk_sl_preprocessor_consume (preproc, NULL);
+          gsk_sl_preprocessor_sync (preproc, GSK_SL_TOKEN_RIGHT_PAREN);
+        }
+      else
+        {
+          gsk_sl_preprocessor_consume (preproc, NULL);
+        }
+    }
+}
+
+void
 gsk_sl_preprocessor_emit_error (GskSlPreprocessor     *preproc,
                                 gboolean               fatal,
                                 const GskCodeLocation *location,
diff --git a/gsk/gskslpreprocessorprivate.h b/gsk/gskslpreprocessorprivate.h
index b6544cc..13755d1 100644
--- a/gsk/gskslpreprocessorprivate.h
+++ b/gsk/gskslpreprocessorprivate.h
@@ -37,6 +37,8 @@ const GskCodeLocation * gsk_sl_preprocessor_get_location        (GskSlPreprocess
 void                    gsk_sl_preprocessor_consume             (GskSlPreprocessor   *preproc,
                                                                  gpointer             consumer);
 
+void                    gsk_sl_preprocessor_sync                (GskSlPreprocessor   *preproc,
+                                                                 GskSlTokenType       token);
 void                    gsk_sl_preprocessor_emit_error          (GskSlPreprocessor   *preproc,
                                                                  gboolean             fatal,
                                                                  const GskCodeLocation *location,
diff --git a/gsk/gskslprogram.c b/gsk/gskslprogram.c
index 47b68be..3d47dd6 100644
--- a/gsk/gskslprogram.c
+++ b/gsk/gskslprogram.c
@@ -119,9 +119,11 @@ gsk_sl_program_parse_variable (GskSlProgram      *program,
     }
 
   if (!gsk_sl_token_is (token, GSK_SL_TOKEN_SEMICOLON))
-    gsk_sl_preprocessor_error (preproc, SYNTAX, "No semicolon at end of variable declaration.");
-  else
-    gsk_sl_preprocessor_consume (preproc, NULL);
+    {
+      gsk_sl_preprocessor_error (preproc, SYNTAX, "No semicolon at end of variable declaration.");
+      gsk_sl_preprocessor_sync (preproc, GSK_SL_TOKEN_SEMICOLON);
+    }
+  gsk_sl_preprocessor_consume (preproc, NULL);
 
   pointer_type = gsk_sl_pointer_type_new (type, FALSE, 
decoration->values[GSK_SL_DECORATION_CALLER_ACCESS].value);
   variable = gsk_sl_variable_new (pointer_type, g_strdup (name), value, 
decoration->values[GSK_SL_DECORATION_CONST].set);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]