packcr 0.0.6 → 0.0.7

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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/lib/packcr/cli.rb +18 -16
  3. data/lib/packcr/code_block.rb +0 -1
  4. data/lib/packcr/context.rb +19 -17
  5. data/lib/packcr/generated/context.rb +440 -0
  6. data/lib/packcr/generated/node/action_node.rb +60 -0
  7. data/lib/packcr/generated/node/alternate_node.rb +98 -0
  8. data/lib/packcr/generated/node/capture_node.rb +39 -0
  9. data/lib/packcr/generated/node/charclass_node.rb +372 -0
  10. data/lib/packcr/generated/node/eof_node.rb +20 -0
  11. data/lib/packcr/generated/node/error_node.rb +67 -0
  12. data/lib/packcr/generated/node/expand_node.rb +30 -0
  13. data/lib/packcr/generated/node/predicate_node.rb +140 -0
  14. data/lib/packcr/generated/node/quantity_node.rb +167 -0
  15. data/lib/packcr/generated/node/reference_node.rb +70 -0
  16. data/lib/packcr/generated/node/rule_node.rb +63 -0
  17. data/lib/packcr/generated/node/sequence_node.rb +42 -0
  18. data/lib/packcr/generated/node/string_node.rb +60 -0
  19. data/lib/packcr/generator.rb +2 -1
  20. data/lib/packcr/node/action_node.rb +4 -2
  21. data/lib/packcr/node/alternate_node.rb +3 -1
  22. data/lib/packcr/node/capture_node.rb +3 -1
  23. data/lib/packcr/node/charclass_node.rb +24 -28
  24. data/lib/packcr/node/eof_node.rb +4 -2
  25. data/lib/packcr/node/error_node.rb +3 -1
  26. data/lib/packcr/node/expand_node.rb +8 -5
  27. data/lib/packcr/node/predicate_node.rb +4 -2
  28. data/lib/packcr/node/quantity_node.rb +12 -10
  29. data/lib/packcr/node/reference_node.rb +11 -5
  30. data/lib/packcr/node/root_node.rb +1 -0
  31. data/lib/packcr/node/rule_node.rb +7 -4
  32. data/lib/packcr/node/sequence_node.rb +3 -1
  33. data/lib/packcr/node/string_node.rb +9 -6
  34. data/lib/packcr/node.rb +3 -5
  35. data/lib/packcr/parser.rb +4375 -4056
  36. data/lib/packcr/stream.rb +17 -12
  37. data/lib/packcr/templates/context/source.c.erb +187 -410
  38. data/lib/packcr/templates/context/source.rb.erb +91 -156
  39. data/lib/packcr/templates/node/action.c.erb +3 -3
  40. data/lib/packcr/templates/node/action.rb.erb +2 -2
  41. data/lib/packcr/templates/node/alternate.c.erb +8 -8
  42. data/lib/packcr/templates/node/alternate.rb.erb +4 -5
  43. data/lib/packcr/templates/node/capture.c.erb +6 -6
  44. data/lib/packcr/templates/node/capture.rb.erb +4 -4
  45. data/lib/packcr/templates/node/charclass.c.erb +12 -12
  46. data/lib/packcr/templates/node/charclass.rb.erb +6 -6
  47. data/lib/packcr/templates/node/charclass_any.c.erb +3 -3
  48. data/lib/packcr/templates/node/charclass_any.rb.erb +2 -2
  49. data/lib/packcr/templates/node/charclass_fail.c.erb +1 -1
  50. data/lib/packcr/templates/node/charclass_one.c.erb +8 -8
  51. data/lib/packcr/templates/node/charclass_one.rb.erb +6 -6
  52. data/lib/packcr/templates/node/charclass_utf8.c.erb +7 -7
  53. data/lib/packcr/templates/node/charclass_utf8.rb.erb +3 -3
  54. data/lib/packcr/templates/node/charclass_utf8_reverse.rb.erb +5 -5
  55. data/lib/packcr/templates/node/eof.c.erb +1 -1
  56. data/lib/packcr/templates/node/error.c.erb +7 -7
  57. data/lib/packcr/templates/node/error.rb.erb +2 -2
  58. data/lib/packcr/templates/node/expand.c.erb +5 -5
  59. data/lib/packcr/templates/node/expand.rb.erb +3 -3
  60. data/lib/packcr/templates/node/predicate.c.erb +10 -10
  61. data/lib/packcr/templates/node/predicate.rb.erb +6 -6
  62. data/lib/packcr/templates/node/predicate_neg.c.erb +8 -8
  63. data/lib/packcr/templates/node/predicate_neg.rb.erb +6 -6
  64. data/lib/packcr/templates/node/{quantify_many.c.erb → quantity_many.c.erb} +11 -11
  65. data/lib/packcr/templates/node/{quantify_many.rb.erb → quantity_many.rb.erb} +9 -9
  66. data/lib/packcr/templates/node/{quantify_one.c.erb → quantity_one.c.erb} +7 -7
  67. data/lib/packcr/templates/node/{quantify_one.rb.erb → quantity_one.rb.erb} +4 -4
  68. data/lib/packcr/templates/node/reference.c.erb +14 -2
  69. data/lib/packcr/templates/node/reference.rb.erb +16 -4
  70. data/lib/packcr/templates/node/reference_reverse.rb.erb +16 -4
  71. data/lib/packcr/templates/node/rule.c.erb +9 -2
  72. data/lib/packcr/templates/node/rule.rb.erb +26 -19
  73. data/lib/packcr/templates/node/string_many.c.erb +5 -5
  74. data/lib/packcr/templates/node/string_many.rb.erb +3 -3
  75. data/lib/packcr/templates/node/string_one.c.erb +4 -4
  76. data/lib/packcr/templates/node/string_one.rb.erb +3 -3
  77. data/lib/packcr/util.rb +21 -16
  78. data/lib/packcr/version.rb +1 -1
  79. data/lib/packcr.rb +8 -11
  80. metadata +37 -9
  81. data/lib/packcr/tokenizer.rb +0 -2948
