[前][次][番号順一覧][スレッド一覧]

ruby-changes:53813

From: duerst <ko1@a...>
Date: Tue, 27 Nov 2018 19:15:52 +0900 (JST)
Subject: [ruby-changes:53813] duerst:r66031 (trunk): introduce helper function quantify_property_node()

duerst	2018-11-27 19:15:45 +0900 (Tue, 27 Nov 2018)

  New Revision: 66031

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66031

  Log:
    introduce helper function quantify_property_node()
    
    The new function quantify_property_node() combines the functions
    create_property_node() and quantify_node(), which frequently appear together.

  Modified files:
    trunk/regparse.c
Index: regparse.c
===================================================================
--- regparse.c	(revision 66030)
+++ regparse.c	(revision 66031)
@@ -5751,6 +5751,15 @@ quantify_node(Node **np, int lower, int https://github.com/ruby/ruby/blob/trunk/regparse.c#L5751
 }
 
 static int
+quantify_property_node(Node **np, ScanEnv* env, const char* propname, int lower, int upper)
+{
+  int r;
+  r = create_property_node(np, env, propname);
+  if (r != 0) return r; 
+  return quantify_node(np, lower, upper);
+}
+
+static int
 node_extended_grapheme_cluster(Node** np, ScanEnv* env)
 {
   Node* tmp = NULL;
@@ -5849,9 +5858,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5858
     /* these are equivalent, so we leave things as is for the moment */
 
     /* T+ */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=T");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 1, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=T", 1, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = onig_node_new_alt(np1, alt);
@@ -5860,9 +5867,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5867
     np1 = NULL;
 
     /* L+ */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=L");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 1, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=L", 1, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = onig_node_new_alt(np1, alt);
@@ -5871,9 +5876,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5876
     np1 = NULL;
 
     /* L* LVT T* */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=T");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=T", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, NULL_NODE);
@@ -5889,10 +5892,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5892
     list2 = tmp;
     np1 = NULL;
 
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=L");
-    if (r != 0) goto err;
-
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=L", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);
@@ -5906,9 +5906,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5906
     list2 = NULL;
 
     /* L* LV V* T* */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=T");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=T", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, NULL_NODE);
@@ -5916,9 +5914,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5914
     list2 = tmp;
     np1 = NULL;
 
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=V");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=V", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);
@@ -5934,9 +5930,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5930
     list2 = tmp;
     np1 = NULL;
 
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=L");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=L", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);
@@ -5950,9 +5944,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5944
     list2 = NULL;
 
     /* L* V+ T* */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=T");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=T", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, NULL_NODE);
@@ -5960,9 +5952,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5952
     list2 = tmp;
     np1 = NULL;
 
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=V");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 1, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=V", 1, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);
@@ -5970,9 +5960,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5960
     list2 = tmp;
     np1 = NULL;
 
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=L");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=L", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);
@@ -5991,9 +5979,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5979
      *                   (ZWJ (Glue_After_Zwj | EBG Extend* E_Modifier?) )* */
 
     /* ZWJ (Glue_After_Zwj | E_Base_GAZ Extend* E_Modifier?) */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=E_Modifier");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, 1);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=E_Modifier", 0, 1);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, NULL_NODE);
@@ -6001,9 +5987,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L5987
     list2 = tmp;
     np1 = NULL;
 
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=Extend");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=Extend", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);
@@ -6026,9 +6010,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6010
 
     /* Unicode 10.0.0 */
     /* Glue_After_Zwj */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=Extend");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=Extend", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, NULL_NODE);
@@ -6120,9 +6102,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6102
     np1 = NULL;
 
     /* E_Modifier? */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=E_Modifier");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, 1);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=E_Modifier", 0, 1);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);
@@ -6131,9 +6111,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6111
     np1 = NULL;
 
     /* Extend* */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=Extend");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=Extend", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);
@@ -6171,9 +6149,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6149
      * has such examples.
      * http://www.unicode.org/Public/9.0.0/ucd/auxiliary/GraphemeBreakTest.html
      */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=E_Modifier");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, 1);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=E_Modifier", 0, 1);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, NULL_NODE);
@@ -6213,9 +6189,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6189
     /* this is actually Regional_Indicator+ in Unicode 10.0.0,
      * but it is Regional_Indicator{2} in Unicode 11.0.0, so no need to fix */
     /* RI-Sequence := Regional_Indicator{2} */
-    r = create_property_node(&np1, env, "Regional_Indicator");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 2, 2);
+    r = quantify_property_node(&np1, env, "Regional_Indicator", 2, 2);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);
@@ -6234,9 +6208,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6208
     alt = NULL;
 
     /* Prepend* */
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=Prepend");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 0, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=Prepend", 0, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list);
@@ -6274,9 +6246,7 @@ node_extended_grapheme_cluster(Node** np https://github.com/ruby/ruby/blob/trunk/regparse.c#L6246
     list2 = tmp;
     np1 = NULL;
 
-    r = create_property_node(&np1, env, "Grapheme_Cluster_Break=Prepend");
-    if (r != 0) goto err;
-    r = quantify_node(&np1, 1, REPEAT_INFINITE);
+    r = quantify_property_node(&np1, env, "Grapheme_Cluster_Break=Prepend", 1, REPEAT_INFINITE);
     if (r != 0) goto err;
 
     tmp = node_new_list(np1, list2);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]