packcr 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/LICENSE +21 -0
 - data/README.md +73 -0
 - data/lib/packcr/context.rb +1 -1
 - data/lib/packcr/generated/context.rb +121 -78
 - data/lib/packcr/generated/node/action_node.rb +2 -2
 - data/lib/packcr/generated/node/alternate_node.rb +2 -2
 - data/lib/packcr/generated/node/capture_node.rb +1 -1
 - data/lib/packcr/generated/node/charclass_node.rb +9 -9
 - data/lib/packcr/generated/node/eof_node.rb +1 -1
 - data/lib/packcr/generated/node/error_node.rb +2 -2
 - data/lib/packcr/generated/node/expand_node.rb +2 -2
 - data/lib/packcr/generated/node/predicate_node.rb +2 -2
 - data/lib/packcr/generated/node/quantity_node.rb +30 -31
 - data/lib/packcr/generated/node/reference_node.rb +2 -2
 - data/lib/packcr/generated/node/rule_node.rb +7 -7
 - data/lib/packcr/generated/node/string_node.rb +4 -4
 - data/lib/packcr/parser.rb +619 -613
 - data/lib/packcr/templates/context/header.c.erb +3 -3
 - data/lib/packcr/templates/context/source.c.erb +417 -403
 - data/lib/packcr/templates/context/source.rb.erb +42 -25
 - data/lib/packcr/templates/node/action.c.erb +2 -2
 - data/lib/packcr/templates/node/alternate.c.erb +2 -2
 - data/lib/packcr/templates/node/capture.c.erb +2 -2
 - data/lib/packcr/templates/node/charclass.c.erb +4 -4
 - data/lib/packcr/templates/node/charclass_any.c.erb +2 -2
 - data/lib/packcr/templates/node/charclass_one.c.erb +4 -4
 - data/lib/packcr/templates/node/charclass_utf8.c.erb +2 -2
 - data/lib/packcr/templates/node/eof.c.erb +1 -1
 - data/lib/packcr/templates/node/error.c.erb +4 -4
 - data/lib/packcr/templates/node/expand.c.erb +2 -2
 - data/lib/packcr/templates/node/predicate.c.erb +1 -1
 - data/lib/packcr/templates/node/predicate_neg.c.erb +1 -1
 - data/lib/packcr/templates/node/quantity_many.c.erb +9 -7
 - data/lib/packcr/templates/node/quantity_one.c.erb +9 -7
 - data/lib/packcr/templates/node/quantity_one.rb.erb +4 -4
 - data/lib/packcr/templates/node/reference.c.erb +6 -6
 - data/lib/packcr/templates/node/rule.c.erb +9 -9
 - data/lib/packcr/templates/node/string_many.c.erb +2 -2
 - data/lib/packcr/templates/node/string_one.c.erb +2 -2
 - data/lib/packcr/util.rb +1 -1
 - data/lib/packcr/version.rb +1 -1
 - metadata +5 -3
 
| 
         @@ -16,14 +16,14 @@ 
     | 
|
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
            #ifndef _MSC_VER
         
     | 
| 
       18 
18 
     | 
    
         
             
            #if defined __GNUC__ && defined _WIN32 /* MinGW */
         
     | 
| 
       19 
     | 
    
         
            -
            #ifndef  
     | 
| 
       20 
     | 
    
         
            -
            #define strnlen(str, maxlen)  
     | 
| 
       21 
     | 
    
         
            -
            static size_t  
     | 
| 
      
 19 
     | 
    
         
            +
            #ifndef PACKCR_USE_SYSTEM_STRNLEN
         
     | 
| 
      
 20 
     | 
    
         
            +
            #define strnlen(str, maxlen) packcr_strnlen(str, maxlen)
         
     | 
| 
      
 21 
     | 
    
         
            +
            static size_t packcr_strnlen(const char *str, size_t maxlen) {
         
     | 
| 
       22 
22 
     | 
    
         
             
                size_t i;
         
     | 
| 
       23 
23 
     | 
    
         
             
                for (i = 0; i < maxlen && str[i]; i++);
         
     | 
| 
       24 
24 
     | 
    
         
             
                return i;
         
     | 
| 
       25 
25 
     | 
    
         
             
            }
         
     | 
| 
       26 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 26 
     | 
    
         
            +
            #endif /* !PACKCR_USE_SYSTEM_STRNLEN */
         
     | 
| 
       27 
27 
     | 
    
         
             
            #endif /* defined __GNUC__ && defined _WIN32 */
         
     | 
| 
       28 
28 
     | 
    
         
             
            #endif /* !_MSC_VER */
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
         @@ -48,221 +48,221 @@ static size_t pcc_strnlen(const char *str, size_t maxlen) { 
     | 
|
| 
       48 
48 
     | 
    
         
             
            #define MARK_FUNC_AS_USED __attribute__((__unused__))
         
     | 
| 
       49 
49 
     | 
    
         
             
            #endif
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
            #ifndef  
     | 
| 
       52 
     | 
    
         
            -
            #define  
     | 
| 
       53 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 51 
     | 
    
         
            +
            #ifndef PACKCR_BUFFER_MIN_SIZE
         
     | 
| 
      
 52 
     | 
    
         
            +
            #define PACKCR_BUFFER_MIN_SIZE 256
         
     | 
| 
      
 53 
     | 
    
         
            +
            #endif /* !PACKCR_BUFFER_MIN_SIZE */
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
            #ifndef  
     | 
| 
       56 
     | 
    
         
            -
            #define  
     | 
| 
       57 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 55 
     | 
    
         
            +
            #ifndef PACKCR_ARRAY_MIN_SIZE
         
     | 
| 
      
 56 
     | 
    
         
            +
            #define PACKCR_ARRAY_MIN_SIZE 2
         
     | 
| 
      
 57 
     | 
    
         
            +
            #endif /* !PACKCR_ARRAY_MIN_SIZE */
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
            #ifndef  
     | 
| 
       60 
     | 
    
         
            -
            #define  
     | 
| 
       61 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 59 
     | 
    
         
            +
            #ifndef PACKCR_POOL_MIN_SIZE
         
     | 
| 
      
 60 
     | 
    
         
            +
            #define PACKCR_POOL_MIN_SIZE 65536
         
     | 
| 
      
 61 
     | 
    
         
            +
            #endif /* !PACKCR_POOL_MIN_SIZE */
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
            #define  
     | 
| 
       64 
     | 
    
         
            -
            #define  
     | 
| 
       65 
     | 
    
         
            -
            #define  
     | 
| 
      
 63 
     | 
    
         
            +
            #define PACKCR_DBG_EVALUATE 0
         
     | 
| 
      
 64 
     | 
    
         
            +
            #define PACKCR_DBG_MATCH    1
         
     | 
| 
      
 65 
     | 
    
         
            +
            #define PACKCR_DBG_NOMATCH  2
         
     | 
| 
       66 
66 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
            #define  
     | 
| 
      
 67 
     | 
    
         
            +
            #define PACKCR_VOID_VALUE (~(size_t)0)
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
            typedef enum  
     | 
| 
       70 
     | 
    
         
            -
                 
     | 
| 
       71 
     | 
    
         
            -
                 
     | 
| 
       72 
     | 
    
         
            -
            }  
     | 
| 
      
 69 
     | 
    
         
            +
            typedef enum packcr_bool_tag {
         
     | 
| 
      
 70 
     | 
    
         
            +
                PACKCR_FALSE = 0,
         
     | 
| 
      
 71 
     | 
    
         
            +
                PACKCR_TRUE
         
     | 
| 
      
 72 
     | 
    
         
            +
            } packcr_bool_t;
         
     | 
| 
       73 
73 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
            typedef struct  
     | 
| 
      
 74 
     | 
    
         
            +
            typedef struct packcr_char_array_tag {
         
     | 
| 
       75 
75 
     | 
    
         
             
                char *buf;
         
     | 
| 
       76 
76 
     | 
    
         
             
                size_t max;
         
     | 
| 
       77 
77 
     | 
    
         
             
                size_t len;
         
     | 
| 
       78 
     | 
    
         
            -
            }  
     | 
| 
      
 78 
     | 
    
         
            +
            } packcr_char_array_t;
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
       80 
     | 
    
         
            -
            typedef struct  
     | 
| 
      
 80 
     | 
    
         
            +
            typedef struct packcr_range_tag {
         
     | 
| 
       81 
81 
     | 
    
         
             
                size_t start;
         
     | 
| 
       82 
82 
     | 
    
         
             
                size_t end;
         
     | 
| 
       83 
83 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       84 
     | 
    
         
            -
                 
     | 
| 
       85 
     | 
    
         
            -
                 
     | 
| 
      
 84 
     | 
    
         
            +
                packcr_location_t start_loc;
         
     | 
| 
      
 85 
     | 
    
         
            +
                packcr_location_t end_loc;
         
     | 
| 
       86 
86 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       87 
     | 
    
         
            -
            }  
     | 
| 
      
 87 
     | 
    
         
            +
            } packcr_range_t;
         
     | 
| 
       88 
88 
     | 
    
         | 
| 
       89 
     | 
    
         
            -
            typedef <%= value_def %> 
     | 
| 
      
 89 
     | 
    
         
            +
            typedef <%= value_def %>packcr_value_t;
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
     | 
    
         
            -
            typedef <%= auxil_def %> 
     | 
| 
      
 91 
     | 
    
         
            +
            typedef <%= auxil_def %>packcr_auxil_t;
         
     | 
| 
       92 
92 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
            <% if prefix != " 
     | 
| 
       94 
     | 
    
         
            -
            typedef <%= prefix%>_context_t  
     | 
| 
      
 93 
     | 
    
         
            +
            <% if prefix != "packcr" -%>
         
     | 
| 
      
 94 
     | 
    
         
            +
            typedef <%= prefix%>_context_t packcr_context_t;
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
       96 
96 
     | 
    
         
             
            <% end -%>
         
     | 
| 
       97 
     | 
    
         
            -
            typedef struct  
     | 
| 
       98 
     | 
    
         
            -
                 
     | 
| 
      
 97 
     | 
    
         
            +
            typedef struct packcr_value_table_tag {
         
     | 
| 
      
 98 
     | 
    
         
            +
                packcr_value_t *buf;
         
     | 
| 
       99 
99 
     | 
    
         
             
                size_t max;
         
     | 
| 
       100 
100 
     | 
    
         
             
                size_t len;
         
     | 
| 
       101 
     | 
    
         
            -
            }  
     | 
| 
      
 101 
     | 
    
         
            +
            } packcr_value_table_t;
         
     | 
| 
       102 
102 
     | 
    
         | 
| 
       103 
     | 
    
         
            -
            typedef struct  
     | 
| 
       104 
     | 
    
         
            -
                 
     | 
| 
      
 103 
     | 
    
         
            +
            typedef struct packcr_value_refer_table_tag {
         
     | 
| 
      
 104 
     | 
    
         
            +
                packcr_value_t **buf;
         
     | 
| 
       105 
105 
     | 
    
         
             
                size_t max;
         
     | 
| 
       106 
106 
     | 
    
         
             
                size_t len;
         
     | 
| 
       107 
     | 
    
         
            -
            }  
     | 
| 
      
 107 
     | 
    
         
            +
            } packcr_value_refer_table_t;
         
     | 
| 
       108 
108 
     | 
    
         | 
| 
       109 
     | 
    
         
            -
            typedef struct  
     | 
| 
       110 
     | 
    
         
            -
                 
     | 
| 
      
 109 
     | 
    
         
            +
            typedef struct packcr_capture_tag {
         
     | 
| 
      
 110 
     | 
    
         
            +
                packcr_range_t range;
         
     | 
| 
       111 
111 
     | 
    
         
             
                char *string; /* mutable */
         
     | 
| 
       112 
     | 
    
         
            -
            }  
     | 
| 
      
 112 
     | 
    
         
            +
            } packcr_capture_t;
         
     | 
| 
       113 
113 
     | 
    
         | 
| 
       114 
     | 
    
         
            -
            typedef struct  
     | 
| 
       115 
     | 
    
         
            -
                 
     | 
| 
      
 114 
     | 
    
         
            +
            typedef struct packcr_capture_table_tag {
         
     | 
| 
      
 115 
     | 
    
         
            +
                packcr_capture_t *buf;
         
     | 
| 
       116 
116 
     | 
    
         
             
                size_t max;
         
     | 
| 
       117 
117 
     | 
    
         
             
                size_t len;
         
     | 
| 
       118 
     | 
    
         
            -
            }  
     | 
| 
      
 118 
     | 
    
         
            +
            } packcr_capture_table_t;
         
     | 
| 
       119 
119 
     | 
    
         | 
| 
       120 
     | 
    
         
            -
            typedef struct  
     | 
| 
       121 
     | 
    
         
            -
                const  
     | 
| 
      
 120 
     | 
    
         
            +
            typedef struct packcr_capture_const_table_tag {
         
     | 
| 
      
 121 
     | 
    
         
            +
                const packcr_capture_t **buf;
         
     | 
| 
       122 
122 
     | 
    
         
             
                size_t max;
         
     | 
| 
       123 
123 
     | 
    
         
             
                size_t len;
         
     | 
| 
       124 
     | 
    
         
            -
            }  
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
            typedef struct  
     | 
| 
       127 
     | 
    
         
            -
            typedef struct  
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
            typedef void (* 
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
            typedef enum  
     | 
| 
       132 
     | 
    
         
            -
                 
     | 
| 
       133 
     | 
    
         
            -
                 
     | 
| 
       134 
     | 
    
         
            -
            }  
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
            typedef struct  
     | 
| 
       137 
     | 
    
         
            -
                 
     | 
| 
       138 
     | 
    
         
            -
                 
     | 
| 
       139 
     | 
    
         
            -
                 
     | 
| 
       140 
     | 
    
         
            -
                 
     | 
| 
       141 
     | 
    
         
            -
            }  
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
            typedef struct  
     | 
| 
       144 
     | 
    
         
            -
                const  
     | 
| 
       145 
     | 
    
         
            -
                 
     | 
| 
       146 
     | 
    
         
            -
            }  
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
            typedef union  
     | 
| 
       149 
     | 
    
         
            -
                 
     | 
| 
       150 
     | 
    
         
            -
                 
     | 
| 
       151 
     | 
    
         
            -
            }  
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
            struct  
     | 
| 
       154 
     | 
    
         
            -
                 
     | 
| 
       155 
     | 
    
         
            -
                 
     | 
| 
      
 124 
     | 
    
         
            +
            } packcr_capture_const_table_t;
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
            typedef struct packcr_thunk_tag packcr_thunk_t;
         
     | 
| 
      
 127 
     | 
    
         
            +
            typedef struct packcr_thunk_array_tag packcr_thunk_array_t;
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
            typedef void (*packcr_action_t)(packcr_context_t *, packcr_thunk_t *, packcr_value_t *);
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
            typedef enum packcr_thunk_type_tag {
         
     | 
| 
      
 132 
     | 
    
         
            +
                PACKCR_THUNK_LEAF,
         
     | 
| 
      
 133 
     | 
    
         
            +
                PACKCR_THUNK_NODE
         
     | 
| 
      
 134 
     | 
    
         
            +
            } packcr_thunk_type_t;
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
            typedef struct packcr_thunk_leaf_tag {
         
     | 
| 
      
 137 
     | 
    
         
            +
                packcr_value_refer_table_t values;
         
     | 
| 
      
 138 
     | 
    
         
            +
                packcr_capture_const_table_t capts;
         
     | 
| 
      
 139 
     | 
    
         
            +
                packcr_capture_t capt0;
         
     | 
| 
      
 140 
     | 
    
         
            +
                packcr_action_t action;
         
     | 
| 
      
 141 
     | 
    
         
            +
            } packcr_thunk_leaf_t;
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
            typedef struct packcr_thunk_node_tag {
         
     | 
| 
      
 144 
     | 
    
         
            +
                const packcr_thunk_array_t *thunks; /* just a reference */
         
     | 
| 
      
 145 
     | 
    
         
            +
                packcr_value_t *value; /* just a reference */
         
     | 
| 
      
 146 
     | 
    
         
            +
            } packcr_thunk_node_t;
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
            typedef union packcr_thunk_data_tag {
         
     | 
| 
      
 149 
     | 
    
         
            +
                packcr_thunk_leaf_t leaf;
         
     | 
| 
      
 150 
     | 
    
         
            +
                packcr_thunk_node_t node;
         
     | 
| 
      
 151 
     | 
    
         
            +
            } packcr_thunk_data_t;
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
            struct packcr_thunk_tag {
         
     | 
| 
      
 154 
     | 
    
         
            +
                packcr_thunk_type_t type;
         
     | 
| 
      
 155 
     | 
    
         
            +
                packcr_thunk_data_t data;
         
     | 
| 
       156 
156 
     | 
    
         
             
            };
         
     | 