@@ -13,18 +13,16 @@ class <%= class_name %>
13
13
  <%- else -%>
14
14
  @buffer = +"".b
15
15
  <%- end %>
16
- @pos = 0
17
- @cur = 0
16
+ @buffer_start_position = 0
17
+ @position_offset = 0
18
18
  @level = 0
19
- @lrstack = []
20
19
  @thunk = ThunkNode.new([], nil, 0)
21
- @heads = {}
22
20
  @memos = LrMemoTable.new
23
21
  @debug = debug
24
22
  @global_values = {}
25
23
  <%- if @location -%>
26
- @pos_loc = Location.new
27
- @cur_loc = Location.new
24
+ @buffer_start_position_loc = Location.new
25
+ @position_offset_loc = Location.new
28
26
  <%- end -%>
29
27
  <%- code(:init).each do |code| -%>
30
28
  <%- %><%= stream.get_code_block(code, 4, @iname) -%>
@@ -45,34 +43,33 @@ class <%= class_name %>
45
43
 
46
44
  def refill_buffer(num, mode = nil)
47
45
  len = @buffer.length
48
- if len >= @cur + num
49
- return len - @cur
46
+ if len >= @position_offset + num
47
+ return len - @position_offset
50
48
  end
51
- while len < @cur + num
49
+ while len < @position_offset + num
52
50
  c = getc
53
51
  break if !c
54
52
  @buffer << c
55
53
  len = @buffer.length
56
54
  end
57
- return len - @cur
55
+ return len - @position_offset
58
56
  end
59
57
 
60
58
  def commit_buffer
61
- @buffer = @buffer[@cur, @buffer.length - @cur]
62
- @pos += @cur
63
- @heads.clear
59
+ @buffer = @buffer[@position_offset, @buffer.length - @position_offset]
60
+ @buffer_start_position += @position_offset
64
61
  @memos.clear
65
- @cur = 0
62
+ @position_offset = 0
66
63
  <%- if @location -%>
67
- @pos_loc = @pos_loc + @cur_loc
68
- @cur_loc = Location.new
64
+ @buffer_start_position_loc = @buffer_start_position_loc + @position_offset_loc
65
+ @position_offset_loc = Location.new
69
66
  <%- end -%>
70
67
  end
71
68
 
72
69
  def parse
73
- pos = @pos
70
+ pos = @buffer_start_position
74
71
  <%- if !@root.rules.empty? -%>
75
- if apply_rule(:evaluate_rule_<%= @root.rules[0].name %>, @thunk.thunks, nil, 0)
72
+ if apply_rule(:evaluate_rule_<%= @root.rules[0].name %>, @thunk.thunks, nil, 0, @buffer_start_position<% if @location %>, @buffer_start_position_loc<% end %>)
76
73
  @thunk.do_action(self, nil, 0)
77
74
  else
78
75
  raise SyntaxError, "can't parse"
@@ -80,7 +77,7 @@ class <%= class_name %>
80
77
  commit_buffer
81
78
  <%- end -%>
82
79
  @thunk.clear
