]> granicus.if.org Git - re2c/commitdiff
Continued adding "--skeleton" switch.
authorUlya Trofimovich <skvadrik@gmail.com>
Sun, 19 Apr 2015 21:05:46 +0000 (22:05 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Sun, 19 Apr 2015 21:05:46 +0000 (22:05 +0100)
Simplified traversal of outgoing arrows when extending prefixes.
Instead of adding outgoing arrow sets (which was erroneous anyway:
they should remain unmodified for another recursion entry), simply
wrap iterator and keep iterating until both ingoing and outgoing
arrows are counted.

re2c/skeleton.cc
re2c/skeleton.h

index dfe053110a76118e6c72794569124bfa7fb4e73e..3ccd960b192ca4985ecb70862abd55c4ea1c01c8 100644 (file)
@@ -196,25 +196,18 @@ void generate (DataFile & o, uint ind, SkeletonState * s, const std::vector<Path
                }
                else
                {
-                       uint out_arrows = 0;
-                       for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i)
-                       {
-                               out_arrows += i->second.size ();
-                       }
-
-                       for (; out_arrows < prefixes.size (); ++out_arrows)
-                       {
-                               s->go.begin ()->second.push_back (s->go.begin ()->second.back ());
-                       }
-
-                       uint k = 0;
-                       const uint prefixes_size = prefixes.size ();
-                       for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i)
+                       const uint in_arrows = prefixes.size ();
+                       const uint out_states = s->go.size ();
+                       SkeletonState::go_t::iterator i = s->go.begin ();
+                       for     ( uint in = 0, out = 0
+                               ; in < in_arrows || out < out_states
+                               ; ++out, s->wrap (++i)
+                               )
                        {
                                std::vector<Path> zs;
-                               for (uint j = 0; j < i->second.size (); ++j, ++k)
+                               for (uint j = 0; j < i->second.size (); ++j, ++in)
                                {
-                                       zs.push_back (prefixes[k % prefixes_size]);
+                                       zs.push_back (prefixes[in % in_arrows]);
                                        update (zs[j], s);
                                        zs[j].chars.push_back (i->second[j]);
                                }
index 29fd23e40326eaf84383d121810f5fcc9107873b..01361e32548874d9835e3d6743dee9a035b8edc1 100644 (file)
@@ -41,6 +41,7 @@ struct SkeletonState
        uint rule;
        uchar visited;
        Path * path;
+
        inline SkeletonState ()
                : go ()
                , rule (~0u)
@@ -51,6 +52,13 @@ struct SkeletonState
        {
                return go.size () == 0;
        }
+       inline void wrap (go_t::iterator & i)
+       {
+               if (i == go.end ())
+               {
+                       i = go.begin ();
+               }
+       }
 };
 
 struct Skeleton