| 
       157 
157 
     | 
    
         | 
| 
       158 
     | 
    
         
            -
            struct  
     | 
| 
       159 
     | 
    
         
            -
                 
     | 
| 
      
 158 
     | 
    
         
            +
            struct packcr_thunk_array_tag {
         
     | 
| 
      
 159 
     | 
    
         
            +
                packcr_thunk_t **buf;
         
     | 
| 
       160 
160 
     | 
    
         
             
                size_t max;
         
     | 
| 
       161 
161 
     | 
    
         
             
                size_t len;
         
     | 
| 
       162 
162 
     | 
    
         
             
            };
         
     | 
| 
       163 
163 
     | 
    
         | 
| 
       164 
     | 
    
         
            -
            typedef struct  
     | 
| 
       165 
     | 
    
         
            -
                 
     | 
| 
       166 
     | 
    
         
            -
                 
     | 
| 
       167 
     | 
    
         
            -
                 
     | 
| 
      
 164 
     | 
    
         
            +
            typedef struct packcr_thunk_chunk_tag {
         
     | 
| 
      
 165 
     | 
    
         
            +
                packcr_value_table_t values;
         
     | 
| 
      
 166 
     | 
    
         
            +
                packcr_capture_table_t capts;
         
     | 
| 
      
 167 
     | 
    
         
            +
                packcr_thunk_array_t thunks;
         
     | 
| 
       168 
168 
     | 
    
         
             
                size_t pos; /* the starting position in the character buffer */
         
     | 
| 
       169 
169 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       170 
     | 
    
         
            -
                 
     | 
| 
      
 170 
     | 
    
         
            +
                packcr_location_t pos_loc;
         
     | 
| 
       171 
171 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       172 
     | 
    
         
            -
            }  
     | 
| 
      
 172 
     | 
    
         
            +
            } packcr_thunk_chunk_t;
         
     | 
| 
       173 
173 
     | 
    
         | 
| 
       174 
     | 
    
         
            -
            typedef struct  
     | 
| 
      
 174 
     | 
    
         
            +
            typedef struct packcr_lr_memo_tag packcr_lr_memo_t;
         
     | 
| 
       175 
175 
     | 
    
         | 
| 
       176 
     | 
    
         
            -
            struct  
     | 
| 
      
 176 
     | 
    
         
            +
            struct packcr_lr_memo_tag {
         
     | 
| 
       177 
177 
     | 
    
         
             
                size_t offset;
         
     | 
| 
       178 
178 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       179 
     | 
    
         
            -
                 
     | 
| 
      
 179 
     | 
    
         
            +
                packcr_location_t offset_loc;
         
     | 
| 
       180 
180 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       181 
     | 
    
         
            -
                 
     | 
| 
       182 
     | 
    
         
            -
                 
     | 
| 
       183 
     | 
    
         
            -
                 
     | 
| 
       184 
     | 
    
         
            -
                 
     | 
| 
      
 181 
     | 
    
         
            +
                packcr_lr_memo_t *hold;
         
     | 
| 
      
 182 
     | 
    
         
            +
                packcr_thunk_chunk_t *chunk;
         
     | 
| 
      
 183 
     | 
    
         
            +
                packcr_bool_t fail;
         
     | 
| 
      
 184 
     | 
    
         
            +
                packcr_bool_t grow;
         
     | 
| 
       185 
185 
     | 
    
         
             
            };
         
     | 
| 
       186 
186 
     | 
    
         | 
| 
       187 
     | 
    
         
            -
            typedef struct  
     | 
| 
      
 187 
     | 
    
         
            +
            typedef struct packcr_rule_set_tag packcr_rule_set_t;
         
     | 
| 
       188 
188 
     | 
    
         | 
| 
       189 
     | 
    
         
            -
            typedef  
     | 
| 
      
 189 
     | 
    
         
            +
            typedef packcr_thunk_chunk_t *(*packcr_rule_t)(packcr_context_t *, size_t<% if @location %>, packcr_location_t<% end %>, packcr_rule_set_t*);
         
     | 
| 
       190 
190 
     | 
    
         | 
| 
       191 
     | 
    
         
            -
            typedef struct  
     | 
| 
       192 
     | 
    
         
            -
                 
     | 
| 
      
 191 
     | 
    
         
            +
            typedef struct packcr_rule_set_tag {
         
     | 
| 
      
 192 
     | 
    
         
            +
                packcr_rule_t *buf;
         
     | 
| 
       193 
193 
     | 
    
         
             
                size_t max;
         
     | 
| 
       194 
194 
     | 
    
         
             
                size_t len;
         
     | 
| 
       195 
     | 
    
         
            -
            }  
     | 
| 
      
 195 
     | 
    
         
            +
            } packcr_rule_set_t;
         
     | 
| 
       196 
196 
     | 
    
         | 
| 
       197 
     | 
    
         
            -
            typedef struct  
     | 
| 
       198 
     | 
    
         
            -
                 
     | 
| 
       199 
     | 
    
         
            -
                 
     | 
| 
       200 
     | 
    
         
            -
            }  
     | 
| 
      
 197 
     | 
    
         
            +
            typedef struct packcr_lr_memo_map_entry_tag {
         
     | 
| 
      
 198 
     | 
    
         
            +
                packcr_rule_t rule;
         
     | 
| 
      
 199 
     | 
    
         
            +
                packcr_lr_memo_t *memo;
         
     | 
| 
      
 200 
     | 
    
         
            +
            } packcr_lr_memo_map_entry_t;
         
     | 
| 
       201 
201 
     | 
    
         | 
| 
       202 
     | 
    
         
            -
            typedef struct  
     | 
| 
       203 
     | 
    
         
            -
                 
     | 
| 
      
 202 
     | 
    
         
            +
            typedef struct packcr_lr_memo_map_tag {
         
     | 
| 
      
 203 
     | 
    
         
            +
                packcr_lr_memo_map_entry_t *buf;
         
     | 
| 
       204 
204 
     | 
    
         
             
                size_t max;
         
     | 
| 
       205 
205 
     | 
    
         
             
                size_t len;
         
     | 
| 
       206 
     | 
    
         
            -
            }  
     | 
| 
      
 206 
     | 
    
         
            +
            } packcr_lr_memo_map_t;
         
     | 
| 
       207 
207 
     | 
    
         | 
| 
       208 
     | 
    
         
            -
            typedef struct  
     | 
| 
       209 
     | 
    
         
            -
                 
     | 
| 
      
 208 
     | 
    
         
            +
            typedef struct packcr_lr_table_tag {
         
     | 
| 
      
 209 
     | 
    
         
            +
                packcr_lr_memo_map_t **buf;
         
     | 
| 
       210 
210 
     | 
    
         
             
                size_t max;
         
     | 
| 
       211 
211 
     | 
    
         
             
                size_t len;
         
     | 
| 
       212 
212 
     | 
    
         
             
                size_t ofs;
         
     | 
| 
       213 
     | 
    
         
            -
            }  
     | 
| 
      
 213 
     | 
    
         
            +
            } packcr_lr_table_t;
         
     | 
| 
       214 
214 
     | 
    
         | 
| 
       215 
     | 
    
         
            -
            typedef struct  
     | 
| 
       216 
     | 
    
         
            -
            typedef struct  
     | 
| 
      
 215 
     | 
    
         
            +
            typedef struct packcr_memory_entry_tag packcr_memory_entry_t;
         
     | 
| 
      
 216 
     | 
    
         
            +
            typedef struct packcr_memory_pool_tag packcr_memory_pool_t;
         
     | 
| 
       217 
217 
     | 
    
         | 
| 
       218 
     | 
    
         
            -
            struct  
     | 
| 
       219 
     | 
    
         
            -
                 
     | 
| 
      
 218 
     | 
    
         
            +
            struct packcr_memory_entry_tag {
         
     | 
| 
      
 219 
     | 
    
         
            +
                packcr_memory_entry_t *next;
         
     | 
| 
       220 
220 
     | 
    
         
             
            };
         
     | 
| 
       221 
221 
     | 
    
         | 
| 
       222 
     | 
    
         
            -
            struct  
     | 
| 
       223 
     | 
    
         
            -
                 
     | 
| 
      
 222 
     | 
    
         
            +
            struct packcr_memory_pool_tag {
         
     | 
| 
      
 223 
     | 
    
         
            +
                packcr_memory_pool_t *next;
         
     | 
| 
       224 
224 
     | 
    
         
             
                size_t allocated;
         
     | 
| 
       225 
225 
     | 
    
         
             
                size_t unused;
         
     | 
| 
       226 
226 
     | 
    
         
             
            };
         
     | 
| 
       227 
227 
     | 
    
         | 
| 
       228 
     | 
    
         
            -
            typedef struct  
     | 
| 
       229 
     | 
    
         
            -
                 
     | 
| 
       230 
     | 
    
         
            -
                 
     | 
| 
      
 228 
     | 
    
         
            +
            typedef struct packcr_memory_recycler_tag {
         
     | 
| 
      
 229 
     | 
    
         
            +
                packcr_memory_pool_t *pool_list;
         
     | 
| 
      
 230 
     | 
    
         
            +
                packcr_memory_entry_t *entry_list;
         
     | 
| 
       231 
231 
     | 
    
         
             
                size_t element_size;
         
     | 
| 
       232 
     | 
    
         
            -
            }  
     | 
| 
      
 232 
     | 
    
         
            +
            } packcr_memory_recycler_t;
         
     | 
| 
       233 
233 
     | 
    
         | 
| 
       234 
234 
     | 
    
         
             
            struct <%= prefix %>_context_tag {
         
     | 
| 
       235 
235 
     | 
    
         
             
                size_t buffer_start_position; /* the position in the input of the first character currently buffered */
         
     | 
| 
       236 
236 
     | 
    
         
             
                size_t position_offset; /* the current parsing position in the character buffer */
         
     | 
| 
       237 
237 
     | 
    
         
             
                <%- if @location -%>
         
     | 
| 
       238 
     | 
    
         
            -
                 
     | 
| 
       239 
     | 
    
         
            -
                 
     | 
| 
      
 238 
     | 
    
         
            +
                packcr_location_t buffer_start_position_loc;
         
     | 
| 
      
 239 
     | 
    
         
            +
                packcr_location_t position_offset_loc;
         
     | 
| 
       240 
240 
     | 
    
         
             
                <%- end -%>
         
     | 
| 
       241 
241 
     | 
    
         
             
                size_t level;
         
     | 
| 
       242 
     | 
    
         
            -
                 
     | 
| 
       243 
     | 
    
         
            -
                 
     | 
| 
       244 
     | 
    
         
            -
                 
     | 
| 
       245 
     | 
    
         
            -
                 
     | 
| 
       246 
     | 
    
         
            -
                 
     | 
| 
       247 
     | 
    
         
            -
                 
     | 
| 
      
 242 
     | 
    
         
            +
                packcr_char_array_t buffer;
         
     | 
| 
      
 243 
     | 
    
         
            +
                packcr_lr_table_t lrtable;
         
     | 
| 
      
 244 
     | 
    
         
            +
                packcr_thunk_array_t thunks;
         
     | 
| 
      
 245 
     | 
    
         
            +
                packcr_auxil_t auxil;
         
     | 
| 
      
 246 
     | 
    
         
            +
                packcr_memory_recycler_t thunk_chunk_recycler;
         
     | 
| 
      
 247 
     | 
    
         
            +
                packcr_memory_recycler_t lr_memo_recycler;
         
     | 
| 
       248 
248 
     | 
    
         
             
            };
         
     | 
| 
       249 
249 
     | 
    
         | 
| 
       250 
     | 
    
         
            -
            #ifndef  
     | 
| 
       251 
     | 
    
         
            -
            #define  
     | 
| 
      
 250 
     | 
    
         
            +
            #ifndef PACKCR_ERROR
         
     | 
| 
      
 251 
     | 
    
         
            +
            #define PACKCR_ERROR(auxil) packcr_error()
         
     | 
| 
       252 
252 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       253 
     | 
    
         
            -
            static void  
     | 
| 
      
 253 
     | 
    
         
            +
            static void packcr_error(void) {
         
     | 
| 
       254 
254 
     | 
    
         
             
                fprintf(stderr, "Syntax error\n");
         
     | 
| 
       255 
255 
     | 
    
         
             
                exit(1);
         
     | 
| 
       256 
256 
     | 
    
         
             
            }
         
     | 
| 
       257 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 257 
     | 
    
         
            +
            #endif /* !PACKCR_ERROR */
         
     | 
| 
       258 
258 
     | 
    
         | 
| 
       259 
     | 
    
         
            -
            #ifndef  
     | 
| 
       260 
     | 
    
         
            -
            #define  
     | 
| 
       261 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 259 
     | 
    
         
            +
            #ifndef PACKCR_GETCHAR
         
     | 
| 
      
 260 
     | 
    
         
            +
            #define PACKCR_GETCHAR(auxil) getchar()
         
     | 
| 
      
 261 
     | 
    
         
            +
            #endif /* !PACKCR_GETCHAR */
         
     | 
| 
       262 
262 
     | 
    
         | 
| 
       263 
     | 
    
         
            -
            #ifndef  
     | 
| 
       264 
     | 
    
         
            -
            #define  
     | 
| 
       265 
     | 
    
         
            -
            static void * 
     | 
| 
      
 263 
     | 
    
         
            +
            #ifndef PACKCR_MALLOC
         
     | 
| 
      
 264 
     | 
    
         
            +
            #define PACKCR_MALLOC(auxil, size) packcr_malloc_e(size)
         
     | 