83
- refill_buffer(1) >= 1 && pos != @pos
80
+ refill_buffer(1) >= 1 && pos != @buffer_start_position
84
81
  end
85
82
 
86
83
  def run
@@ -95,22 +92,22 @@ class <%= class_name %>
95
92
  <%= ref.var %> = (__pcc_in.value_refs[<%= ref.index %>] ||= Value.new).value
96
93
  <%- end -%>
97
94
  __0 = __pcc_in.capt0.capture_string(@buffer)
98
- __0s = @pos + __pcc_in.capt0.range_start
99
- __0e = @pos + __pcc_in.capt0.range_end
95
+ __0s = @buffer_start_position + __pcc_in.capt0.range_start
96
+ __0e = @buffer_start_position + __pcc_in.capt0.range_end
100
97
  <%- if @location -%>
101
- __0sl = @pos_loc + __pcc_in.capt0.start_loc
102
- __0el = @pos_loc + __pcc_in.capt0.end_loc
98
+ __0sl = @buffer_start_position_loc + __pcc_in.capt0.start_loc
99
+ __0el = @buffer_start_position_loc + __pcc_in.capt0.end_loc
103
100
  <%- end -%>
104
101
  <%- if @capture_in_code -%>
105
102
  __0c = __pcc_in.capt0
106
103
  <%- end -%>
107
104
  <%- code.capts.each do |capture| -%>
108
105
  __<%= capture.index + 1 %> = __pcc_in.capts[<%= capture.index %>].capture_string(@buffer)
109
- __<%= capture.index + 1 %>s = @pos + __pcc_in.capts[<%= capture.index %>].range_start
110
- __<%= capture.index + 1 %>e = @pos + __pcc_in.capts[<%= capture.index %>].range_end
106
+ __<%= capture.index + 1 %>s = @buffer_start_position + __pcc_in.capts[<%= capture.index %>].range_start
107
+ __<%= capture.index + 1 %>e = @buffer_start_position + __pcc_in.capts[<%= capture.index %>].range_end
111
108
  <%- if @location -%>
112
- __<%= capture.index + 1 %>sl = @pos_loc + __pcc_in.capts[<%= capture.index %>].start_loc
113
- __<%= capture.index + 1 %>el = @pos_loc + __pcc_in.capts[<%= capture.index %>].end_loc
109
+ __<%= capture.index + 1 %>sl = @buffer_start_position_loc + __pcc_in.capts[<%= capture.index %>].start_loc
110
+ __<%= capture.index + 1 %>el = @buffer_start_position_loc + __pcc_in.capts[<%= capture.index %>].end_loc
114
111
  <%- end -%>
115
112
  <%- if @capture_in_code -%>
116
113
  __<%= capture.index + 1 %>c = __pcc_in.capts[<%= capture.index %>]
@@ -124,118 +121,79 @@ class <%= class_name %>
124
121
  <%- end -%>
125
122
  <%- end -%>
126
123
  <%- @root.rules.each do |rule| -%>
127
- def evaluate_rule_<%= rule.name %>
128
- answer = ThunkChunk.new
129
- answer.pos = @cur
130
- <%- if @location -%>
131
- answer.pos_loc = @cur_loc
132
- <%- end -%>
133
- <%- gen = ::Packcr::Generator.new(rule, @ascii, @location, :rb) -%>
134
- <%- -%><%= gen.generate_code(rule, 0, 4, false) -%>
135
- end
124
+ <%- gen = ::Packcr::Generator.new(rule, @ascii, @location, :rb) -%>
125
+ <%- -%><%= gen.generate_code(rule, 0, 2, false) -%>
136
126
 
137
127
  <%- end -%>
138
- def setup_lr(rule, lr)
139
- lr.head ||= LrHead.new(rule)
140
- @lrstack.reverse_each do |lrentry|
141
- if lrentry.head == lr.head
142
- break
143
- end
144
- lrentry.head = lr.head
145
- lr.head.involved_set[lrentry.rule] = true
146
- end
147
- end
148
-
149
- def grow_lr(rule, memo, head, pos<% if @location %>, p_loc<% end %>)
150
- @heads[pos] = head
128
+ def grow_lr(rule, offset<% if @location %>, offset_loc<% end %>)
151
129
  while true
152
- @cur = pos - @pos
130
+ old_offset = @position_offset
131
+ @position_offset = offset
153
132
  <%- if @location -%>
154
- @cur_loc = p_loc - @pos_loc
133
+ @position_offset_loc = offset_loc
155
134
  <%- end -%>
156
- head.involved_set_to_eval_set
157
- answer = public_send(rule)
158
- if !answer || @pos + @cur <= memo.pos
135
+ answer = public_send(rule, offset<% if @location %>, offset_loc<% end %>, limits: {rule => true})
136
+ if !answer || @position_offset <= old_offset
159
137
  break
160
138
  end
139
+ memo = @memos[offset, rule]
161
140
  memo.answer = answer
162
- memo.pos = @pos + @cur
141
+ memo.offset = @position_offset
163
142
  <%- if @location -%>
164
- memo.pos_loc = @pos_loc + @cur_loc
143
+ memo.offset_loc = @position_offset_loc
165
144
  <%- end -%>
166
145
  end
167
- @heads[pos] = nil
168
- @cur = memo.pos - @pos
169
- <%- if @location -%>
170
- @cur_loc = memo.pos_loc - @pos_loc
171
- <%- end -%>
172
- memo.answer
173
- end
174
-
175
- def lr_answer(rule, memo, pos<% if @location %>, p_loc<% end %>)
176
- head = memo.lr.head
177
- if head.rule_name != rule
178
- return memo.lr.seed
179
- end
180
-
181
- memo.answer = memo.lr.seed
182
- if !memo.answer
183
- return nil
184
- end
185
- grow_lr(rule, memo, head, pos<% if @location %>, p_loc<% end %>)
186
146
  end
187
147
 
188
148
  def rule_answer(rule)
189
- pos = @pos + @cur
149
+ offset = @position_offset
190
150
  <%- if @location -%>
191
- p_loc = @pos_loc + @cur_loc
151
+ offset_loc = @position_offset_loc
192
152
  <%- end -%>
193
- memo = @memos[pos, rule]
194
- head = @heads[pos]
195
-
196
- if head
197
- if !memo && rule != head.rule_name && !head.involved_set[rule]
198
- return nil
199
- end
200
- if head.eval_set.delete(rule)
201
- return public_send(rule)
202
- end
203
- end
153
+ memo = @memos[offset, rule]
204
154
 
205
- if memo
206
- @cur = memo.pos - @pos
155
+ if !memo
156
+ memo = LrMemo.new(offset<% if @location %>, offset_loc<% end %>)
157
+ @memos[offset, rule] = memo
158
+ answer = public_send(rule, offset<% if @location %>, offset_loc<% end %>)
159
+ memo.answer = answer
160
+ memo.offset = @position_offset
207
161
  <%- if @location -%>
208
- @cur_loc = memo.pos_loc - @pos_loc
162
+ memo.offset_loc = @position_offset_loc
209
163
  <%- end -%>
210
- if !memo.lr
211
- return memo.answer
164
+ if memo.grow
165
+ grow_lr(rule, offset<% if @location %>, offset_loc<% end %>)
166
+ memo.grow = false
167
+ answer = memo.answer
168
+ @position_offset = memo.offset
212
169
  end
213
- setup_lr(rule, memo.lr)
214
- return memo.lr.seed
215
- end
216
-
217
- lr = LrEntry.new
218
- lr.rule = rule
219
- @lrstack.push(lr)
220
- memo = LrMemo.new(lr, pos<% if @location %>, p_loc<% end %>)
221
- @memos[pos, rule] = memo
222
- answer = public_send(rule)
223
- @lrstack.pop
224
- memo.pos = @pos + @cur
225
- <%- if @location -%>
226
- memo.pos_loc = @pos_loc + @cur_loc
227
- <%- end -%>
228
- if !lr.head
229
- memo.answer = answer
230
170
  return answer
171
+ elsif memo.fail
172
+ memo.answer = nil
173
+ memo.grow = true
174
+ return nil
175
+ else
176
+ @position_offset = memo.offset
177
+ return memo.answer
231
178
  end
232
-
233
- lr.seed = answer
234
- lr_answer(rule, memo, pos<% if @location %>, p_loc<% end %>)
235
179
  end
236
180
 
237
- def apply_rule(rule, thunks, values, index)
238
- answer = rule_answer(rule)
181
+ def apply_rule(rule, thunks, values, index, offset<% if @location %>, offset_loc<% end %>, limits: nil)
182
+ if limits
183
+ limits = limits.merge(rule => true)
184
+ answer = public_send(rule, offset<% if @location %>, offset_loc<% end %>, limits: limits)
185
+ memo = @memos[offset, rule]
186
+ if !answer || @position_offset <= memo.offset
187
+ answer = memo.answer
188
+ @position_offset = memo.offset
189
+ else
190
+ memo.answer = answer
191
+ memo.offset = @position_offset
192
+ end
193
+ else
194
+ answer = rule_answer(rule)
195
+ end
196
+
239
197
  if !answer