| 
      
 265 
     | 
    
         
            +
            static void *packcr_malloc_e(size_t size) {
         
     | 
| 
       266 
266 
     | 
    
         
             
                void *const p = malloc(size);
         
     | 
| 
       267 
267 
     | 
    
         
             
                if (p == NULL) {
         
     | 
| 
       268 
268 
     | 
    
         
             
                    fprintf(stderr, "Out of memory\n");
         
     | 
| 
         @@ -270,11 +270,11 @@ static void *pcc_malloc_e(size_t size) { 
     | 
|
| 
       270 
270 
     | 
    
         
             
                }
         
     | 
| 
       271 
271 
     | 
    
         
             
                return p;
         
     | 
| 
       272 
272 
     | 
    
         
             
            }
         
     | 
| 
       273 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 273 
     | 
    
         
            +
            #endif /* !PACKCR_MALLOC */
         
     | 
| 
       274 
274 
     | 
    
         | 
| 
       275 
     | 
    
         
            -
            #ifndef  
     | 
| 
       276 
     | 
    
         
            -
            #define  
     | 
| 
       277 
     | 
    
         
            -
            static void * 
     | 
| 
      
 275 
     | 
    
         
            +
            #ifndef PACKCR_REALLOC
         
     | 
| 
      
 276 
     | 
    
         
            +
            #define PACKCR_REALLOC(auxil, ptr, size) packcr_realloc_e(ptr, size)
         
     | 
| 
      
 277 
     | 
    
         
            +
            static void *packcr_realloc_e(void *ptr, size_t size) {
         
     | 
| 
       278 
278 
     | 
    
         
             
                void *const p = realloc(ptr, size);
         
     | 
| 
       279 
279 
     | 
    
         
             
                if (p == NULL) {
         
     | 
| 
       280 
280 
     | 
    
         
             
                    fprintf(stderr, "Out of memory\n");
         
     | 
| 
         @@ -282,259 +282,259 @@ static void *pcc_realloc_e(void *ptr, size_t size) { 
     | 
|
| 
       282 
282 
     | 
    
         
             
                }
         
     | 
| 
       283 
283 
     | 
    
         
             
                return p;
         
     | 
| 
       284 
284 
     | 
    
         
             
            }
         
     | 
| 
       285 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 285 
     | 
    
         
            +
            #endif /* !PACKCR_REALLOC */
         
     | 
| 
       286 
286 
     | 
    
         | 
| 
       287 
     | 
    
         
            -
            #ifndef  
     | 
| 
       288 
     | 
    
         
            -
            #define  
     | 
| 
       289 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 287 
     | 
    
         
            +
            #ifndef PACKCR_FREE
         
     | 
| 
      
 288 
     | 
    
         
            +
            #define PACKCR_FREE(auxil, ptr) free(ptr)
         
     | 
| 
      
 289 
     | 
    
         
            +
            #endif /* !PACKCR_FREE */
         
     | 
| 
       290 
290 
     | 
    
         | 
| 
       291 
     | 
    
         
            -
            #ifndef  
     | 
| 
       292 
     | 
    
         
            -
            #define  
     | 
| 
       293 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 291 
     | 
    
         
            +
            #ifndef PACKCR_DEBUG
         
     | 
| 
      
 292 
     | 
    
         
            +
            #define PACKCR_DEBUG(auxil, event, rule, level, pos, buffer, length) ((void)0)
         
     | 
| 
      
 293 
     | 
    
         
            +
            #endif /* !PACKCR_DEBUG */
         
     | 
| 
       294 
294 
     | 
    
         | 
| 
       295 
     | 
    
         
            -
            static char * 
     | 
| 
      
 295 
     | 
    
         
            +
            static char *packcr_strndup_e(packcr_auxil_t auxil, const char *str, size_t len) {
         
     | 
| 
       296 
296 
     | 
    
         
             
                const size_t m = strnlen(str, len);
         
     | 
| 
       297 
     | 
    
         
            -
                char *const s = (char *) 
     | 
| 
      
 297 
     | 
    
         
            +
                char *const s = (char *)PACKCR_MALLOC(auxil, m + 1);
         
     | 
| 
       298 
298 
     | 
    
         
             
                memcpy(s, str, m);
         
     | 
| 
       299 
299 
     | 
    
         
             
                s[m] = '\0';
         
     | 
| 
       300 
300 
     | 
    
         
             
                return s;
         
     | 
| 
       301 
301 
     | 
    
         
             
            }
         
     | 
| 
       302 
302 
     | 
    
         | 
| 
       303 
     | 
    
         
            -
            static void  
     | 
| 
      
 303 
     | 
    
         
            +
            static void packcr_char_array__init(packcr_auxil_t auxil, packcr_char_array_t *array) {
         
     | 
| 
       304 
304 
     | 
    
         
             
                array->len = 0;
         
     | 
| 
       305 
305 
     | 
    
         
             
                array->max = 0;
         
     | 
| 
       306 
306 
     | 
    
         
             
                array->buf = NULL;
         
     | 
| 
       307 
307 
     | 
    
         
             
            }
         
     | 
| 
       308 
308 
     | 
    
         | 
| 
       309 
     | 
    
         
            -
            static void  
     | 
| 
      
 309 
     | 
    
         
            +
            static void packcr_char_array__add(packcr_auxil_t auxil, packcr_char_array_t *array, char ch) {
         
     | 
| 
       310 
310 
     | 
    
         
             
                if (array->max <= array->len) {
         
     | 
| 
       311 
311 
     | 
    
         
             
                    const size_t n = array->len + 1;
         
     | 
| 
       312 
312 
     | 
    
         
             
                    size_t m = array->max;
         
     | 
| 
       313 
     | 
    
         
            -
                    if (m == 0) m =  
     | 
| 
      
 313 
     | 
    
         
            +
                    if (m == 0) m = PACKCR_BUFFER_MIN_SIZE;
         
     | 
| 
       314 
314 
     | 
    
         
             
                    while (m < n && m != 0) m <<= 1;
         
     | 
| 
       315 
315 
     | 
    
         
             
                    if (m == 0) m = n;
         
     | 
| 
       316 
     | 
    
         
            -
                    array->buf = (char *) 
     | 
| 
      
 316 
     | 
    
         
            +
                    array->buf = (char *)PACKCR_REALLOC(auxil, array->buf, m);
         
     | 
| 
       317 
317 
     | 
    
         
             
                    array->max = m;
         
     | 
| 
       318 
318 
     | 
    
         
             
                }
         
     | 
| 
       319 
319 
     | 
    
         
             
                array->buf[array->len++] = ch;
         
     | 
| 
       320 
320 
     | 
    
         
             
            }
         
     | 
| 
       321 
321 
     | 
    
         | 
| 
       322 
     | 
    
         
            -
            static void  
     | 
| 
       323 
     | 
    
         
            -
                 
     | 
| 
      
 322 
     | 
    
         
            +
            static void packcr_char_array__term(packcr_auxil_t auxil, packcr_char_array_t *array) {
         
     | 
| 
      
 323 
     | 
    
         
            +
                PACKCR_FREE(auxil, array->buf);
         
     | 
| 
       324 
324 
     | 
    
         
             
            }
         
     | 
| 
       325 
325 
     | 
    
         | 
| 
       326 
     | 
    
         
            -
            static void  
     | 
| 
      
 326 
     | 
    
         
            +
            static void packcr_value_table__init(packcr_auxil_t auxil, packcr_value_table_t *table) {
         
     | 
| 
       327 
327 
     | 
    
         
             
                table->len = 0;
         
     | 
| 
       328 
328 
     | 
    
         
             
                table->max = 0;
         
     | 
| 
       329 
329 
     | 
    
         
             
                table->buf = NULL;
         
     | 
| 
       330 
330 
     | 
    
         
             
            }
         
     | 
| 
       331 
331 
     | 
    
         | 
| 
       332 
332 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       333 
     | 
    
         
            -
            static void  
     | 
| 
      
 333 
     | 
    
         
            +
            static void packcr_value_table__resize(packcr_auxil_t auxil, packcr_value_table_t *table, size_t len) {
         
     | 
| 
       334 
334 
     | 
    
         
             
                if (table->max < len) {
         
     | 
| 
       335 
335 
     | 
    
         
             
                    size_t m = table->max;
         
     | 
| 
       336 
     | 
    
         
            -
                    if (m == 0) m =  
     | 
| 
      
 336 
     | 
    
         
            +
                    if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
         
     | 
| 
       337 
337 
     | 
    
         
             
                    while (m < len && m != 0) m <<= 1;
         
     | 
| 
       338 
338 
     | 
    
         
             
                    if (m == 0) m = len;
         
     | 
| 
       339 
     | 
    
         
            -
                    table->buf = ( 
     | 
| 
      
 339 
     | 
    
         
            +
                    table->buf = (packcr_value_t *)PACKCR_REALLOC(auxil, table->buf, sizeof(packcr_value_t) * m);
         
     | 
| 
       340 
340 
     | 
    
         
             
                    table->max = m;
         
     | 
| 
       341 
341 
     | 
    
         
             
                }
         
     | 
| 
       342 
342 
     | 
    
         
             
                table->len = len;
         
     | 
| 
       343 
343 
     | 
    
         
             
            }
         
     | 
| 
       344 
344 
     | 
    
         | 
| 
       345 
345 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       346 
     | 
    
         
            -
            static void  
     | 
| 
       347 
     | 
    
         
            -
                memset(table->buf, 0, sizeof( 
     | 
| 
      
 346 
     | 
    
         
            +
            static void packcr_value_table__clear(packcr_auxil_t auxil, packcr_value_table_t *table) {
         
     | 
| 
      
 347 
     | 
    
         
            +
                memset(table->buf, 0, sizeof(packcr_value_t) * table->len);
         
     | 
| 
       348 
348 
     | 
    
         
             
            }
         
     | 
| 
       349 
349 
     | 
    
         | 
| 
       350 
     | 
    
         
            -
            static void  
     | 
| 
       351 
     | 
    
         
            -
                 
     | 
| 
      
 350 
     | 
    
         
            +
            static void packcr_value_table__term(packcr_auxil_t auxil, packcr_value_table_t *table) {
         
     | 
| 
      
 351 
     | 
    
         
            +
                PACKCR_FREE(auxil, table->buf);
         
     | 
| 
       352 
352 
     | 
    
         
             
            }
         
     | 
| 
       353 
353 
     | 
    
         | 
| 
       354 
     | 
    
         
            -
            static void  
     | 
| 
      
 354 
     | 
    
         
            +
            static void packcr_value_refer_table__init(packcr_auxil_t auxil, packcr_value_refer_table_t *table) {
         
     | 
| 
       355 
355 
     | 
    
         
             
                table->len = 0;
         
     | 
| 
       356 
356 
     | 
    
         
             
                table->max = 0;
         
     | 
| 
       357 
357 
     | 
    
         
             
                table->buf = NULL;
         
     | 
| 
       358 
358 
     | 
    
         
             
            }
         
     | 
| 
       359 
359 
     | 
    
         | 
| 
       360 
     | 
    
         
            -
            static void  
     | 
| 
      
 360 
     | 
    
         
            +
            static void packcr_value_refer_table__resize(packcr_auxil_t auxil, packcr_value_refer_table_t *table, size_t len) {
         
     | 
| 
       361 
361 
     | 
    
         
             
                size_t i;
         
     | 
| 
       362 
362 
     | 
    
         
             
                if (table->max < len) {
         
     | 
| 
       363 
363 
     | 
    
         
             
                    size_t m = table->max;
         
     | 
| 
       364 
     | 
    
         
            -
                    if (m == 0) m =  
     | 
| 
      
 364 
     | 
    
         
            +
                    if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
         
     | 
| 
       365 
365 
     | 
    
         
             
                    while (m < len && m != 0) m <<= 1;
         
     | 
| 
       366 
366 
     | 
    
         
             
                    if (m == 0) m = len;
         
     | 
| 
       367 
     | 
    
         
            -
                    table->buf = ( 
     | 
| 
      
 367 
     | 
    
         
            +
                    table->buf = (packcr_value_t **)PACKCR_REALLOC(auxil, table->buf, sizeof(packcr_value_t *) * m);
         
     | 
| 
       368 
368 
     | 
    
         
             
                    table->max = m;
         
     | 
| 
       369 
369 
     | 
    
         
             
                }
         
     | 
| 
       370 
370 
     | 
    
         
             
                for (i = table->len; i < len; i++) table->buf[i] = NULL;
         
     | 
| 
       371 
371 
     | 
    
         
             
                table->len = len;
         
     | 
| 
       372 
372 
     | 
    
         
             
            }
         
     | 
| 
       373 
373 
     | 
    
         | 
| 
       374 
     | 
    
         
            -
            static void  
     | 
| 
       375 
     | 
    
         
            -
                 
     | 
| 
      
 374 
     | 
    
         
            +
            static void packcr_value_refer_table__term(packcr_auxil_t auxil, packcr_value_refer_table_t *table) {
         
     | 
| 
      
 375 
     | 
    
         
            +
                PACKCR_FREE(auxil, table->buf);
         
     | 
| 
       376 
376 
     | 
    
         
             
            }
         
     | 
| 
       377 
377 
     | 
    
         | 
| 
       378 
     | 
    
         
            -
            static void  
     | 
| 
      
 378 
     | 
    
         
            +
            static void packcr_capture_table__init(packcr_auxil_t auxil, packcr_capture_table_t *table) {
         
     | 
| 
       379 
379 
     | 
    
         
             
                table->len = 0;
         
     | 
| 
       380 
380 
     | 
    
         
             
                table->max = 0;
         
     | 
| 
       381 
381 
     | 
    
         
             
                table->buf = NULL;
         
     | 
| 
       382 
382 
     | 
    
         
             
            }
         
     | 
| 
       383 
383 
     | 
    
         | 
| 
       384 
384 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       385 
     | 
    
         
            -
            static void  
     | 
| 
      
 385 
     | 
    
         
            +
            static void packcr_capture_table__resize(packcr_auxil_t auxil, packcr_capture_table_t *table, size_t len) {
         
     | 
| 
       386 
386 
     | 
    
         
             
                size_t i;
         
     | 
| 
       387 
     | 
    
         
            -
                for (i = len; i < table->len; i++)  
     | 
| 
      
 387 
     | 
    
         
            +
                for (i = len; i < table->len; i++) PACKCR_FREE(auxil, table->buf[i].string);
         
     | 
| 
       388 
388 
     | 
    
         
             
                if (table->max < len) {
         
     | 
| 
       389 
389 
     | 
    
         
             
                    size_t m = table->max;
         
     | 
| 
       390 
     | 
    
         
            -
                    if (m == 0) m =  
     | 
| 
      
 390 
     | 
    
         
            +
                    if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
         
     | 
| 
       391 
391 
     | 
    
         
             
                    while (m < len && m != 0) m <<= 1;
         
     | 
| 
       392 
392 
     | 
    
         
             
                    if (m == 0) m = len;
         
     | 
| 
       393 
     | 
    
         
            -
                    table->buf = ( 
     | 
| 
      
 393 
     | 
    
         
            +
                    table->buf = (packcr_capture_t *)PACKCR_REALLOC(auxil, table->buf, sizeof(packcr_capture_t) * m);
         
     | 
| 
       394 
394 
     | 
    
         
             
                    table->max = m;
         
     | 
| 
       395 
395 
     | 
    
         
             
                }
         
     | 
| 
       396 
396 
     | 
    
         
             
                for (i = table->len; i < len; i++) {
         
     | 
| 
       397 
397 
     | 
    
         
             
                    table->buf[i].range.start = 0;
         
     | 
| 
       398 
398 
     | 
    
         
             
                    table->buf[i].range.end = 0;
         
     | 
| 
       399 
399 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       400 
     | 
    
         
            -
                     
     | 
| 
       401 
     | 
    
         
            -
                     
     | 
| 
      
 400 
     | 
    
         
            +
                    packcr_location_init(&table->buf[i].range.start_loc);
         
     | 
| 
      
 401 
     | 
    
         
            +
                    packcr_location_init(&table->buf[i].range.end_loc);
         
     | 
| 
       402 
402 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       403 
403 
     | 
    
         
             
                    table->buf[i].string = NULL;
         
     | 
| 
       404 
404 
     | 
    
         
             
                }
         
     | 
| 
       405 
405 
     | 
    
         
             
                table->len = len;
         
     | 
| 
       406 
406 
     | 
    
         
             
            }
         
     | 
| 
       407 
407 
     | 
    
         | 
| 
       408 
     | 
    
         
            -
            static void  
     | 
| 
      
 408 
     | 
    
         
            +
            static void packcr_capture_table__term(packcr_auxil_t auxil, packcr_capture_table_t *table) {
         
     | 
| 
       409 
409 
     | 
    
         
             
                while (table->len > 0) {
         
     | 
| 
       410 
410 
     | 
    
         
             
                    table->len--;
         
     | 
| 
       411 
     | 
    
         
            -
                     
     | 
| 
      
 411 
     | 
    
         
            +
                    PACKCR_FREE(auxil, table->buf[table->len].string);
         
     | 
| 
       412 
412 
     | 
    
         
             
                }
         
     | 
| 
       413 
     | 
    
         
            -
                 
     | 
| 
      
 413 
     | 
    
         
            +
                PACKCR_FREE(auxil, table->buf);
         
     | 
| 
       414 
414 
     | 
    
         
             
            }
         
     | 
| 
       415 
415 
     | 
    
         | 
| 
       416 
     | 
    
         
            -
            static void  
     | 
| 
      
 416 
     | 
    
         
            +
            static void packcr_capture_const_table__init(packcr_auxil_t auxil, packcr_capture_const_table_t *table) {
         
     | 
| 
       417 
417 
     | 
    
         
             
                table->len = 0;
         
     | 
| 
       418 
418 
     | 
    
         
             
                table->max = 0;
         
     | 
| 
       419 
419 
     | 
    
         
             
                table->buf = NULL;
         
     | 
| 
       420 
420 
     | 
    
         
             
            }
         
     | 
| 
       421 
421 
     | 
    
         | 
| 
       422 
     | 
    
         
            -
            static void  
     | 
| 
      
 422 
     | 
    
         
            +
            static void packcr_capture_const_table__resize(packcr_auxil_t auxil, packcr_capture_const_table_t *table, size_t len) {
         
     | 
| 
       423 
423 
     | 
    
         
             
                size_t i;
         
     | 
| 
       424 
424 
     | 
    
         
             
                if (table->max < len) {
         
     | 
| 
       425 
425 
     | 
    
         
             
                    size_t m = table->max;
         
     | 
| 
       426 
     | 
    
         
            -
                    if (m == 0) m =  
     | 
| 
      
 426 
     | 
    
         
            +
                    if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
         
     | 
| 
       427 
427 
     | 
    
         
             
                    while (m < len && m != 0) m <<= 1;
         
     | 
| 
       428 
428 
     | 
    
         
             
                    if (m == 0) m = len;
         
     | 
| 
       429 
     | 
    
         
            -
                    table->buf = (const  
     | 
| 
      
 429 
     | 
    
         
            +
                    table->buf = (const packcr_capture_t **)PACKCR_REALLOC(auxil, (packcr_capture_t **)table->buf, sizeof(const packcr_capture_t *) * m);
         
     | 
| 
       430 
430 
     | 
    
         
             
                    table->max = m;
         
     | 
| 
       431 
431 
     | 
    
         
             
                }
         
     | 
| 
       432 
432 
     | 
    
         
             
                for (i = table->len; i < len; i++) table->buf[i] = NULL;
         
     | 
| 
       433 
433 
     | 
    
         
             
                table->len = len;
         
     | 
| 
       434 
434 
     | 
    
         
             
            }
         
     | 
| 
       435 
435 
     | 
    
         | 
| 
       436 
     | 
    
         
            -
            static void  
     | 
| 
       437 
     | 
    
         
            -
                 
     | 
| 
      
 436 
     | 
    
         
            +
            static void packcr_capture_const_table__term(packcr_auxil_t auxil, packcr_capture_const_table_t *table) {
         
     | 
| 
      
 437 
     | 
    
         
            +
                PACKCR_FREE(auxil, (void *)table->buf);
         
     | 
| 
       438 
438 
     | 
    
         
             
            }
         
     | 
| 
       439 
439 
     | 
    
         | 
| 
       440 
440 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       441 
     | 
    
         
            -
            static  
     | 
| 
       442 
     | 
    
         
            -
                 
     | 
| 
       443 
     | 
    
         
            -
                thunk->type =  
     | 
| 
       444 
     | 
    
         
            -
                 
     | 
| 
       445 
     | 
    
         
            -
                 
     | 
| 
       446 
     | 
    
         
            -
                 
     | 
| 
       447 
     | 
    
         
            -
                 
     | 
| 
      
 441 
     | 
    
         
            +
            static packcr_thunk_t *packcr_thunk__create_leaf(packcr_auxil_t auxil, packcr_action_t action, size_t valuec, size_t captc) {
         
     | 
| 
      
 442 
     | 
    
         
            +
                packcr_thunk_t *const thunk = (packcr_thunk_t *)PACKCR_MALLOC(auxil, sizeof(packcr_thunk_t));
         
     | 
| 
      
 443 
     | 
    
         
            +
                thunk->type = PACKCR_THUNK_LEAF;
         
     | 
| 
      
 444 
     | 
    
         
            +
                packcr_value_refer_table__init(auxil, &thunk->data.leaf.values);
         
     | 
| 
      
 445 
     | 
    
         
            +
                packcr_value_refer_table__resize(auxil, &thunk->data.leaf.values, valuec);
         
     | 
| 
      
 446 
     | 
    
         
            +
                packcr_capture_const_table__init(auxil, &thunk->data.leaf.capts);
         
     | 
| 
      
 447 
     | 
    
         
            +
                packcr_capture_const_table__resize(auxil, &thunk->data.leaf.capts, captc);
         
     | 
| 
       448 
448 
     | 
    
         
             
                thunk->data.leaf.capt0.range.start = 0;
         
     | 
| 
       449 
449 
     | 
    
         
             
                thunk->data.leaf.capt0.range.end = 0;
         
     | 
| 
       450 
450 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       451 
     | 
    
         
            -
                 
     | 
| 
       452 
     | 
    
         
            -
                 
     | 
| 
      
 451 
     | 
    
         
            +
                packcr_location_init(&thunk->data.leaf.capt0.range.start_loc);
         
     | 
| 
      
 452 
     | 
    
         
            +
                packcr_location_init(&thunk->data.leaf.capt0.range.end_loc);
         
     | 
| 
       453 
453 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       454 
454 
     | 
    
         
             
                thunk->data.leaf.capt0.string = NULL;
         
     | 
| 
       455 
455 
     | 
    
         
             
                thunk->data.leaf.action = action;
         
     | 
| 
       456 
456 
     | 
    
         
             
                return thunk;
         
     | 
| 
       457 
457 
     | 
    
         
             
            }
         
     | 
| 
       458 
458 
     | 
    
         | 
| 
       459 
     | 
    
         
            -
            static  
     | 
| 
       460 
     | 
    
         
            -
                 
     | 
| 
       461 
     | 
    
         
            -
                thunk->type =  
     | 
| 
      
 459 
     | 
    
         
            +
            static packcr_thunk_t *packcr_thunk__create_node(packcr_auxil_t auxil, const packcr_thunk_array_t *thunks, packcr_value_t *value) {
         
     | 
| 
      
 460 
     | 
    
         
            +
                packcr_thunk_t *const thunk = (packcr_thunk_t *)PACKCR_MALLOC(auxil, sizeof(packcr_thunk_t));
         
     | 
| 
      
 461 
     | 
    
         
            +
                thunk->type = PACKCR_THUNK_NODE;
         
     | 
| 
       462 
462 
     | 
    
         
             
                thunk->data.node.thunks = thunks;
         
     | 
| 
       463 
463 
     | 
    
         
             
                thunk->data.node.value = value;
         
     | 
| 
       464 
464 
     | 
    
         
             
                return thunk;
         
     | 
| 
       465 
465 
     | 
    
         
             
            }
         
     | 
| 
       466 
466 
     | 
    
         | 
| 
       467 
     | 
    
         
            -
            static void  
     | 
| 
      
 467 
     | 
    
         
            +
            static void packcr_thunk__destroy(packcr_auxil_t auxil, packcr_thunk_t *thunk) {
         
     | 
| 
       468 
468 
     | 
    
         
             
                if (thunk == NULL) return;
         
     | 
| 
       469 
469 
     | 
    
         
             
                switch (thunk->type) {
         
     | 
| 
       470 
     | 
    
         
            -
                case  
     | 
| 
       471 
     | 
    
         
            -
                     
     | 
| 
       472 
     | 
    
         
            -
                     
     | 
| 
       473 
     | 
    
         
            -
                     
     | 
| 
      
 470 
     | 
    
         
            +
                case PACKCR_THUNK_LEAF:
         
     | 
| 
      
 471 
     | 
    
         
            +
                    PACKCR_FREE(auxil, thunk->data.leaf.capt0.string);
         
     | 
| 
      
 472 
     | 
    
         
            +
                    packcr_capture_const_table__term(auxil, &thunk->data.leaf.capts);
         
     | 
| 
      
 473 
     | 
    
         
            +
                    packcr_value_refer_table__term(auxil, &thunk->data.leaf.values);
         
     | 
| 
       474 
474 
     | 
    
         
             
                    break;
         
     | 
| 
       475 
     | 
    
         
            -
                case  
     | 
| 
      
 475 
     | 
    
         
            +
                case PACKCR_THUNK_NODE:
         
     | 
| 
       476 
476 
     | 
    
         
             
                    break;
         
     | 
| 
       477 
477 
     | 
    
         
             
                default: /* unknown */
         
     | 
| 
       478 
478 
     | 
    
         
             
                    break;
         
     | 
| 
       479 
479 
     | 
    
         
             
                }
         
     | 
| 
       480 
     | 
    
         
            -
                 
     | 
| 
      
 480 
     | 
    
         
            +
                PACKCR_FREE(auxil, thunk);
         
     | 
| 
       481 
481 
     | 
    
         
             
            }
         
     | 
| 
       482 
482 
     | 
    
         | 
| 
       483 
     | 
    
         
            -
            static void  
     | 
| 
      
 483 
     | 
    
         
            +
            static void packcr_thunk_array__init(packcr_auxil_t auxil, packcr_thunk_array_t *array) {
         
     | 
| 
       484 
484 
     | 
    
         
             
                array->len = 0;
         
     | 
| 
       485 
485 
     | 
    
         
             
                array->max = 0;
         
     | 
| 
       486 
486 
     | 
    
         
             
                array->buf = NULL;
         
     | 
| 
       487 
487 
     | 
    
         
             
            }
         
     | 
| 
       488 
488 
     | 
    
         | 
| 
       489 
     | 
    
         
            -
            static void  
     | 
| 
      
 489 
     | 
    
         
            +
            static void packcr_thunk_array__add(packcr_auxil_t auxil, packcr_thunk_array_t *array, packcr_thunk_t *thunk) {
         
     | 
| 
       490 
490 
     | 
    
         
             
                if (array->max <= array->len) {
         
     | 
| 
       491 
491 
     | 
    
         
             
                    const size_t n = array->len + 1;
         
     | 
| 
       492 
492 
     | 
    
         
             
                    size_t m = array->max;
         
     | 
| 
       493 
     | 
    
         
            -
                    if (m == 0) m =  
     | 
| 
      
 493 
     | 
    
         
            +
                    if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
         
     | 
| 
       494 
494 
     | 
    
         
             
                    while (m < n && m != 0) m <<= 1;
         
     | 
| 
       495 
495 
     | 
    
         
             
                    if (m == 0) m = n;
         
     | 
| 
       496 
     | 
    
         
            -
                    array->buf = ( 
     | 
| 
      
 496 
     | 
    
         
            +
                    array->buf = (packcr_thunk_t **)PACKCR_REALLOC(auxil, array->buf, sizeof(packcr_thunk_t *) * m);
         
     | 
| 
       497 
497 
     | 
    
         
             
                    array->max = m;
         
     | 
| 
       498 
498 
     | 
    
         
             
                }
         
     | 
| 
       499 
499 
     | 
    
         
             
                array->buf[array->len++] = thunk;
         
     | 
| 
       500 
500 
     | 
    
         
             
            }
         
     | 
| 
       501 
501 
     | 
    
         | 
| 
       502 
     | 
    
         
            -
            static void  
     | 
| 
      
 502 
     | 
    
         
            +
            static void packcr_thunk_array__revert(packcr_auxil_t auxil, packcr_thunk_array_t *array, size_t len) {
         
     | 
| 
       503 
503 
     | 
    
         
             
                while (array->len > len) {
         
     | 
| 
       504 
504 
     | 
    
         
             
                    array->len--;
         
     | 
| 
       505 
     | 
    
         
            -
                     
     | 
| 
      
 505 
     | 
    
         
            +
                    packcr_thunk__destroy(auxil, array->buf[array->len]);
         
     | 
| 
       506 
506 
     | 
    
         
             
                }
         
     | 
| 
       507 
507 
     | 
    
         
             
            }
         
     | 
| 
       508 
508 
     | 
    
         | 
| 
       509 
     | 
    
         
            -
            static void  
     | 
| 
      
 509 
     | 
    
         
            +
            static void packcr_thunk_array__term(packcr_auxil_t auxil, packcr_thunk_array_t *array) {
         
     | 
| 
       510 
510 
     | 
    
         
             
                while (array->len > 0) {
         
     | 
| 
       511 
511 
     | 
    
         
             
                    array->len--;
         
     | 
| 
       512 
     | 
    
         
            -
                     
     | 
| 
      
 512 
     | 
    
         
            +
                    packcr_thunk__destroy(auxil, array->buf[array->len]);
         
     | 
| 
       513 
513 
     | 
    
         
             
                }
         
     | 
| 
       514 
     | 
    
         
            -
                 
     | 
| 
      
 514 
     | 
    
         
            +
                PACKCR_FREE(auxil, array->buf);
         
     | 
| 
       515 
515 
     | 
    
         
             
            }
         
     | 
| 
       516 
516 
     | 
    
         | 
| 
       517 
     | 
    
         
            -
            static void  
     | 
| 
      
 517 
     | 
    
         
            +
            static void packcr_memory_recycler__init(packcr_auxil_t auxil, packcr_memory_recycler_t *recycler, size_t element_size) {
         
     | 
| 
       518 
518 
     | 
    
         
             
                recycler->pool_list = NULL;
         
     | 
| 
       519 
519 
     | 
    
         
             
                recycler->entry_list = NULL;
         
     | 
| 
       520 
520 
     | 
    
         
             
                recycler->element_size = element_size;
         
     | 
| 
       521 
521 
     | 
    
         
             
            }
         
     | 
| 
       522 
522 
     | 
    
         | 
| 
       523 
     | 
    
         
            -
            static void * 
     | 
| 
      
 523 
     | 
    
         
            +
            static void *packcr_memory_recycler__supply(packcr_auxil_t auxil, packcr_memory_recycler_t *recycler) {
         
     | 
| 
       524 
524 
     | 
    
         
             
                if (recycler->entry_list) {
         
     | 
| 
       525 
     | 
    
         
            -
                     
     | 
| 
      
 525 
     | 
    
         
            +
                    packcr_memory_entry_t *const tmp = recycler->entry_list;
         
     | 
| 
       526 
526 
     | 
    
         
             
                    recycler->entry_list = tmp->next;
         
     | 
| 
       527 
527 
     | 
    
         
             
                    return tmp;
         
     | 
| 
       528 
528 
     | 
    
         
             
                }
         
     | 
| 
       529 
529 
     | 
    
         
             
                if (!recycler->pool_list || recycler->pool_list->unused == 0) {
         
     | 
| 
       530 
     | 
    
         
            -
                    size_t size =  
     | 
| 
      
 530 
     | 
    
         
            +
                    size_t size = PACKCR_POOL_MIN_SIZE;
         
     | 
| 
       531 
531 
     | 
    
         
             
                    if (recycler->pool_list) {
         
     | 
| 
       532 
532 
     | 
    
         
             
                        size = recycler->pool_list->allocated << 1;
         
     | 
| 
       533 
533 
     | 
    
         
             
                        if (size == 0) size = recycler->pool_list->allocated;
         
     | 
| 
       534 
534 
     | 
    
         
             
                    }
         
     | 
| 
       535 
535 
     | 
    
         
             
                    {
         
     | 
| 
       536 
     | 
    
         
            -
                         
     | 
| 
       537 
     | 
    
         
            -
                            auxil, sizeof( 
     | 
| 
      
 536 
     | 
    
         
            +
                        packcr_memory_pool_t *const pool = (packcr_memory_pool_t *)PACKCR_MALLOC(
         
     | 
| 
      
 537 
     | 
    
         
            +
                            auxil, sizeof(packcr_memory_pool_t) + recycler->element_size * size
         
     | 
| 
       538 
538 
     | 
    
         
             
                        );
         
     | 
| 
       539 
539 
     | 
    
         
             
                        pool->allocated = size;
         
     | 
| 
       540 
540 
     | 
    
         
             
                        pool->unused = size;
         
     | 
| 
         @@ -543,136 +543,136 @@ static void *pcc_memory_recycler__supply(pcc_auxil_t auxil, pcc_memory_recycler_ 
     | 
|
| 
       543 
543 
     | 
    
         
             
                    }
         
     | 
| 
       544 
544 
     | 
    
         
             
                }
         
     | 
| 
       545 
545 
     | 
    
         
             
                recycler->pool_list->unused--;
         
     | 
| 
       546 
     | 
    
         
            -
                return (char *)recycler->pool_list + sizeof( 
     | 
| 
      
 546 
     | 
    
         
            +
                return (char *)recycler->pool_list + sizeof(packcr_memory_pool_t) + recycler->element_size * recycler->pool_list->unused;
         
     | 
| 
       547 
547 
     | 
    
         
             
            }
         
     | 
| 
       548 
548 
     | 
    
         | 
| 
       549 
     | 
    
         
            -
            static void  
     | 
| 
       550 
     | 
    
         
            -
                 
     | 
| 
      
 549 
     | 
    
         
            +
            static void packcr_memory_recycler__recycle(packcr_auxil_t auxil, packcr_memory_recycler_t *recycler, void *ptr) {
         
     | 
| 
      
 550 
     | 
    
         
            +
                packcr_memory_entry_t *const tmp = (packcr_memory_entry_t *)ptr;
         
     | 
| 
       551 
551 
     | 
    
         
             
                tmp->next = recycler->entry_list;
         
     | 
| 
       552 
552 
     | 
    
         
             
                recycler->entry_list = tmp;
         
     | 
| 
       553 
553 
     | 
    
         
             
            }
         
     | 
| 
       554 
554 
     | 
    
         | 
| 
       555 
     | 
    
         
            -
            static void  
     | 
| 
      
 555 
     | 
    
         
            +
            static void packcr_memory_recycler__term(packcr_auxil_t auxil, packcr_memory_recycler_t *recycler) {
         
     | 
| 
       556 
556 
     | 
    
         
             
                while (recycler->pool_list) {
         
     | 
| 
       557 
     | 
    
         
            -
                     
     | 
| 
      
 557 
     | 
    
         
            +
                    packcr_memory_pool_t *const tmp = recycler->pool_list;
         
     | 
| 
       558 
558 
     | 
    
         
             
                    recycler->pool_list = tmp->next;
         
     | 
| 
       559 
     | 
    
         
            -
                     
     | 
| 
      
 559 
     | 
    
         
            +
                    PACKCR_FREE(auxil, tmp);
         
     | 
| 
       560 
560 
     | 
    
         
             
                }
         
     | 
| 
       561 
561 
     | 
    
         
             
            }
         
     | 
| 
       562 
562 
     | 
    
         | 
| 
       563 
563 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       564 
     | 
    
         
            -
            static  
     | 
| 
       565 
     | 
    
         
            -
                 
     | 
| 
       566 
     | 
    
         
            -
                 
     | 
| 
       567 
     | 
    
         
            -
                 
     | 
| 
       568 
     | 
    
         
            -
                 
     | 
| 
      
 564 
     | 
    
         
            +
            static packcr_thunk_chunk_t *packcr_thunk_chunk__create(packcr_context_t *ctx) {
         
     | 
| 
      
 565 
     | 
    
         
            +
                packcr_thunk_chunk_t *const chunk = (packcr_thunk_chunk_t *)packcr_memory_recycler__supply(ctx->auxil, &ctx->thunk_chunk_recycler);
         
     | 
| 
      
 566 
     | 
    
         
            +
                packcr_value_table__init(ctx->auxil, &chunk->values);
         
     | 
| 
      
 567 
     | 
    
         
            +
                packcr_capture_table__init(ctx->auxil, &chunk->capts);
         
     | 
| 
      
 568 
     | 
    
         
            +
                packcr_thunk_array__init(ctx->auxil, &chunk->thunks);
         
     | 
| 
       569 
569 
     | 
    
         
             
                chunk->pos = 0;
         
     | 
| 
       570 
570 
     | 
    
         
             
                return chunk;
         
     | 
| 
       571 
571 
     | 
    
         
             
            }
         
     | 
| 
       572 
572 
     | 
    
         | 
| 
       573 
     | 
    
         
            -
            static void  
     | 
| 
      
 573 
     | 
    
         
            +
            static void packcr_thunk_chunk__destroy(packcr_context_t *ctx, packcr_thunk_chunk_t *chunk) {
         
     | 
| 
       574 
574 
     | 
    
         
             
                if (chunk == NULL) return;
         
     | 
| 
       575 
     | 
    
         
            -
                 
     | 
| 
       576 
     | 
    
         
            -
                 
     | 
| 
       577 
     | 
    
         
            -
                 
     | 
| 
       578 
     | 
    
         
            -
                 
     | 
| 
      
 575 
     | 
    
         
            +
                packcr_thunk_array__term(ctx->auxil, &chunk->thunks);
         
     | 
| 
      
 576 
     | 
    
         
            +
                packcr_capture_table__term(ctx->auxil, &chunk->capts);
         
     | 
| 
      
 577 
     | 
    
         
            +
                packcr_value_table__term(ctx->auxil, &chunk->values);
         
     | 
| 
      
 578 
     | 
    
         
            +
                packcr_memory_recycler__recycle(ctx->auxil, &ctx->thunk_chunk_recycler, chunk);
         
     | 
| 
       579 
579 
     | 
    
         
             
            }
         
     | 
| 
       580 
580 
     | 
    
         | 
| 
       581 
     | 
    
         
            -
            static void  
     | 
| 
      
 581 
     | 
    
         
            +
            static void packcr_rule_set__init(packcr_auxil_t auxil, packcr_rule_set_t *set) {
         
     | 
| 
       582 
582 
     | 
    
         
             
                set->len = 0;
         
     | 
| 
       583 
583 
     | 
    
         
             
                set->max = 0;
         
     | 
| 
       584 
584 
     | 
    
         
             
                set->buf = NULL;
         
     | 
| 
       585 
585 
     | 
    
         
             
            }
         
     | 
| 
       586 
586 
     | 
    
         | 
| 
       587 
     | 
    
         
            -
            static size_t  
     | 
| 
      
 587 
     | 
    
         
            +
            static size_t packcr_rule_set__index(packcr_auxil_t auxil, const packcr_rule_set_t *set, packcr_rule_t rule) {
         
     | 
| 
       588 
588 
     | 
    
         
             
                size_t i;
         
     | 
| 
       589 
589 
     | 
    
         
             
                for (i = 0; i < set->len; i++) {
         
     | 
| 
       590 
590 
     | 
    
         
             
                    if (set->buf[i] == rule) return i;
         
     | 
| 
       591 
591 
     | 
    
         
             
                }
         
     | 
| 
       592 
     | 
    
         
            -
                return  
     | 
| 
      
 592 
     | 
    
         
            +
                return PACKCR_VOID_VALUE;
         
     | 
| 
       593 
593 
     | 
    
         
             
            }
         
     | 
| 
       594 
594 
     | 
    
         | 
| 
       595 
     | 
    
         
            -
            static  
     | 
| 
       596 
     | 
    
         
            -
                const size_t i =  
     | 
| 
       597 
     | 
    
         
            -
                if (i !=  
     | 
| 
      
 595 
     | 
    
         
            +
            static packcr_bool_t packcr_rule_set__add(packcr_auxil_t auxil, packcr_rule_set_t *set, packcr_rule_t rule) {
         
     | 
| 
      
 596 
     | 
    
         
            +
                const size_t i = packcr_rule_set__index(auxil, set, rule);
         
     | 
| 
      
 597 
     | 
    
         
            +
                if (i != PACKCR_VOID_VALUE) return PACKCR_FALSE;
         
     | 
| 
       598 
598 
     | 
    
         
             
                if (set->max <= set->len) {
         
     | 
| 
       599 
599 
     | 
    
         
             
                    const size_t n = set->len + 1;
         
     | 
| 
       600 
600 
     | 
    
         
             
                    size_t m = set->max;
         
     | 
| 
       601 
     | 
    
         
            -
                    if (m == 0) m =  
     | 
| 
      
 601 
     | 
    
         
            +
                    if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
         
     | 
| 
       602 
602 
     | 
    
         
             
                    while (m < n && m != 0) m <<= 1;
         
     | 
| 
       603 
603 
     | 
    
         
             
                    if (m == 0) m = n;
         
     | 
| 
       604 
     | 
    
         
            -
                    set->buf = ( 
     | 
| 
      
 604 
     | 
    
         
            +
                    set->buf = (packcr_rule_t *)PACKCR_REALLOC(auxil, set->buf, sizeof(packcr_rule_t) * m);
         
     | 
| 
       605 
605 
     | 
    
         
             
                    set->max = m;
         
     | 
| 
       606 
606 
     | 
    
         
             
                }
         
     | 
| 
       607 
607 
     | 
    
         
             
                set->buf[set->len++] = rule;
         
     | 
| 
       608 
     | 
    
         
            -
                return  
     | 
| 
      
 608 
     | 
    
         
            +
                return PACKCR_TRUE;
         
     | 
| 
       609 
609 
     | 
    
         
             
            }
         
     | 
| 
       610 
610 
     | 
    
         | 
| 
       611 
     | 
    
         
            -
            static void  
     | 
| 
       612 
     | 
    
         
            -
                 
     | 
| 
      
 611 
     | 
    
         
            +
            static void packcr_rule_set__term(packcr_auxil_t auxil, packcr_rule_set_t *set) {
         
     | 
| 
      
 612 
     | 
    
         
            +
                PACKCR_FREE(auxil, set->buf);
         
     | 
| 
       613 
613 
     | 
    
         
             
            }
         
     | 
| 
       614 
614 
     | 
    
         | 
| 
       615 
     | 
    
         
            -
            static  
     | 
| 
       616 
     | 
    
         
            -
                 
     | 
| 
      
 615 
     | 
    
         
            +
            static packcr_lr_memo_t *packcr_lr_memo__create(packcr_context_t *ctx, size_t offset<% if @location %>, packcr_location_t offset_loc<% end %>) {
         
     | 
| 
      
 616 
     | 
    
         
            +
                packcr_lr_memo_t *memo = (packcr_lr_memo_t *)packcr_memory_recycler__supply(ctx->auxil, &ctx->lr_memo_recycler);
         
     | 
| 
       617 
617 
     | 
    
         
             
                memo->offset = offset;
         
     | 
| 
       618 
618 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       619 
619 
     | 
    
         
             
                memo->offset_loc = offset_loc;
         
     | 
| 
       620 
620 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       621 
621 
     | 
    
         
             
                memo->chunk = NULL;
         
     | 
| 
       622 
     | 
    
         
            -
                memo->fail =  
     | 
| 
       623 
     | 
    
         
            -
                memo->grow =  
     | 
| 
      
 622 
     | 
    
         
            +
                memo->fail = PACKCR_TRUE;
         
     | 
| 
      
 623 
     | 
    
         
            +
                memo->grow = PACKCR_FALSE;
         
     | 
| 
       624 
624 
     | 
    
         
             
                memo->hold = NULL;
         
     | 
| 
       625 
625 
     | 
    
         
             
                return memo;
         
     | 
| 
       626 
626 
     | 
    
         
             
            }
         
     | 
| 
       627 
627 
     | 
    
         | 
| 
       628 
     | 
    
         
            -
            static void  
     | 
| 
      
 628 
     | 
    
         
            +
            static void packcr_lr_memo__set_chunk(packcr_context_t *ctx, packcr_lr_memo_t *memo, packcr_thunk_chunk_t *chunk) {
         
     | 
| 
       629 
629 
     | 
    
         
             
                if (memo->chunk) {
         
     | 
| 
       630 
     | 
    
         
            -
                     
     | 
| 
       631 
     | 
    
         
            -
                     
     | 
| 
       632 
     | 
    
         
            -
                     
     | 
| 
       633 
     | 
    
         
            -
                    memo->hold =  
     | 
| 
      
 630 
     | 
    
         
            +
                    packcr_lr_memo_t *const new_hold_memo = packcr_lr_memo__create(ctx, memo->offset<% if @location %>, memo->offset_loc<% end %>);
         
     | 
| 
      
 631 
     | 
    
         
            +
                    new_hold_memo->chunk = memo->chunk;
         
     | 
| 
      
 632 
     | 
    
         
            +
                    new_hold_memo->hold = memo->hold;
         
     | 
| 
      
 633 
     | 
    
         
            +
                    memo->hold = new_hold_memo;
         
     | 
| 
       634 
634 
     | 
    
         
             
                }
         
     | 
| 
       635 
635 
     | 
    
         
             
                memo->chunk = chunk;
         
     | 
| 
       636 
     | 
    
         
            -
                memo->fail =  
     | 
| 
      
 636 
     | 
    
         
            +
                memo->fail = PACKCR_FALSE;
         
     | 
| 
       637 
637 
     | 
    
         
             
            }
         
     | 
| 
       638 
638 
     | 
    
         | 
| 
       639 
     | 
    
         
            -
            static void  
     | 
| 
      
 639 
     | 
    
         
            +
            static void packcr_lr_memo__destroy(packcr_context_t *ctx, packcr_lr_memo_t *memo) {
         
     | 
| 
       640 
640 
     | 
    
         
             
                while (memo != NULL) {
         
     | 
| 
       641 
     | 
    
         
            -
                     
     | 
| 
       642 
     | 
    
         
            -
                     
     | 
| 
       643 
     | 
    
         
            -
                     
     | 
| 
       644 
     | 
    
         
            -
                    memo =  
     | 
| 
      
 641 
     | 
    
         
            +
                    packcr_lr_memo_t *const hold_memo = memo->hold;
         
     | 
| 
      
 642 
     | 
    
         
            +
                    packcr_thunk_chunk__destroy(ctx, memo->chunk);
         
     | 
| 
      
 643 
     | 
    
         
            +
                    packcr_memory_recycler__recycle(ctx->auxil, &ctx->lr_memo_recycler, memo);
         
     | 
| 
      
 644 
     | 
    
         
            +
                    memo = hold_memo;
         
     | 
| 
       645 
645 
     | 
    
         
             
                }
         
     | 
| 
       646 
646 
     | 
    
         
             
            }
         
     | 
| 
       647 
647 
     | 
    
         | 
| 
       648 
     | 
    
         
            -
            static void  
     | 
| 
      
 648 
     | 
    
         
            +
            static void packcr_lr_memo_map__init(packcr_auxil_t auxil, packcr_lr_memo_map_t *map) {
         
     | 
| 
       649 
649 
     | 
    
         
             
                map->len = 0;
         
     | 
| 
       650 
650 
     | 
    
         
             
                map->max = 0;
         
     | 
| 
       651 
651 
     | 
    
         
             
                map->buf = NULL;
         
     | 
| 
       652 
652 
     | 
    
         
             
            }
         
     | 
| 
       653 
653 
     | 
    
         | 
| 
       654 
     | 
    
         
            -
            static size_t  
     | 
| 
      
 654 
     | 
    
         
            +
            static size_t packcr_lr_memo_map__index(packcr_context_t *ctx, packcr_lr_memo_map_t *map, packcr_rule_t rule) {
         
     | 
| 
       655 
655 
     | 
    
         
             
                size_t i;
         
     | 
| 
       656 
656 
     | 
    
         
             
                for (i = 0; i < map->len; i++) {
         
     | 
| 
       657 
657 
     | 
    
         
             
                    if (map->buf[i].rule == rule) return i;
         
     | 
| 
       658 
658 
     | 
    
         
             
                }
         
     | 
| 
       659 
     | 
    
         
            -
                return  
     | 
| 
      
 659 
     | 
    
         
            +
                return PACKCR_VOID_VALUE;
         
     | 
| 
       660 
660 
     | 
    
         
             
            }
         
     | 
| 
       661 
661 
     | 
    
         | 
| 
       662 
     | 
    
         
            -
            static void  
     | 
| 
       663 
     | 
    
         
            -
                const size_t i =  
     | 
| 
       664 
     | 
    
         
            -
                if (i !=  
     | 
| 
       665 
     | 
    
         
            -
                     
     | 
| 
      
 662 
     | 
    
         
            +
            static void packcr_lr_memo_map__put(packcr_context_t *ctx, packcr_lr_memo_map_t *map, packcr_rule_t rule, packcr_lr_memo_t *memo) {
         
     | 
| 
      
 663 
     | 
    
         
            +
                const size_t i = packcr_lr_memo_map__index(ctx, map, rule);
         
     | 
| 
      
 664 
     | 
    
         
            +
                if (i != PACKCR_VOID_VALUE) {
         
     | 
| 
      
 665 
     | 
    
         
            +
                    packcr_lr_memo__destroy(ctx, map->buf[i].memo);
         
     | 
| 
       666 
666 
     | 
    
         
             
                    map->buf[i].memo = memo;
         
     | 
| 
       667 
667 
     | 
    
         
             
                }
         
     | 
| 
       668 
668 
     | 
    
         
             
                else {
         
     | 
| 
       669 
669 
     | 
    
         
             
                    if (map->max <= map->len) {
         
     | 
| 
       670 
670 
     | 
    
         
             
                        const size_t n = map->len + 1;
         
     | 
| 
       671 
671 
     | 
    
         
             
                        size_t m = map->max;
         
     | 
| 
       672 
     | 
    
         
            -
                        if (m == 0) m =  
     | 
| 
      
 672 
     | 
    
         
            +
                        if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
         
     | 
| 
       673 
673 
     | 
    
         
             
                        while (m < n && m != 0) m <<= 1;
         
     | 
| 
       674 
674 
     | 
    
         
             
                        if (m == 0) m = n;
         
     | 
| 
       675 
     | 
    
         
            -
                        map->buf = ( 
     | 
| 
      
 675 
     | 
    
         
            +
                        map->buf = (packcr_lr_memo_map_entry_t *)PACKCR_REALLOC(ctx->auxil, map->buf, sizeof(packcr_lr_memo_map_entry_t) * m);
         
     | 
| 
       676 
676 
     | 
    
         
             
                        map->max = m;
         
     | 
| 
       677 
677 
     | 
    
         
             
                    }
         
     | 
| 
       678 
678 
     | 
    
         
             
                    map->buf[map->len].rule = rule;
         
     | 
| 
         @@ -681,156 +681,156 @@ static void pcc_lr_memo_map__put(pcc_context_t *ctx, pcc_lr_memo_map_t *map, pcc 
     | 
|
| 
       681 
681 
     | 
    
         
             
                }
         
     | 
| 
       682 
682 
     | 
    
         
             
            }
         
     | 
| 
       683 
683 
     | 
    
         | 
| 
       684 
     | 
    
         
            -
            static  
     | 
| 
       685 
     | 
    
         
            -
                const size_t i =  
     | 
| 
       686 
     | 
    
         
            -
                return (i !=  
     | 
| 
      
 684 
     | 
    
         
            +
            static packcr_lr_memo_t *packcr_lr_memo_map__get(packcr_context_t *ctx, packcr_lr_memo_map_t *map, packcr_rule_t rule) {
         
     | 
| 
      
 685 
     | 
    
         
            +
                const size_t i = packcr_lr_memo_map__index(ctx, map, rule);
         
     | 
| 
      
 686 
     | 
    
         
            +
                return (i != PACKCR_VOID_VALUE) ? map->buf[i].memo : NULL;
         
     | 
| 
       687 
687 
     | 
    
         
             
            }
         
     | 
| 
       688 
688 
     | 
    
         | 
| 
       689 
     | 
    
         
            -
            static void  
     | 
| 
      
 689 
     | 
    
         
            +
            static void packcr_lr_memo_map__term(packcr_context_t *ctx, packcr_lr_memo_map_t *map) {
         
     | 
| 
       690 
690 
     | 
    
         
             
                while (map->len > 0) {
         
     | 
| 
       691 
691 
     | 
    
         
             
                    map->len--;
         
     | 
| 
       692 
     | 
    
         
            -
                     
     | 
| 
      
 692 
     | 
    
         
            +
                    packcr_lr_memo__destroy(ctx, map->buf[map->len].memo);
         
     | 
| 
       693 
693 
     | 
    
         
             
                }
         
     | 
| 
       694 
     | 
    
         
            -
                 
     | 
| 
      
 694 
     | 
    
         
            +
                PACKCR_FREE(ctx->auxil, map->buf);
         
     | 
| 
       695 
695 
     | 
    
         
             
            }
         
     | 
| 
       696 
696 
     | 
    
         | 
| 
       697 
     | 
    
         
            -
            static  
     | 
| 
       698 
     | 
    
         
            -
                 
     | 
| 
       699 
     | 
    
         
            -
                 
     | 
| 
      
 697 
     | 
    
         
            +
            static packcr_lr_memo_map_t *packcr_lr_memo_map__create(packcr_context_t *ctx) {
         
     | 
| 
      
 698 
     | 
    
         
            +
                packcr_lr_memo_map_t *const memo = (packcr_lr_memo_map_t *)PACKCR_MALLOC(ctx->auxil, sizeof(packcr_lr_memo_map_t));
         
     | 
| 
      
 699 
     | 
    
         
            +
                packcr_lr_memo_map__init(ctx->auxil, memo);
         
     | 
| 
       700 
700 
     | 
    
         
             
                return memo;
         
     | 
| 
       701 
701 
     | 
    
         
             
            }
         
     | 
| 
       702 
702 
     | 
    
         | 
| 
       703 
     | 
    
         
            -
            static void  
     | 
| 
      
 703 
     | 
    
         
            +
            static void packcr_lr_memo_map__destroy(packcr_context_t *ctx, packcr_lr_memo_map_t *memo) {
         
     | 
| 
       704 
704 
     | 
    
         
             
                if (memo == NULL) return;
         
     | 
| 
       705 
     | 
    
         
            -
                 
     | 
| 
       706 
     | 
    
         
            -
                 
     | 
| 
      
 705 
     | 
    
         
            +
                packcr_lr_memo_map__term(ctx, memo);
         
     | 
| 
      
 706 
     | 
    
         
            +
                PACKCR_FREE(ctx->auxil, memo);
         
     | 
| 
       707 
707 
     | 
    
         
             
            }
         
     | 
| 
       708 
708 
     | 
    
         | 
| 
       709 
     | 
    
         
            -
            static void  
     | 
| 
      
 709 
     | 
    
         
            +
            static void packcr_lr_table__init(packcr_auxil_t auxil, packcr_lr_table_t *table) {
         
     | 
| 
       710 
710 
     | 
    
         
             
                table->ofs = 0;
         
     | 
| 
       711 
711 
     | 
    
         
             
                table->len = 0;
         
     | 
| 
       712 
712 
     | 
    
         
             
                table->max = 0;
         
     | 
| 
       713 
713 
     | 
    
         
             
                table->buf = NULL;
         
     | 
| 
       714 
714 
     | 
    
         
             
            }
         
     | 
| 
       715 
715 
     | 
    
         | 
| 
       716 
     | 
    
         
            -
            static void  
     | 
| 
      
 716 
     | 
    
         
            +
            static void packcr_lr_table__resize(packcr_context_t *ctx, packcr_lr_table_t *table, size_t len) {
         
     | 
| 
       717 
717 
     | 
    
         
             
                size_t i;
         
     | 
| 
       718 
     | 
    
         
            -
                for (i = len; i < table->len; i++)  
     | 
| 
      
 718 
     | 
    
         
            +
                for (i = len; i < table->len; i++) packcr_lr_memo_map__destroy(ctx, table->buf[i]);
         
     | 
| 
       719 
719 
     | 
    
         
             
                if (table->max < len) {
         
     | 
| 
       720 
720 
     | 
    
         
             
                    size_t m = table->max;
         
     | 
| 
       721 
     | 
    
         
            -
                    if (m == 0) m =  
     | 
| 
      
 721 
     | 
    
         
            +
                    if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
         
     | 
| 
       722 
722 
     | 
    
         
             
                    while (m < len && m != 0) m <<= 1;
         
     | 
| 
       723 
723 
     | 
    
         
             
                    if (m == 0) m = len;
         
     | 
| 
       724 
     | 
    
         
            -
                    table->buf = ( 
     | 
| 
      
 724 
     | 
    
         
            +
                    table->buf = (packcr_lr_memo_map_t **)PACKCR_REALLOC(ctx->auxil, table->buf, sizeof(packcr_lr_memo_map_t *) * m);
         
     | 
| 
       725 
725 
     | 
    
         
             
                    table->max = m;
         
     | 
| 
       726 
726 
     | 
    
         
             
                }
         
     | 
| 
       727 
727 
     | 
    
         
             
                for (i = table->len; i < len; i++) table->buf[i] = NULL;
         
     | 
| 
       728 
728 
     | 
    
         
             
                table->len = len;
         
     | 
| 
       729 
729 
     | 
    
         
             
            }
         
     | 
| 
       730 
730 
     | 
    
         | 
| 
       731 
     | 
    
         
            -
            static void  
     | 
| 
      
 731 
     | 
    
         
            +
            static void packcr_lr_table__set_memo(packcr_context_t *ctx, packcr_lr_table_t *table, size_t index, packcr_rule_t rule, packcr_lr_memo_t *memo) {
         
     | 
| 
       732 
732 
     | 
    
         
             
                index += table->ofs;
         
     | 
| 
       733 
     | 
    
         
            -
                if (index >= table->len)  
     | 
| 
       734 
     | 
    
         
            -
                if (table->buf[index] == NULL) table->buf[index] =  
     | 
| 
       735 
     | 
    
         
            -
                 
     | 
| 
      
 733 
     | 
    
         
            +
                if (index >= table->len) packcr_lr_table__resize(ctx, table, index + 1);
         
     | 
| 
      
 734 
     | 
    
         
            +
                if (table->buf[index] == NULL) table->buf[index] = packcr_lr_memo_map__create(ctx);
         
     | 
| 
      
 735 
     | 
    
         
            +
                packcr_lr_memo_map__put(ctx, table->buf[index], rule, memo);
         
     | 
| 
       736 
736 
     | 
    
         
             
            }
         
     | 
| 
       737 
737 
     | 
    
         | 
| 
       738 
     | 
    
         
            -
            static  
     | 
| 
      
 738 
     | 
    
         
            +
            static packcr_lr_memo_t *packcr_lr_table__get_memo(packcr_context_t *ctx, packcr_lr_table_t *table, size_t index, packcr_rule_t rule) {
         
     | 
| 
       739 
739 
     | 
    
         
             
                index += table->ofs;
         
     | 
| 
       740 
740 
     | 
    
         
             
                if (index >= table->len || table->buf[index] == NULL) return NULL;
         
     | 
| 
       741 
     | 
    
         
            -
                return  
     | 
| 
      
 741 
     | 
    
         
            +
                return packcr_lr_memo_map__get(ctx, table->buf[index], rule);
         
     | 
| 
       742 
742 
     | 
    
         
             
            }
         
     | 
| 
       743 
743 
     | 
    
         | 
| 
       744 
     | 
    
         
            -
            static void  
     | 
| 
      
 744 
     | 
    
         
            +
            static void packcr_lr_table__shift(packcr_context_t *ctx, packcr_lr_table_t *table, size_t count) {
         
     | 
| 
       745 
745 
     | 
    
         
             
                size_t i;
         
     | 
| 
       746 
746 
     | 
    
         
             
                if (count > table->len - table->ofs) count = table->len - table->ofs;
         
     | 
| 
       747 
     | 
    
         
            -
                for (i = 0; i < count; i++)  
     | 
| 
      
 747 
     | 
    
         
            +
                for (i = 0; i < count; i++) packcr_lr_memo_map__destroy(ctx, table->buf[table->ofs++]);
         
     | 
| 
       748 
748 
     | 
    
         
             
                if (table->ofs > (table->max >> 1)) {
         
     | 
| 
       749 
     | 
    
         
            -
                    memmove(table->buf, table->buf + table->ofs, sizeof( 
     | 
| 
      
 749 
     | 
    
         
            +
                    memmove(table->buf, table->buf + table->ofs, sizeof(packcr_lr_memo_map_t *) * (table->len - table->ofs));
         
     | 
| 
       750 
750 
     | 
    
         
             
                    table->len -= table->ofs;
         
     | 
| 
       751 
751 
     | 
    
         
             
                    table->ofs = 0;
         
     | 
| 
       752 
752 
     | 
    
         
             
                }
         
     | 
| 
       753 
753 
     | 
    
         
             
            }
         
     | 
| 
       754 
754 
     | 
    
         | 
| 
       755 
     | 
    
         
            -
            static void  
     | 
| 
      
 755 
     | 
    
         
            +
            static void packcr_lr_table__term(packcr_context_t *ctx, packcr_lr_table_t *table) {
         
     | 
| 
       756 
756 
     | 
    
         
             
                while (table->len > table->ofs) {
         
     | 
| 
       757 
757 
     | 
    
         
             
                    table->len--;
         
     | 
| 
       758 
     | 
    
         
            -
                     
     | 
| 
      
 758 
     | 
    
         
            +
                    packcr_lr_memo_map__destroy(ctx, table->buf[table->len]);
         
     | 
| 
       759 
759 
     | 
    
         
             
                }
         
     | 
| 
       760 
     | 
    
         
            -
                 
     | 
| 
      
 760 
     | 
    
         
            +
                PACKCR_FREE(ctx->auxil, table->buf);
         
     | 
| 
       761 
761 
     | 
    
         
             
            }
         
     | 
| 
       762 
762 
     | 
    
         | 
| 
       763 
     | 
    
         
            -
            static  
     | 
| 
       764 
     | 
    
         
            -
                 
     | 
| 
      
 763 
     | 
    
         
            +
            static packcr_context_t *packcr_context__create(packcr_auxil_t auxil) {
         
     | 
| 
      
 764 
     | 
    
         
            +
                packcr_context_t *const ctx = (packcr_context_t *)PACKCR_MALLOC(auxil, sizeof(packcr_context_t));
         
     | 
| 
       765 
765 
     | 
    
         
             
                ctx->buffer_start_position = 0;
         
     | 
| 
       766 
766 
     | 
    
         
             
                ctx->position_offset = 0;
         
     | 
| 
       767 
767 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       768 
     | 
    
         
            -
                 
     | 
| 
       769 
     | 
    
         
            -
                 
     | 
| 
      
 768 
     | 
    
         
            +
                packcr_location_init(&ctx->buffer_start_position_loc);
         
     | 
| 
      
 769 
     | 
    
         
            +
                packcr_location_init(&ctx->position_offset_loc);
         
     | 
| 
       770 
770 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       771 
771 
     | 
    
         
             
                ctx->level = 0;
         
     | 
| 
       772 
     | 
    
         
            -
                 
     | 
| 
       773 
     | 
    
         
            -
                 
     | 
| 
       774 
     | 
    
         
            -
                 
     | 
| 
       775 
     | 
    
         
            -
                 
     | 
| 
       776 
     | 
    
         
            -
                 
     | 
| 
      
 772 
     | 
    
         
            +
                packcr_char_array__init(auxil, &ctx->buffer);
         
     | 
| 
      
 773 
     | 
    
         
            +
                packcr_lr_table__init(auxil, &ctx->lrtable);
         
     | 
| 
      
 774 
     | 
    
         
            +
                packcr_thunk_array__init(auxil, &ctx->thunks);
         
     | 
| 
      
 775 
     | 
    
         
            +
                packcr_memory_recycler__init(auxil, &ctx->thunk_chunk_recycler, sizeof(packcr_thunk_chunk_t));
         
     | 
| 
      
 776 
     | 
    
         
            +
                packcr_memory_recycler__init(auxil, &ctx->lr_memo_recycler, sizeof(packcr_lr_memo_t));
         
     | 
| 
       777 
777 
     | 
    
         
             
                ctx->auxil = auxil;
         
     | 
| 
       778 
778 
     | 
    
         
             
                return ctx;
         
     | 
| 
       779 
779 
     | 
    
         
             
            }
         
     | 
| 
       780 
780 
     | 
    
         | 
| 
       781 
     | 
    
         
            -
            static void  
     | 
| 
      
 781 
     | 
    
         
            +
            static void packcr_context__destroy(packcr_context_t *ctx) {
         
     | 
| 
       782 
782 
     | 
    
         
             
                if (ctx == NULL) return;
         
     | 
| 
       783 
     | 
    
         
            -
                 
     | 
| 
       784 
     | 
    
         
            -
                 
     | 
| 
       785 
     | 
    
         
            -
                 
     | 
| 
       786 
     | 
    
         
            -
                 
     | 
| 
       787 
     | 
    
         
            -
                 
     | 
| 
       788 
     | 
    
         
            -
                 
     | 
| 
      
 783 
     | 
    
         
            +
                packcr_thunk_array__term(ctx->auxil, &ctx->thunks);
         
     | 
| 
      
 784 
     | 
    
         
            +
                packcr_lr_table__term(ctx, &ctx->lrtable);
         
     | 
| 
      
 785 
     | 
    
         
            +
                packcr_char_array__term(ctx->auxil, &ctx->buffer);
         
     | 
| 
      
 786 
     | 
    
         
            +
                packcr_memory_recycler__term(ctx->auxil, &ctx->thunk_chunk_recycler);
         
     | 
| 
      
 787 
     | 
    
         
            +
                packcr_memory_recycler__term(ctx->auxil, &ctx->lr_memo_recycler);
         
     | 
| 
      
 788 
     | 
    
         
            +
                PACKCR_FREE(ctx->auxil, ctx);
         
     | 
| 
       789 
789 
     | 
    
         
             
            }
         
     | 
| 
       790 
790 
     | 
    
         | 
| 
       791 
     | 
    
         
            -
            static size_t  
     | 
| 
      
 791 
     | 
    
         
            +
            static size_t packcr_refill_buffer(packcr_context_t *ctx, size_t num) {
         
     | 
| 
       792 
792 
     | 
    
         
             
                if (ctx->buffer.len >= ctx->position_offset + num) return ctx->buffer.len - ctx->position_offset;
         
     | 
| 
       793 
793 
     | 
    
         
             
                while (ctx->buffer.len < ctx->position_offset + num) {
         
     | 
| 
       794 
     | 
    
         
            -
                    const int c =  
     | 
| 
      
 794 
     | 
    
         
            +
                    const int c = PACKCR_GETCHAR(ctx->auxil);
         
     | 
| 
       795 
795 
     | 
    
         
             
                    if (c < 0) break;
         
     | 
| 
       796 
     | 
    
         
            -
                     
     | 
| 
      
 796 
     | 
    
         
            +
                    packcr_char_array__add(ctx->auxil, &ctx->buffer, (char)c);
         
     | 
| 
       797 
797 
     | 
    
         
             
                }
         
     | 
| 
       798 
798 
     | 
    
         
             
                return ctx->buffer.len - ctx->position_offset;
         
     | 
| 
       799 
799 
     | 
    
         
             
            }
         
     | 
| 
       800 
800 
     | 
    
         | 
| 
       801 
801 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       802 
     | 
    
         
            -
            static void  
     | 
| 
      
 802 
     | 
    
         
            +
            static void packcr_commit_buffer(packcr_context_t *ctx) {
         
     | 
| 
       803 
803 
     | 
    
         
             
                memmove(ctx->buffer.buf, ctx->buffer.buf + ctx->position_offset, ctx->buffer.len - ctx->position_offset);
         
     | 
| 
       804 
804 
     | 
    
         
             
                ctx->buffer.len -= ctx->position_offset;
         
     | 
| 
       805 
805 
     | 
    
         
             
                ctx->buffer_start_position += ctx->position_offset;
         
     | 
| 
       806 
     | 
    
         
            -
                 
     | 
| 
      
 806 
     | 
    
         
            +
                packcr_lr_table__shift(ctx, &ctx->lrtable, ctx->position_offset);
         
     | 
| 
       807 
807 
     | 
    
         
             
                ctx->position_offset = 0;
         
     | 
| 
       808 
808 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       809 
     | 
    
         
            -
                ctx->buffer_start_position_loc =  
     | 
| 
       810 
     | 
    
         
            -
                 
     | 
| 
      
 809 
     | 
    
         
            +
                ctx->buffer_start_position_loc = packcr_location_add(ctx->buffer_start_position_loc, ctx->position_offset_loc);
         
     | 
| 
      
 810 
     | 
    
         
            +
                packcr_location_init(&ctx->position_offset_loc);
         
     | 
| 
       811 
811 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       812 
812 
     | 
    
         
             
            }
         
     | 
| 
       813 
813 
     | 
    
         | 
| 
       814 
814 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       815 
     | 
    
         
            -
            static const char * 
     | 
| 
      
 815 
     | 
    
         
            +
            static const char *packcr_get_capture_string(packcr_context_t *ctx, const packcr_capture_t *capt) {
         
     | 
| 
       816 
816 
     | 
    
         
             
                if (capt->string == NULL)
         
     | 
| 
       817 
     | 
    
         
            -
                    (( 
     | 
| 
       818 
     | 
    
         
            -
                         
     | 
| 
      
 817 
     | 
    
         
            +
                    ((packcr_capture_t *)capt)->string =
         
     | 
| 
      
 818 
     | 
    
         
            +
                        packcr_strndup_e(ctx->auxil, ctx->buffer.buf + capt->range.start, capt->range.end - capt->range.start);
         
     | 
| 
       819 
819 
     | 
    
         
             
                return capt->string;
         
     | 
| 
       820 
820 
     | 
    
         
             
            }
         
     | 
| 
       821 
821 
     | 
    
         | 
| 
       822 
822 
     | 
    
         
             
            <% if @utf8 -%>
         
     | 
| 
       823 
     | 
    
         
            -
            static size_t  
     | 
| 
      
 823 
     | 
    
         
            +
            static size_t packcr_get_char_as_utf32(packcr_context_t *ctx, int *out) { /* with checking UTF-8 validity */
         
     | 
| 
       824 
824 
     | 
    
         
             
                int c, u;
         
     | 
| 
       825 
825 
     | 
    
         
             
                size_t n;
         
     | 
| 
       826 
     | 
    
         
            -
                if ( 
     | 
| 
      
 826 
     | 
    
         
            +
                if (packcr_refill_buffer(ctx, 1) < 1) return 0;
         
     | 
| 
       827 
827 
     | 
    
         
             
                c = (int)(unsigned char)ctx->buffer.buf[ctx->position_offset];
         
     | 
| 
       828 
828 
     | 
    
         
             
                n = (c < 0x80) ? 1 :
         
     | 
| 
       829 
829 
     | 
    
         
             
                    ((c & 0xe0) == 0xc0) ? 2 :
         
     | 
| 
       830 
830 
     | 
    
         
             
                    ((c & 0xf0) == 0xe0) ? 3 :
         
     | 
| 
       831 
831 
     | 
    
         
             
                    ((c & 0xf8) == 0xf0) ? 4 : 0;
         
     | 
| 
       832 
832 
     | 
    
         
             
                if (n < 1) return 0;
         
     | 
| 
       833 
     | 
    
         
            -
                if ( 
     | 
| 
      
 833 
     | 
    
         
            +
                if (packcr_refill_buffer(ctx, n) < n) return 0;
         
     | 
| 
       834 
834 
     | 
    
         
             
                switch (n) {
         
     | 
| 
       835 
835 
     | 
    
         
             
                case 1:
         
     | 
| 
       836 
836 
     | 
    
         
             
                    u = c;
         
     | 
| 
         @@ -873,28 +873,28 @@ static size_t pcc_get_char_as_utf32(pcc_context_t *ctx, int *out) { /* with chec 
     | 
|
| 
       873 
873 
     | 
    
         
             
            }
         
     | 
| 
       874 
874 
     | 
    
         | 
| 
       875 
875 
     | 
    
         
             
            <% end -%>
         
     | 
| 
       876 
     | 
    
         
            -
            static void  
     | 
| 
      
 876 
     | 
    
         
            +
            static void packcr_grow_lr(packcr_context_t *ctx, packcr_rule_t rule, size_t offset<% if @location %>, packcr_location_t offset_loc<% end %>) {
         
     | 
| 
       877 
877 
     | 
    
         
             
                while(1) {
         
     | 
| 
       878 
878 
     | 
    
         
             
                    const size_t old_offset = ctx->position_offset;
         
     | 
| 
       879 
     | 
    
         
            -
                     
     | 
| 
       880 
     | 
    
         
            -
                     
     | 
| 
       881 
     | 
    
         
            -
                     
     | 
| 
      
 879 
     | 
    
         
            +
                    packcr_thunk_chunk_t *chunk;
         
     | 
| 
      
 880 
     | 
    
         
            +
                    packcr_lr_memo_t *memo;
         
     | 
| 
      
 881 
     | 
    
         
            +
                    packcr_rule_set_t limits;
         
     | 
| 
       882 
882 
     | 
    
         
             
                    ctx->position_offset = offset;
         
     | 
| 
       883 
883 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       884 
884 
     | 
    
         
             
                    ctx->position_offset_loc = offset_loc;
         
     | 
| 
       885 
885 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       886 
     | 
    
         
            -
                     
     | 
| 
       887 
     | 
    
         
            -
                     
     | 
| 
      
 886 
     | 
    
         
            +
                    packcr_rule_set__init(ctx->auxil, &limits);
         
     | 
| 
      
 887 
     | 
    
         
            +
                    packcr_rule_set__add(ctx->auxil, &limits, rule);
         
     | 
| 
       888 
888 
     | 
    
         
             
                    chunk = rule(ctx, offset<% if @location %>, offset_loc<% end %>, &limits);
         
     | 
| 
       889 
     | 
    
         
            -
                     
     | 
| 
      
 889 
     | 
    
         
            +
                    packcr_rule_set__term(ctx->auxil, &limits);
         
     | 
| 
       890 
890 
     | 
    
         
             
                    if (!chunk)
         
     | 
| 
       891 
891 
     | 
    
         
             
                        break;
         
     | 
| 
       892 
892 
     | 
    
         
             
                    if (ctx->position_offset <= old_offset) {
         
     | 
| 
       893 
     | 
    
         
            -
                         
     | 
| 
      
 893 
     | 
    
         
            +
                        packcr_thunk_chunk__destroy(ctx, chunk);
         
     | 
| 
       894 
894 
     | 
    
         
             
                        break;
         
     | 
| 
       895 
895 
     | 
    
         
             
                    }
         
     | 
| 
       896 
     | 
    
         
            -
                    memo =  
     | 
| 
       897 
     | 
    
         
            -
                     
     | 
| 
      
 896 
     | 
    
         
            +
                    memo = packcr_lr_table__get_memo(ctx, &ctx->lrtable, offset, rule);
         
     | 
| 
      
 897 
     | 
    
         
            +
                    packcr_lr_memo__set_chunk(ctx, memo, chunk);
         
     | 
| 
       898 
898 
     | 
    
         
             
                    memo->offset = ctx->position_offset;
         
     | 
| 
       899 
899 
     | 
    
         
             
                    <%- if @location -%>
         
     | 
| 
       900 
900 
     | 
    
         
             
                    memo->offset_loc = ctx->position_offset_loc;
         
     | 
| 
         @@ -903,76 +903,90 @@ static void pcc_grow_lr(pcc_context_t *ctx, pcc_rule_t rule, size_t offset<% if 
     | 
|
| 
       903 
903 
     | 
    
         
             
            }
         
     | 
| 
       904 
904 
     | 
    
         | 
| 
       905 
905 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       906 
     | 
    
         
            -
            static  
     | 
| 
       907 
     | 
    
         
            -
                 
     | 
| 
      
 906 
     | 
    
         
            +
            static packcr_thunk_chunk_t *packcr_get_rule_thunk_chunk(packcr_context_t *ctx, packcr_rule_t rule) {
         
     | 
| 
      
 907 
     | 
    
         
            +
                packcr_thunk_chunk_t *c = NULL;
         
     | 
| 
       908 
908 
     | 
    
         
             
                size_t offset = ctx->position_offset;
         
     | 
| 
       909 
909 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       910 
     | 
    
         
            -
                 
     | 
| 
      
 910 
     | 
    
         
            +
                packcr_location_t offset_loc = ctx->position_offset_loc;
         
     | 
| 
       911 
911 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       912 
     | 
    
         
            -
                 
     | 
| 
      
 912 
     | 
    
         
            +
                packcr_lr_memo_t *memo = packcr_lr_table__get_memo(ctx, &ctx->lrtable, offset, rule);
         
     | 
| 
       913 
913 
     | 
    
         | 
| 
       914 
     | 
    
         
            -
                if ( 
     | 
| 
       915 
     | 
    
         
            -
                     
     | 
| 
       916 
     | 
    
         
            -
                     
     | 
| 
      
 914 
     | 
    
         
            +
                if (memo == NULL) {
         
     | 
| 
      
 915 
     | 
    
         
            +
                    memo = packcr_lr_memo__create(ctx, offset<% if @location %>, offset_loc<% end %>);
         
     | 
| 
      
 916 
     | 
    
         
            +
                    packcr_lr_table__set_memo(ctx, &ctx->lrtable, offset, rule, memo);
         
     | 
| 
       917 
917 
     | 
    
         
             
                    c = rule(ctx, offset<% if @location %>, offset_loc<% end %>, NULL);
         
     | 
| 
       918 
     | 
    
         
            -
                     
     | 
| 
       919 
     | 
    
         
            -
                     
     | 
| 
      
 918 
     | 
    
         
            +
                    packcr_lr_memo__set_chunk(ctx, memo, c);
         
     | 
| 
      
 919 
     | 
    
         
            +
                    memo->offset = ctx->position_offset;
         
     | 
| 
      
 920 
     | 
    
         
            +
            <%- if @location -%>
         
     | 
| 
      
 921 
     | 
    
         
            +
                    memo->offset_loc = ctx->position_offset_loc;
         
     | 
| 
      
 922 
     | 
    
         
            +
            <%- end -%>
         
     | 
| 
      
 923 
     | 
    
         
            +
                    if (memo->grow) {
         
     | 
| 
      
 924 
     | 
    
         
            +
                        packcr_grow_lr(ctx, rule, offset<% if @location %>, offset_loc<% end %>);
         
     | 
| 
      
 925 
     | 
    
         
            +
                        memo->grow = PACKCR_FALSE;
         
     | 
| 
      
 926 
     | 
    
         
            +
                        ctx->position_offset = memo->offset;
         
     | 
| 
       920 
927 
     | 
    
         
             
            <%- if @location -%>
         
     | 
| 
       921 
     | 
    
         
            -
             
     | 
| 
      
 928 
     | 
    
         
            +
                        ctx->position_offset_loc = memo->offset_loc;
         
     | 
| 
       922 
929 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       923 
     | 
    
         
            -
             
     | 
| 
       924 
     | 
    
         
            -
                        pcc_grow_lr(ctx, rule, offset<% if @location %>, offset_loc<% end %>);
         
     | 
| 
       925 
     | 
    
         
            -
                        a->grow = PCC_FALSE;
         
     | 
| 
       926 
     | 
    
         
            -
                        ctx->position_offset = a->offset;
         
     | 
| 
       927 
     | 
    
         
            -
                        return a->chunk;
         
     | 
| 
      
 930 
     | 
    
         
            +
                        return memo->chunk;
         
     | 
| 
       928 
931 
     | 
    
         
             
                    }
         
     | 
| 
       929 
932 
     | 
    
         
             
                    return c;
         
     | 
| 
       930 
     | 
    
         
            -
                } else if ( 
     | 
| 
       931 
     | 
    
         
            -
                     
     | 
| 
       932 
     | 
    
         
            -
                     
     | 
| 
      
 933 
     | 
    
         
            +
                } else if (memo->fail) {
         
     | 
| 
      
 934 
     | 
    
         
            +
                    packcr_lr_memo__set_chunk(ctx, memo, NULL);
         
     | 
| 
      
 935 
     | 
    
         
            +
                    memo->grow = PACKCR_TRUE;
         
     | 
| 
       933 
936 
     | 
    
         
             
                    return NULL;
         
     | 
| 
       934 
937 
     | 
    
         
             
                }
         
     | 
| 
       935 
     | 
    
         
            -
                ctx->position_offset =  
     | 
| 
       936 
     | 
    
         
            -
             
     | 
| 
      
 938 
     | 
    
         
            +
                ctx->position_offset = memo->offset;
         
     | 
| 
      
 939 
     | 
    
         
            +
            <%- if @location -%>
         
     | 
| 
      
 940 
     | 
    
         
            +
                ctx->position_offset_loc = memo->offset_loc;
         
     | 
| 
      
 941 
     | 
    
         
            +
            <%- end -%>
         
     | 
| 
      
 942 
     | 
    
         
            +
                return memo->chunk;
         
     | 
| 
       937 
943 
     | 
    
         
             
            }
         
     | 
| 
       938 
944 
     | 
    
         | 
| 
       939 
945 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       940 
     | 
    
         
            -
            static  
     | 
| 
       941 
     | 
    
         
            -
                static  
     | 
| 
       942 
     | 
    
         
            -
                 
     | 
| 
      
 946 
     | 
    
         
            +
            static packcr_bool_t packcr_apply_rule(packcr_context_t *ctx, packcr_rule_t rule, packcr_thunk_array_t *thunks, packcr_value_t *value, size_t offset<% if @location %>, packcr_location_t offset_loc<% end %>, packcr_rule_set_t *limits) {
         
     | 
| 
      
 947 
     | 
    
         
            +
                static packcr_value_t null;
         
     | 
| 
      
 948 
     | 
    
         
            +
                packcr_thunk_chunk_t *c;
         
     | 
| 
       943 
949 
     | 
    
         
             
                if (limits != NULL) {
         
     | 
| 
       944 
     | 
    
         
            -
                     
     | 
| 
       945 
     | 
    
         
            -
                     
     | 
| 
      
 950 
     | 
    
         
            +
                    packcr_lr_memo_t *memo;
         
     | 
| 
      
 951 
     | 
    
         
            +
                    packcr_rule_set__add(ctx->auxil, limits, rule);
         
     | 
| 
       946 
952 
     | 
    
         
             
                    c = rule(ctx, offset<% if @location %>, offset_loc<% end %>, limits);
         
     | 
| 
       947 
     | 
    
         
            -
                     
     | 
| 
       948 
     | 
    
         
            -
                    if ( 
     | 
| 
       949 
     | 
    
         
            -
                         
     | 
| 
       950 
     | 
    
         
            -
             
     | 
| 
      
 953 
     | 
    
         
            +
                    memo = packcr_lr_table__get_memo(ctx, &ctx->lrtable, offset, rule);
         
     | 
| 
      
 954 
     | 
    
         
            +
                    if (memo == NULL || ctx->position_offset <= memo->offset) {
         
     | 
| 
      
 955 
     | 
    
         
            +
                        if (memo) {
         
     | 
| 
      
 956 
     | 
    
         
            +
                            c = memo->chunk;
         
     | 
| 
      
 957 
     | 
    
         
            +
                            ctx->position_offset = memo->offset;
         
     | 
| 
      
 958 
     | 
    
         
            +
                            <%- if @location -%>
         
     | 
| 
      
 959 
     | 
    
         
            +
                            ctx->position_offset_loc = memo->offset_loc;
         
     | 
| 
      
 960 
     | 
    
         
            +
                            <%- end -%>
         
     | 
| 
      
 961 
     | 
    
         
            +
                        }
         
     | 
| 
       951 
962 
     | 
    
         
             
                    } else {
         
     | 
| 
       952 
     | 
    
         
            -
                         
     | 
| 
       953 
     | 
    
         
            -
                         
     | 
| 
      
 963 
     | 
    
         
            +
                        packcr_lr_memo__set_chunk(ctx, memo, c);
         
     | 
| 
      
 964 
     | 
    
         
            +
                        memo->offset = ctx->position_offset;
         
     | 
| 
      
 965 
     | 
    
         
            +
                        <%- if @location -%>
         
     | 
| 
      
 966 
     | 
    
         
            +
                        memo->offset_loc = ctx->position_offset_loc;
         
     | 
| 
      
 967 
     | 
    
         
            +
                        <%- end -%>
         
     | 
| 
       954 
968 
     | 
    
         
             
                    }
         
     | 
| 
       955 
969 
     | 
    
         
             
                } else {
         
     | 
| 
       956 
     | 
    
         
            -
                    c =  
     | 
| 
      
 970 
     | 
    
         
            +
                    c = packcr_get_rule_thunk_chunk(ctx, rule);
         
     | 
| 
       957 
971 
     | 
    
         
             
                }
         
     | 
| 
       958 
     | 
    
         
            -
                if (c == NULL) return  
     | 
| 
      
 972 
     | 
    
         
            +
                if (c == NULL) return PACKCR_FALSE;
         
     | 
| 
       959 
973 
     | 
    
         
             
                if (value == NULL) value = &null;
         
     | 
| 
       960 
     | 
    
         
            -
                memset(value, 0, sizeof( 
     | 
| 
       961 
     | 
    
         
            -
                 
     | 
| 
       962 
     | 
    
         
            -
                return  
     | 
| 
      
 974 
     | 
    
         
            +
                memset(value, 0, sizeof(packcr_value_t)); /* in case */
         
     | 
| 
      
 975 
     | 
    
         
            +
                packcr_thunk_array__add(ctx->auxil, thunks, packcr_thunk__create_node(ctx->auxil, &c->thunks, value));
         
     | 
| 
      
 976 
     | 
    
         
            +
                return PACKCR_TRUE;
         
     | 
| 
       963 
977 
     | 
    
         
             
            }
         
     | 
| 
       964 
978 
     | 
    
         | 
| 
       965 
979 
     | 
    
         
             
            MARK_FUNC_AS_USED
         
     | 
| 
       966 
     | 
    
         
            -
            static void  
     | 
| 
      
 980 
     | 
    
         
            +
            static void packcr_do_action(packcr_context_t *ctx, const packcr_thunk_array_t *thunks, packcr_value_t *value) {
         
     | 
| 
       967 
981 
     | 
    
         
             
                size_t i;
         
     | 
| 
       968 
982 
     | 
    
         
             
                for (i = 0; i < thunks->len; i++) {
         
     | 
| 
       969 
     | 
    
         
            -
                     
     | 
| 
      
 983 
     | 
    
         
            +
                    packcr_thunk_t *const thunk = thunks->buf[i];
         
     | 
| 
       970 
984 
     | 
    
         
             
                    switch (thunk->type) {
         
     | 
| 
       971 
     | 
    
         
            -
                    case  
     | 
| 
      
 985 
     | 
    
         
            +
                    case PACKCR_THUNK_LEAF:
         
     | 
| 
       972 
986 
     | 
    
         
             
                        thunk->data.leaf.action(ctx, thunk, value);
         
     | 
| 
       973 
987 
     | 
    
         
             
                        break;
         
     | 
| 
       974 
     | 
    
         
            -
                    case  
     | 
| 
       975 
     | 
    
         
            -
                         
     | 
| 
      
 988 
     | 
    
         
            +
                    case PACKCR_THUNK_NODE:
         
     | 
| 
      
 989 
     | 
    
         
            +
                        packcr_do_action(ctx, thunk->data.node.thunks, thunk->data.node.value);
         
     | 
| 
       976 
990 
     | 
    
         
             
                        break;
         
     | 
| 
       977 
991 
     | 
    
         
             
                    default: /* unknown */
         
     | 
| 
       978 
992 
     | 
    
         
             
                        break;
         
     | 
| 
         @@ -982,32 +996,32 @@ static void pcc_do_action(pcc_context_t *ctx, const pcc_thunk_array_t *thunks, p 
     | 
|
| 
       982 
996 
     | 
    
         | 
| 
       983 
997 
     | 
    
         
             
            <%- @root.rules.each do |rule| -%>
         
     | 
| 
       984 
998 
     | 
    
         
             
            <%-   rule.codes.each do |code| -%>
         
     | 
| 
       985 
     | 
    
         
            -
            static void  
     | 
| 
       986 
     | 
    
         
            -
            #define auxil ( 
     | 
| 
       987 
     | 
    
         
            -
            #define __ (* 
     | 
| 
      
 999 
     | 
    
         
            +
            static void packcr_action_<%= rule.name %>_<%= code.index %>(<%= prefix %>_context_t *__packcr_ctx, packcr_thunk_t *__packcr_in, packcr_value_t *__packcr_out) {
         
     | 
| 
      
 1000 
     | 
    
         
            +
            #define auxil (__packcr_ctx->auxil)
         
     | 
| 
      
 1001 
     | 
    
         
            +
            #define __ (*__packcr_out)
         
     | 
| 
       988 
1002 
     | 
    
         
             
            <%-     code.vars.each do |ref| -%>
         
     | 
| 
       989 
     | 
    
         
            -
            #define <%= ref.var %> (* 
     | 
| 
      
 1003 
     | 
    
         
            +
            #define <%= ref.var %> (*__packcr_in->data.leaf.values.buf[<%= ref.index %>])
         
     | 
| 
       990 
1004 
     | 
    
         
             
            <%      end -%>
         
     | 
| 
       991 
     | 
    
         
            -
            #define _0  
     | 
| 
       992 
     | 
    
         
            -
            #define _0s ((const size_t)( 
     | 
| 
       993 
     | 
    
         
            -
            #define _0e ((const size_t)( 
     | 
| 
      
 1005 
     | 
    
         
            +
            #define _0 packcr_get_capture_string(__packcr_ctx, &__packcr_in->data.leaf.capt0)
         
     | 
| 
      
 1006 
     | 
    
         
            +
            #define _0s ((const size_t)(__packcr_ctx->buffer_start_position + __packcr_in->data.leaf.capt0.range.start))
         
     | 
| 
      
 1007 
     | 
    
         
            +
            #define _0e ((const size_t)(__packcr_ctx->buffer_start_position + __packcr_in->data.leaf.capt0.range.end))
         
     | 
| 
       994 
1008 
     | 
    
         
             
            <%-     if @location -%>
         
     | 
| 
       995 
     | 
    
         
            -
            #define _0sl ((const  
     | 
| 
       996 
     | 
    
         
            -
            #define _0el ((const  
     | 
| 
      
 1009 
     | 
    
         
            +
            #define _0sl ((const packcr_location_t)(packcr_location_add(__packcr_ctx->buffer_start_position_loc, __packcr_in->data.leaf.capt0.range.start_loc)))
         
     | 
| 
      
 1010 
     | 
    
         
            +
            #define _0el ((const packcr_location_t)(packcr_location_add(__packcr_ctx->buffer_start_position_loc, __packcr_in->data.leaf.capt0.range.end_loc)))
         
     | 
| 
       997 
1011 
     | 
    
         
             
            <%-     end -%>
         
     | 
| 
       998 
1012 
     | 
    
         
             
            <%-     if @capture_in_code -%>
         
     | 
| 
       999 
     | 
    
         
            -
            #define _0c  
     | 
| 
      
 1013 
     | 
    
         
            +
            #define _0c __packcr_in->data.leaf.capt0
         
     | 
| 
       1000 
1014 
     | 
    
         
             
            <%-     end -%>
         
     | 
| 
       1001 
1015 
     | 
    
         
             
            <%      code.capts.each do |capture| -%>
         
     | 
| 
       1002 
     | 
    
         
            -
            #define _<%= capture.index + 1 %>  
     | 
| 
       1003 
     | 
    
         
            -
            #define _<%= capture.index + 1 %>s ((const size_t)( 
     | 
| 
       1004 
     | 
    
         
            -
            #define _<%= capture.index + 1 %>e ((const size_t)( 
     | 
| 
      
 1016 
     | 
    
         
            +
            #define _<%= capture.index + 1 %> packcr_get_capture_string(__packcr_ctx, __packcr_in->data.leaf.capts.buf[<%= capture.index %>])
         
     | 
| 
      
 1017 
     | 
    
         
            +
            #define _<%= capture.index + 1 %>s ((const size_t)(__packcr_ctx->buffer_start_position + __packcr_in->data.leaf.capts.buf[<%= capture.index %>]->range.start))
         
     | 
| 
      
 1018 
     | 
    
         
            +
            #define _<%= capture.index + 1 %>e ((const size_t)(__packcr_ctx->buffer_start_position + __packcr_in->data.leaf.capts.buf[<%= capture.index %>]->range.end))
         
     | 
| 
       1005 
1019 
     | 
    
         
             
            <%-       if @location -%>
         
     | 
| 
       1006 
     | 
    
         
            -
            #define _<%= capture.index + 1 %>sl ((const  
     | 
| 
       1007 
     | 
    
         
            -
            #define _<%= capture.index + 1 %>el ((const  
     | 
| 
      
 1020 
     | 
    
         
            +
            #define _<%= capture.index + 1 %>sl ((const packcr_location_t)(packcr_location_add(__packcr_ctx->buffer_start_position_loc, __packcr_in->data.leaf.capts.buf[<%= capture.index %>]->range.start_loc)))
         
     | 
| 
      
 1021 
     | 
    
         
            +
            #define _<%= capture.index + 1 %>el ((const packcr_location_t)(packcr_location_add(__packcr_ctx->buffer_start_position_loc, __packcr_in->data.leaf.capts.buf[<%= capture.index %>]->range.end_loc)))
         
     | 
| 
       1008 
1022 
     | 
    
         
             
            <%-       end -%>
         
     | 
| 
       1009 
1023 
     | 
    
         
             
            <%-       if @capture_in_code -%>
         
     | 
| 
       1010 
     | 
    
         
            -
            #define _<%= capture.index + 1 %>c (* 
     | 
| 
      
 1024 
     | 
    
         
            +
            #define _<%= capture.index + 1 %>c (*__packcr_in->data.leaf.capts.buf[<%= capture.index %>])
         
     | 
| 
       1011 
1025 
     | 
    
         
             
            <%-       end -%>
         
     | 
| 
       1012 
1026 
     | 
    
         
             
            <%-     end -%>
         
     | 
| 
       1013 
1027 
     | 
    
         
             
            <%=     stream.get_code_block(code.code, 4, @iname) -%>
         
     | 
| 
         @@ -1033,7 +1047,7 @@ static void pcc_action_<%= rule.name %>_<%= code.index %>(<%= prefix %>_context_ 
     | 
|
| 
       1033 
1047 
     | 
    
         
             
            <%-   end -%>
         
     | 
| 
       1034 
1048 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       1035 
1049 
     | 
    
         
             
            <%- @root.rules.each do |rule| -%>
         
     | 
| 
       1036 
     | 
    
         
            -
            static  
     | 
| 
      
 1050 
     | 
    
         
            +
            static packcr_thunk_chunk_t *packcr_evaluate_rule_<%= rule.name %>(packcr_context_t *ctx, size_t offset<% if @location %>, packcr_location_t offset_loc<% end %>, packcr_rule_set_t *limits);
         
     | 
| 
       1037 
1051 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       1038 
1052 
     | 
    
         | 
| 
       1039 
1053 
     | 
    
         
             
            <%- @root.rules.each do |rule| -%>
         
     | 
| 
         @@ -1042,24 +1056,24 @@ static pcc_thunk_chunk_t *pcc_evaluate_rule_<%= rule.name %>(pcc_context_t *ctx, 
     | 
|
| 
       1042 
1056 
     | 
    
         | 
| 
       1043 
1057 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       1044 
1058 
     | 
    
         
             
            <%= prefix %>_context_t *<%= prefix %>_create(<%= auxil_def %>auxil) {
         
     | 
| 
       1045 
     | 
    
         
            -
                return  
     | 
| 
      
 1059 
     | 
    
         
            +
                return packcr_context__create(auxil);
         
     | 
| 
       1046 
1060 
     | 
    
         
             
            }
         
     | 
| 
       1047 
1061 
     | 
    
         | 
| 
       1048 
1062 
     | 
    
         
             
            int <%= prefix %>_parse(<%= prefix %>_context_t *ctx, <%= value_def %>*ret) {
         
     | 
| 
       1049 
1063 
     | 
    
         
             
                size_t pos = ctx->buffer_start_position;
         
     | 
| 
       1050 
1064 
     | 
    
         
             
            <%- if !@root.rules.empty? -%>
         
     | 
| 
       1051 
     | 
    
         
            -
                if ( 
     | 
| 
       1052 
     | 
    
         
            -
                     
     | 
| 
      
 1065 
     | 
    
         
            +
                if (packcr_apply_rule(ctx, packcr_evaluate_rule_<%= @root.rules[0].name %>, &ctx->thunks, ret, ctx->position_offset<% if @location %>, ctx->position_offset_loc<% end %>, NULL))
         
     | 
| 
      
 1066 
     | 
    
         
            +
                    packcr_do_action(ctx, &ctx->thunks, ret);
         
     | 
| 
       1053 
1067 
     | 
    
         
             
                else
         
     | 
| 
       1054 
     | 
    
         
            -
                     
     | 
| 
       1055 
     | 
    
         
            -
                 
     | 
| 
      
 1068 
     | 
    
         
            +
                    PACKCR_ERROR(ctx->auxil);
         
     | 
| 
      
 1069 
     | 
    
         
            +
                packcr_commit_buffer(ctx);
         
     | 
| 
       1056 
1070 
     | 
    
         
             
            <%- end -%>
         
     | 
| 
       1057 
     | 
    
         
            -
                 
     | 
| 
       1058 
     | 
    
         
            -
                return pos != ctx->buffer_start_position &&  
     | 
| 
      
 1071 
     | 
    
         
            +
                packcr_thunk_array__revert(ctx->auxil, &ctx->thunks, 0);
         
     | 
| 
      
 1072 
     | 
    
         
            +
                return pos != ctx->buffer_start_position && packcr_refill_buffer(ctx, 1) >= 1;
         
     | 
| 
       1059 
1073 
     | 
    
         
             
            }
         
     | 
| 
       1060 
1074 
     | 
    
         | 
| 
       1061 
1075 
     | 
    
         
             
            void <%= prefix %>_destroy(<%= prefix %>_context_t *ctx) {
         
     | 
| 
       1062 
     | 
    
         
            -
                 
     | 
| 
      
 1076 
     | 
    
         
            +
                packcr_context__destroy(ctx);
         
     | 
| 
       1063 
1077 
     | 
    
         
             
            }
         
     | 
| 
       1064 
1078 
     | 
    
         
             
            <%- if !code(:lsource).empty? -%>
         
     | 
| 
       1065 
1079 
     | 
    
         |