240
198
  return false
241
199
  end
@@ -273,20 +231,24 @@ class <%= class_name %>
273
231
  end
274
232
  end
275
233
 
276
- class LrHead
277
- attr_accessor :rule_name, :involved_set, :eval_set
234
+ class LrMemo
235
+ attr_accessor :grow, :answer, :offset, :fail
236
+ <%- if @location -%>
237
+ attr_accessor :offset_loc
238
+ <%- end -%>
278
239
 
279
- def initialize(rule_name)
280
- @rule_name = rule_name
281
- @involved_set = {}
282
- @eval_set = {}
240
+ def initialize(offset<% if @location %>, offset_loc<% end %>)
241
+ @offset = offset
242
+ <%- if @location -%>
243
+ @offset_loc = offset_loc
244
+ <%- end -%>
245
+ @fail = true
246
+ @grow = false
283
247
  end
284
248
 
285
- def involved_set_to_eval_set
286
- @eval_set.clear
287
- @involved_set.each do |k, v|
288
- @eval_set[k] = true
289
- end
249
+ def answer=(answer)
250
+ @fail = nil
251
+ @answer = answer
290
252
  end
291
253
  end
292
254
 
@@ -311,10 +273,7 @@ class <%= class_name %>
311
273
  end
312
274
  end
313
275
 
314
- class Thunk
315
- end
316
-
317
- class ThunkLeaf < Thunk
276
+ class ThunkLeaf
318
277
  attr_accessor :capt0, :capts, :value_refs, :action
319
278
 
320
279
  def initialize(action, capt0 = Capture.new, value_refs = {}, capts = {})
@@ -329,7 +288,7 @@ class <%= class_name %>
329
288
  end
330
289
  end
331
290
 
332
- class ThunkNode < Thunk
291
+ class ThunkNode
333
292
  attr_accessor :thunks, :values, :index
334
293
 
335
294
  def initialize(thunks, values, index)
@@ -350,10 +309,6 @@ class <%= class_name %>
350
309
  end
351
310
  end
352
311
 
353
- class LrEntry
354
- attr_accessor :rule, :head, :seed
355
- end
356
-
357
312
  class Capture
358
313
  attr_accessor :range_start, :range_end
359
314
  <%- if @location -%>
@@ -370,27 +325,7 @@ class <%= class_name %>
370
325
  end
371
326
 
372
327
  def capture_string(buffer)
373
- @string ||= buffer[@range_start, @range_end - @range_start]
374
- end
375
- end
376
-
377
- class LrMemo
378
- attr_accessor :lr, :answer, :pos
379
- <%- if @location -%>
380
- attr_accessor :pos_loc
381
- <%- end -%>
382
-
383
- def initialize(lr, pos<% if @location %>, pos_loc<% end %>)
384
- @pos = pos
385
- <%- if @location -%>
386
- @pos_loc = pos_loc
387
- <%- end -%>
388
- @lr = lr
389
- end
390
-
391
- def answer=(answer)
392
- @lr = nil
393
- @answer = answer
328
+ @capture_string ||= buffer[@range_start, @range_end - @range_start]
394
329
  end
395
330
  end
396
331
 
@@ -7,10 +7,10 @@
7
7
  thunk->data.leaf.capts.buf[<%= capt.index %>] = &(chunk->capts.buf[<%= capt.index %>]);
8
8
  <%- end -%>
9
9
  thunk->data.leaf.capt0.range.start = chunk->pos;
10
- thunk->data.leaf.capt0.range.end = ctx->cur;
10
+ thunk->data.leaf.capt0.range.end = ctx->position_offset;
11
11
  <%- if gen.location -%>
12
- thunk->data.leaf.capt0.range.start_loc_ptr = &chunk->pos_loc;
13
- thunk->data.leaf.capt0.range.end_loc_ptr = &ctx->cur_loc;
12
+ thunk->data.leaf.capt0.range.start_loc = chunk->pos_loc;
13
+ thunk->data.leaf.capt0.range.end_loc = ctx->position_offset_loc;
14
14
  <%- end -%>
15
15
  pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
16
16
  }
@@ -2,9 +2,9 @@ answer.thunks.push(
2
2
  ThunkLeaf.new(
3
3
  :action_<%= gen.rule.name %>_<%= index %>,
4
4
  Capture.new(
5
- answer.pos, @cur,
5
+ answer.pos, @position_offset,
6
6
  <%- if gen.location -%>
7
- answer.pos_loc, @cur_loc,
7
+ answer.pos_loc, @position_offset_loc,
8
8
  <%- end -%>
9
9
  ),
10
10
  <%- if vars.empty? -%>
@@ -1,8 +1,8 @@
1
1
  <%- m = gen.next_label -%>
2
2
  {
3
- const size_t p = ctx->cur;
3
+ const size_t p = ctx->position_offset;
4
4
  <%- if gen.location -%>
5
- const pcc_location_t p_loc = ctx->cur_loc;
5
+ const pcc_location_t p_loc = ctx->position_offset_loc;
6
6
  <%- end -%>
7
7
  const size_t n = chunk->thunks.len;
8
8
  <%- nodes.each_with_index do |expr, i| -%>
@@ -17,18 +17,18 @@
17
17
  <%- break -%>
18
18
  <%- else -%>
19
19
  <%- if r == Packcr::CODE_REACH__BOTH -%>
20
- goto L<%= "%04d" % m %>;
20
+ goto L<%= format("%04d", m) %>;
21
21
  <%- end -%>
22
22
  <%- end -%>
23
- L<%= "%04d" % l %>:;
24
- ctx->cur = p;
23
+ L<%= format("%04d", l) %>:;
24
+ ctx->position_offset = p;
25
25
  <%- if gen.location -%>
26
- ctx->cur_loc = p_loc;
26
+ ctx->position_offset_loc = p_loc;
27
27
  <%- end -%>
28
28
  pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
29
29
  <%- if !c -%>
30
- goto L<%= "%04d" % onfail %>;
30
+ goto L<%= format("%04d", onfail) %>;
31
31
  <%- end -%>
32
32
  <%- end -%>
33
- L<%= "%04d" % m %>:;
33
+ L<%= format("%04d", m) %>:;
34
34
  }
@@ -1,14 +1,13 @@
1
1
  <%- m = gen.next_label -%>
2
2
  catch(<%= m %>) do
3
- pos<%= gen.level %> = @cur
3
+ pos<%= gen.level %> = @position_offset
4
4
  <%- if gen.location -%>
5
- p_loc<%= gen.level %> = @cur_loc
5
+ p_loc<%= gen.level %> = @position_offset_loc
6
6
  <%- end -%>
7
7
  n<%= gen.level %> = answer.thunks.length
8
8
  <%- nodes.each_with_index do |expr, i| -%>
9
9
  <%- c = i + 1 < nodes.length -%>
10
10
  <%- if expr.reversible?(gen) -%>
11
- <%- r = expr.reachability -%>
12
11
  <%- %><%= gen.generate_code(expr, m, 2, false, reverse: true, oncut: onfail) -%>
13
12
  <%- else -%>
14
13
  <%- l = gen.next_label -%>
@@ -28,9 +27,9 @@ catch(<%= m %>) do
28
27
  <%- end -%>
29
28
  end
30
29
  <%- end -%>
31
- @cur = pos<%= gen.level %>
30
+ @position_offset = pos<%= gen.level %>
32
31
  <%- if gen.location -%>
33
- @cur_loc = p_loc<%= gen.level %>
32
+ @position_offset_loc = p_loc<%= gen.level %>
34
33
  <%- end -%>
35
34
  answer.thunks[n<%= gen.level %>..-1] = []
36
35
  <%- if !c -%>
@@ -1,17 +1,17 @@
1
1
  {
2
- const size_t p = ctx->cur;
2
+ const size_t p = ctx->position_offset;
3
3
  size_t q;
4
4
  <%- if gen.location -%>
5
- pcc_location_t p_loc = ctx->cur_loc;
5
+ pcc_location_t p_loc = ctx->position_offset_loc;
6
6
  pcc_location_t q_loc;
7
7
  <%- end -%>
8
8
  <%= gen.generate_code(expr, onfail, 4, false) -%>
9
- q = ctx->cur;
9
+ q = ctx->position_offset;
10
10
  chunk->capts.buf[<%= index %>].range.start = p;
11
11
  chunk->capts.buf[<%= index %>].range.end = q;
12
12
  <%- if gen.location -%>
13
- q_loc = ctx->cur_loc;
14
- *chunk->capts.buf[<%= index %>].range.start_loc_ptr = p_loc;
15
- *chunk->capts.buf[<%= index %>].range.end_loc_ptr = q_loc;
13
+ q_loc = ctx->position_offset_loc;
14
+ chunk->capts.buf[<%= index %>].range.start_loc = p_loc;
15
+ chunk->capts.buf[<%= index %>].range.end_loc = q_loc;
16
16
  <%- end -%>
17
17
  }
@@ -1,14 +1,14 @@
1
- pos<%= gen.level %> = @cur
1
+ pos<%= gen.level %> = @position_offset
2
2
  <%- if gen.location -%>
3
- p_loc<%= gen.level %> = @cur_loc
3
+ p_loc<%= gen.level %> = @position_offset_loc
4
4
  <%- end -%>
5
5
  <%- %><%= gen.generate_code(expr, onfail, 0, false) -%>
6
- q<%= gen.level %> = @cur
6
+ q<%= gen.level %> = @position_offset
7
7
  capt<%= gen.level %> = answer.capts[<%= index %>]
8
8
  capt<%= gen.level %>.range_start = pos<%= gen.level %>
9
9
  capt<%= gen.level %>.range_end = q<%= gen.level %>
10
10
  <%- if gen.location -%>
11
- q_loc<%= gen.level %> = @cur_loc
11
+ q_loc<%= gen.level %> = @position_offset_loc
12
12
  capt<%= gen.level %>.start_loc = p_loc<%= gen.level %>
13
13
  capt<%= gen.level %>.end_loc = q_loc<%= gen.level %>
14
14
  <%- end -%>
@@ -1,21 +1,21 @@
1
1
  {
2
2
  <%- if !a && charclass =~ /\A[^\\]-.\z/ -%>
3
3
  char c;
4
- if (pcc_refill_buffer(ctx, 1) < 1) goto L<%= "%04d" % onfail %>;
5
- c = ctx->buffer.buf[ctx->cur];
4
+ if (pcc_refill_buffer(ctx, 1) < 1) goto L<%= format("%04d", onfail) %>;
5
+ c = ctx->buffer.buf[ctx->position_offset];
6
6
  <%- if a -%>
7
- if (c >= '<%= Packcr.escape_character(charclass[0]) %>' && c <= '<%= Packcr.escape_character(charclass[2]) %>') goto L<%= "%04d" % onfail %>;
7
+ if (c >= '<%= Packcr.escape_character(charclass[0]) %>' && c <= '<%= Packcr.escape_character(charclass[2]) %>') goto L<%= format("%04d", onfail) %>;
8
8
  <%- else -%>
9
- if (!(c >= '<%= Packcr.escape_character(charclass[0]) %>' && c <= '<%= Packcr.escape_character(charclass[2]) %>')) goto L<%= "%04d" % onfail %>;
9
+ if (!(c >= '<%= Packcr.escape_character(charclass[0]) %>' && c <= '<%= Packcr.escape_character(charclass[2]) %>')) goto L<%= format("%04d", onfail) %>;
10
10
  <%- end -%>
11
11
  <%- if gen.location -%>
12
- pcc_location_forward(&ctx->cur_loc, ctx->buffer.buf + ctx->cur, 1);
12
+ pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
13
13
  <%- end -%>
14
- ctx->cur++;
14
+ ctx->position_offset++;
15
15
  <%- else -%>
16
16
  char c;
17
- if (pcc_refill_buffer(ctx, 1) < 1) goto L<%= "%04d" % onfail %>;
18
- c = ctx->buffer.buf[ctx->cur];
17
+ if (pcc_refill_buffer(ctx, 1) < 1) goto L<%= format("%04d", onfail) %>;
18
+ c = ctx->buffer.buf[ctx->position_offset];
19
19
  <%- if a -%>
20
20
  if (
21
21
  <%- else -%>
@@ -35,13 +35,13 @@
35
35
  <%- i += 1 -%>
36
36
  <%- end -%>
37
37
  <%- if a -%>
38
- ) goto L<%= "%04d" % onfail %>;
38
+ ) goto L<%= format("%04d", onfail) %>;
39
39
  <%- else -%>
40
- )) goto L<%= "%04d" % onfail %>;
40
+ )) goto L<%= format("%04d", onfail) %>;
41
41
  <%- end -%>
42
42
  <%- if gen.location -%>
43
- pcc_location_forward(&ctx->cur_loc, ctx->buffer.buf + ctx->cur, 1);
43
+ pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
44
44
  <%- end -%>
45
- ctx->cur++;
45
+ ctx->position_offset++;
46
46
  <%- end -%>
47
47
  }
@@ -2,7 +2,7 @@
2
2
  if refill_buffer(1) < 1
3
3
  throw(<%= onfail %>)
4
4
  end
5
- c<%= gen.level %> = @buffer[@cur]
5
+ c<%= gen.level %> = @buffer[@position_offset]
6
6
  <%- if a -%>
7
7
  if c<%= gen.level %> >= "<%= Packcr.escape_character(charclass[0]) %>" && c<%= gen.level %> <= "<%= Packcr.escape_character(charclass[2]) %>"
8
8
  throw(<%= onfail %>)
@@ -13,14 +13,14 @@ unless c<%= gen.level %> >= "<%= Packcr.escape_character(charclass[0]) %>" && c<
13
13
  end
14
14
  <%- end -%>
15
15
  <%- if gen.location -%>
16
- @cur_loc = @cur_loc.forward(@buffer, @cur, 1)
16
+ @position_offset_loc = @position_offset_loc.forward(@buffer, @position_offset, 1)
17
17
  <%- end -%>
18
- @cur += 1
18
+ @position_offset += 1
19
19
  <%- else -%>
20
20
  if refill_buffer(1) < 1
21
21
  throw(<%= onfail %>)
22
22
  end
23
- c<%= gen.level %> = @buffer[@cur]
23
+ c<%= gen.level %> = @buffer[@position_offset]
24
24
  <%- if a -%>
25
25
  if (
26
26
  <%- else -%>
@@ -43,7 +43,7 @@ unless (
43
43
  throw(<%= onfail %>)
44
44
  end
45
45
  <%- if gen.location -%>
46
- @cur_loc = @cur_loc.forward(@buffer, @cur, 1)
46
+ @position_offset_loc = @position_offset_loc.forward(@buffer, @position_offset, 1)
47
47
  <%- end -%>
48
- @cur += 1
48
+ @position_offset += 1
49
49
  <%- end -%>
@@ -1,5 +1,5 @@
1
- if (pcc_refill_buffer(ctx, 1) < 1) goto L<%= "%04d" % onfail %>;
1
+ if (pcc_refill_buffer(ctx, 1) < 1) goto L<%= format("%04d", onfail) %>;
2
2
  <%- if gen.location -%>
3
- pcc_location_forward(&ctx->cur, ctx->buffer.buf + ctx->cur, 1);
3
+ pcc_location_forward(&ctx->position_offset, ctx->buffer.buf + ctx->position_offset, 1);
4
4
  <%- end -%>
5
- ctx->cur++;
5
+ ctx->position_offset++;
@@ -2,6 +2,6 @@ if refill_buffer(1) < 1
2
2
  throw(<%= onfail %>)
3
3
  end
4
4
  <%- if gen.location -%>
5
- @cur_loc = @cur_loc.forward(@buffer, @cur, 1)
5
+ @position_offset_loc = @position_offset_loc.forward(@buffer, @position_offset, 1)
6
6
  <%- end -%>
7
- @cur += 1
7
+ @position_offset += 1
@@ -1 +1 @@
1
- goto L<%= "%04d" % onfail %>;
1
+ goto L<%= format("%04d", onfail) %>;
@@ -1,19 +1,19 @@
1
1
  <%- if a -%>
2
2
  if (
3
3
  pcc_refill_buffer(ctx, 1) < 1 ||
4
- ctx->buffer.buf[ctx->cur] == '<%= Packcr.escape_character(charclass[i]) %>'
5
- ) goto L<%= "%04d" % onfail %>;
4
+ ctx->buffer.buf[ctx->position_offset] == '<%= Packcr.escape_character(charclass[i]) %>'
5
+ ) goto L<%= format("%04d", onfail) %>;
6
6
  <%- if gen.location -%>
7
- pcc_location_forward(&ctx->cur_loc, ctx->buffer.buf + ctx->cur, 1);
7
+ pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
8
8
  <%- end -%>
9
- ctx->cur++;
9
+ ctx->position_offset++;
10
10
  <%- else -%>
11
11
  if (
12
12
  pcc_refill_buffer(ctx, 1) < 1 ||
13
- ctx->buffer.buf[ctx->cur] != '<%= Packcr.escape_character(charclass[0]) %>'
14
- ) goto L<%= "%04d" % onfail %>;
13
+ ctx->buffer.buf[ctx->position_offset] != '<%= Packcr.escape_character(charclass[0]) %>'
14
+ ) goto L<%= format("%04d", onfail) %>;
15
15
  <%- if gen.location -%>
16
- pcc_location_forward(&ctx->cur_loc, ctx->buffer.buf + ctx->cur, 1);
16
+ pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
17
17
  <%- end -%>
18
- ctx->cur++;
18
+ ctx->position_offset++;
19
19
  <%- end -%>