packcr 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -0
  3. data/README.md +73 -0
  4. data/lib/packcr/context.rb +1 -1
  5. data/lib/packcr/generated/context.rb +121 -78
  6. data/lib/packcr/generated/node/action_node.rb +2 -2
  7. data/lib/packcr/generated/node/alternate_node.rb +2 -2
  8. data/lib/packcr/generated/node/capture_node.rb +1 -1
  9. data/lib/packcr/generated/node/charclass_node.rb +9 -9
  10. data/lib/packcr/generated/node/eof_node.rb +1 -1
  11. data/lib/packcr/generated/node/error_node.rb +2 -2
  12. data/lib/packcr/generated/node/expand_node.rb +2 -2
  13. data/lib/packcr/generated/node/predicate_node.rb +2 -2
  14. data/lib/packcr/generated/node/quantity_node.rb +30 -31
  15. data/lib/packcr/generated/node/reference_node.rb +2 -2
  16. data/lib/packcr/generated/node/rule_node.rb +7 -7
  17. data/lib/packcr/generated/node/string_node.rb +4 -4
  18. data/lib/packcr/parser.rb +619 -613
  19. data/lib/packcr/templates/context/header.c.erb +3 -3
  20. data/lib/packcr/templates/context/source.c.erb +417 -403
  21. data/lib/packcr/templates/context/source.rb.erb +42 -25
  22. data/lib/packcr/templates/node/action.c.erb +2 -2
  23. data/lib/packcr/templates/node/alternate.c.erb +2 -2
  24. data/lib/packcr/templates/node/capture.c.erb +2 -2
  25. data/lib/packcr/templates/node/charclass.c.erb +4 -4
  26. data/lib/packcr/templates/node/charclass_any.c.erb +2 -2
  27. data/lib/packcr/templates/node/charclass_one.c.erb +4 -4
  28. data/lib/packcr/templates/node/charclass_utf8.c.erb +2 -2
  29. data/lib/packcr/templates/node/eof.c.erb +1 -1
  30. data/lib/packcr/templates/node/error.c.erb +4 -4
  31. data/lib/packcr/templates/node/expand.c.erb +2 -2
  32. data/lib/packcr/templates/node/predicate.c.erb +1 -1
  33. data/lib/packcr/templates/node/predicate_neg.c.erb +1 -1
  34. data/lib/packcr/templates/node/quantity_many.c.erb +9 -7
  35. data/lib/packcr/templates/node/quantity_one.c.erb +9 -7
  36. data/lib/packcr/templates/node/quantity_one.rb.erb +4 -4
  37. data/lib/packcr/templates/node/reference.c.erb +6 -6
  38. data/lib/packcr/templates/node/rule.c.erb +9 -9
  39. data/lib/packcr/templates/node/string_many.c.erb +2 -2
  40. data/lib/packcr/templates/node/string_one.c.erb +2 -2
  41. data/lib/packcr/util.rb +1 -1
  42. data/lib/packcr/version.rb +1 -1
  43. metadata +5 -3
@@ -1,12 +1,19 @@
1
1
  # A packrat parser generated by PackCR <%= Packcr::VERSION %>
2
- <%- if !code(:source).empty? -%>
2
+ <%- if !code(:esource).empty? -%>
3
3
 
4
- <%- code(:source).each do |code| -%>
4
+ <%- code(:esource).each do |code| -%>
5
5
  <%= stream.get_code_block(code, 0, @iname) -%>
6
6
  <%- end -%>
7
7
  <%- end -%>
8
-
9
8
  class <%= class_name %>
9
+ <%- code(:location).each do |code| -%>
10
+ <%- %><%= stream.get_code_block(code, 2, @iname) -%>
11
+
12
+ <%- end -%>
13
+ <%- code(:source).each do |code| -%>
14
+ <%= stream.get_code_block(code, 2, @iname) -%>
15
+
16
+ <%- end -%>
10
17
  def initialize(<% if @auxil_type %><%= auxil_type %>, <% end %>debug: false)
11
18
  <%- if @utf8 -%>
12
19
  @buffer = +""
@@ -86,36 +93,36 @@ class <%= class_name %>
86
93
 
87
94
  <%- @root.rules.each do |rule| -%>
88
95
  <%- rule.codes.each do |code| -%>
89
- def action_<%= rule.name %>_<%= code.index %>(__pcc_in, __pcc_vars, __pcc_index)
90
- ____ = (__pcc_vars[__pcc_index] ||= Value.new).value if __pcc_vars
96
+ def action_<%= rule.name %>_<%= code.index %>(__packcr_in, __packcr_vars, __packcr_index)
97
+ ____ = (__packcr_vars[__packcr_index] ||= Value.new).value if __packcr_vars
91
98
  <%- code.vars.each do |ref| -%>
92
- <%= ref.var %> = (__pcc_in.value_refs[<%= ref.index %>] ||= Value.new).value
99
+ <%= ref.var %> = (__packcr_in.value_refs[<%= ref.index %>] ||= Value.new).value
93
100
  <%- end -%>
94
- __0 = __pcc_in.capt0.capture_string(@buffer)
95
- __0s = @buffer_start_position + __pcc_in.capt0.range_start
96
- __0e = @buffer_start_position + __pcc_in.capt0.range_end
101
+ __0 = __packcr_in.capt0.capture_string(@buffer)
102
+ __0s = @buffer_start_position + __packcr_in.capt0.range_start
103
+ __0e = @buffer_start_position + __packcr_in.capt0.range_end
97
104
  <%- if @location -%>
98
- __0sl = @buffer_start_position_loc + __pcc_in.capt0.start_loc
99
- __0el = @buffer_start_position_loc + __pcc_in.capt0.end_loc
105
+ __0sl = @buffer_start_position_loc + __packcr_in.capt0.start_loc
106
+ __0el = @buffer_start_position_loc + __packcr_in.capt0.end_loc
100
107
  <%- end -%>
101
108
  <%- if @capture_in_code -%>
102
- __0c = __pcc_in.capt0
109
+ __0c = __packcr_in.capt0
103
110
  <%- end -%>
104
111
  <%- code.capts.each do |capture| -%>
105
- __<%= capture.index + 1 %> = __pcc_in.capts[<%= capture.index %>].capture_string(@buffer)
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
112
+ __<%= capture.index + 1 %> = __packcr_in.capts[<%= capture.index %>].capture_string(@buffer)
113
+ __<%= capture.index + 1 %>s = @buffer_start_position + __packcr_in.capts[<%= capture.index %>].range_start
114
+ __<%= capture.index + 1 %>e = @buffer_start_position + __packcr_in.capts[<%= capture.index %>].range_end
108
115
  <%- if @location -%>
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
116
+ __<%= capture.index + 1 %>sl = @buffer_start_position_loc + __packcr_in.capts[<%= capture.index %>].start_loc
117
+ __<%= capture.index + 1 %>el = @buffer_start_position_loc + __packcr_in.capts[<%= capture.index %>].end_loc
111
118
  <%- end -%>
112
119
  <%- if @capture_in_code -%>
113
- __<%= capture.index + 1 %>c = __pcc_in.capts[<%= capture.index %>]
120
+ __<%= capture.index + 1 %>c = __packcr_in.capts[<%= capture.index %>]
114
121
  <%- end -%>
115
122
  <%- end -%>
116
123
  <%- %><%= stream.get_code_block(code.code, 4, @iname) -%>
117
124
 
118
- __pcc_vars[__pcc_index].value = ____ if __pcc_vars
125
+ __packcr_vars[__packcr_index].value = ____ if __packcr_vars
119
126
  end
120
127
 
121
128
  <%- end -%>
@@ -166,6 +173,9 @@ class <%= class_name %>
166
173
  memo.grow = false
167
174
  answer = memo.answer
168
175
  @position_offset = memo.offset
176
+ <%- if @location -%>
177
+ @position_offset_loc = memo.offset_loc
178
+ <%- end -%>
169
179
  end
170
180
  return answer
171
181
  elsif memo.fail
@@ -174,6 +184,9 @@ class <%= class_name %>
174
184
  return nil
175
185
  else
176
186
  @position_offset = memo.offset
187
+ <%- if @location -%>
188
+ @position_offset_loc = memo.offset_loc
189
+ <%- end -%>
177
190
  return memo.answer
178
191
  end
179
192
  end
@@ -184,11 +197,19 @@ class <%= class_name %>
184
197
  answer = public_send(rule, offset<% if @location %>, offset_loc<% end %>, limits: limits)
185
198
  memo = @memos[offset, rule]
186
199
  if !answer || @position_offset <= memo.offset
187
- answer = memo.answer
188
- @position_offset = memo.offset
200
+ if memo
201
+ answer = memo.answer
202
+ @position_offset = memo.offset
203
+ <%- if @location -%>
204
+ @position_offset_loc = memo.offset_loc
205
+ <%- end -%>
206
+ end
189
207
  else
190
208
  memo.answer = answer
191
209
  memo.offset = @position_offset
210
+ <%- if @location -%>
211
+ memo.offset_loc = @position_offset_loc
212
+ <%- end -%>
192
213
  end
193
214
  else
194
215
  answer = rule_answer(rule)
@@ -208,10 +229,6 @@ class <%= class_name %>
208
229
  end
209
230
  end
210
231
 
211
- <%- code(:location).each do |code| -%>
212
- <%- %><%= stream.get_code_block(code, 2, @iname) -%>
213
-
214
- <%- end -%>
215
232
  class LrMemoTable
216
233
  def initialize
217
234
  @memos = {}
@@ -1,5 +1,5 @@
1
1
  {
2
- pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_<%= gen.rule.name %>_<%= index %>, <%= gen.rule.vars.length %>, <%= gen.rule.capts.length %>);
2
+ packcr_thunk_t *const thunk = packcr_thunk__create_leaf(ctx->auxil, packcr_action_<%= gen.rule.name %>_<%= index %>, <%= gen.rule.vars.length %>, <%= gen.rule.capts.length %>);
3
3
  <%- vars.each do |var| -%>
4
4
  thunk->data.leaf.values.buf[<%= var.index %>] = &(chunk->values.buf[<%= var.index %>]);
5
5
  <%- end -%>
@@ -12,5 +12,5 @@
12
12
  thunk->data.leaf.capt0.range.start_loc = chunk->pos_loc;
13
13
  thunk->data.leaf.capt0.range.end_loc = ctx->position_offset_loc;
14
14
  <%- end -%>
15
- pcc_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
15
+ packcr_thunk_array__add(ctx->auxil, &chunk->thunks, thunk);
16
16
  }
@@ -2,7 +2,7 @@
2
2
  {
3
3
  const size_t p = ctx->position_offset;
4
4
  <%- if gen.location -%>
5
- const pcc_location_t p_loc = ctx->position_offset_loc;
5
+ const packcr_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| -%>
@@ -25,7 +25,7 @@ L<%= format("%04d", l) %>:;
25
25
  <%- if gen.location -%>
26
26
  ctx->position_offset_loc = p_loc;
27
27
  <%- end -%>
28
- pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
28
+ packcr_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
29
29
  <%- if !c -%>
30
30
  goto L<%= format("%04d", onfail) %>;
31
31
  <%- end -%>
@@ -2,8 +2,8 @@
2
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->position_offset_loc;
6
- pcc_location_t q_loc;
5
+ packcr_location_t p_loc = ctx->position_offset_loc;
6
+ packcr_location_t q_loc;
7
7
  <%- end -%>
8
8
  <%= gen.generate_code(expr, onfail, 4, false) -%>
9
9
  q = ctx->position_offset;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  <%- if !a && charclass =~ /\A[^\\]-.\z/ -%>
3
3
  char c;
4
- if (pcc_refill_buffer(ctx, 1) < 1) goto L<%= format("%04d", onfail) %>;
4
+ if (packcr_refill_buffer(ctx, 1) < 1) goto L<%= format("%04d", onfail) %>;
5
5
  c = ctx->buffer.buf[ctx->position_offset];
6
6
  <%- if a -%>
7
7
  if (c >= '<%= Packcr.escape_character(charclass[0]) %>' && c <= '<%= Packcr.escape_character(charclass[2]) %>') goto L<%= format("%04d", onfail) %>;
@@ -9,12 +9,12 @@
9
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->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
12
+ packcr_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
13
13
  <%- end -%>
14
14
  ctx->position_offset++;
15
15
  <%- else -%>
16
16
  char c;
17
- if (pcc_refill_buffer(ctx, 1) < 1) goto L<%= format("%04d", onfail) %>;
17
+ if (packcr_refill_buffer(ctx, 1) < 1) goto L<%= format("%04d", onfail) %>;
18
18
  c = ctx->buffer.buf[ctx->position_offset];
19
19
  <%- if a -%>
20
20
  if (
@@ -40,7 +40,7 @@
40
40
  )) goto L<%= format("%04d", onfail) %>;
41
41
  <%- end -%>
42
42
  <%- if gen.location -%>
43
- pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
43
+ packcr_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
44
44
  <%- end -%>
45
45
  ctx->position_offset++;
46
46
  <%- end -%>
@@ -1,5 +1,5 @@
1
- if (pcc_refill_buffer(ctx, 1) < 1) goto L<%= format("%04d", onfail) %>;
1
+ if (packcr_refill_buffer(ctx, 1) < 1) goto L<%= format("%04d", onfail) %>;
2
2
  <%- if gen.location -%>
3
- pcc_location_forward(&ctx->position_offset, ctx->buffer.buf + ctx->position_offset, 1);
3
+ packcr_location_forward(&ctx->position_offset, ctx->buffer.buf + ctx->position_offset, 1);
4
4
  <%- end -%>
5
5
  ctx->position_offset++;
@@ -1,19 +1,19 @@
1
1
  <%- if a -%>
2
2
  if (
3
- pcc_refill_buffer(ctx, 1) < 1 ||
3
+ packcr_refill_buffer(ctx, 1) < 1 ||
4
4
  ctx->buffer.buf[ctx->position_offset] == '<%= Packcr.escape_character(charclass[i]) %>'
5
5
  ) goto L<%= format("%04d", onfail) %>;
6
6
  <%- if gen.location -%>
7
- pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
7
+ packcr_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
8
8
  <%- end -%>
9
9
  ctx->position_offset++;
10
10
  <%- else -%>
11
11
  if (
12
- pcc_refill_buffer(ctx, 1) < 1 ||
12
+ packcr_refill_buffer(ctx, 1) < 1 ||
13
13
  ctx->buffer.buf[ctx->position_offset] != '<%= Packcr.escape_character(charclass[0]) %>'
14
14
  ) goto L<%= format("%04d", onfail) %>;
15
15
  <%- if gen.location -%>
16
- pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
16
+ packcr_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
17
17
  <%- end -%>
18
18
  ctx->position_offset++;
19
19
  <%- end -%>
@@ -2,7 +2,7 @@
2
2
  <%- i = a ? 1 : 0 -%>
3
3
  {
4
4
  int u;
5
- const size_t n = pcc_get_char_as_utf32(ctx, &u);
5
+ const size_t n = packcr_get_char_as_utf32(ctx, &u);
6
6
  if (n == 0) goto L<%= format("%04d", onfail) %>;
7
7
  <%- if charclass && !(a && n == 1) # not '.' or '[^]' -%>
8
8
  <%- u0 = 0 -%>
@@ -43,7 +43,7 @@
43
43
  <%- end -%>
44
44
  <%- end -%>
45
45
  <%- if gen.location -%>
46
- pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, n);
46
+ packcr_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, n);
47
47
  <%- end -%>
48
48
  ctx->position_offset += n;
49
49
  }
@@ -1 +1 @@
1
- if (pcc_refill_buffer(ctx, 1) >= 1) goto L<%= format("%04d", onfail) %>;
1
+ if (packcr_refill_buffer(ctx, 1) >= 1) goto L<%= format("%04d", onfail) %>;
@@ -5,8 +5,8 @@
5
5
  goto L<%= format("%04d", m) %>;
6
6
  L<%= format("%04d", l) %>:;
7
7
  {
8
- pcc_value_t null;
9
- pcc_thunk_t *const thunk = pcc_thunk__create_leaf(ctx->auxil, pcc_action_<%= gen.rule.name %>_<%= index %>, <%= gen.rule.vars.length %>, <%= gen.rule.capts.length %>);
8
+ packcr_value_t null;
9
+ packcr_thunk_t *const thunk = packcr_thunk__create_leaf(ctx->auxil, packcr_action_<%= gen.rule.name %>_<%= index %>, <%= gen.rule.vars.length %>, <%= gen.rule.capts.length %>);
10
10
  <%- vars.each do |var| -%>
11
11
  thunk->data.leaf.values.buf[<%= var.index %>] = &(chunk->values.buf[<%= var.index %>]);
12
12
  <%- end -%>
@@ -19,9 +19,9 @@ L<%= format("%04d", l) %>:;
19
19
  thunk->data.leaf.capt0.range.start_loc = chunk->pos_loc;
20
20
  thunk->data.leaf.capt0.range.end_loc = ctx->position_offset_loc;
21
21
  <%- end -%>
22
- memset(&null, 0, sizeof(pcc_value_t)); /* in case */
22
+ memset(&null, 0, sizeof(packcr_value_t)); /* in case */
23
23
  thunk->data.leaf.action(ctx, thunk, &null);
24
- pcc_thunk__destroy(ctx->auxil, thunk);
24
+ packcr_thunk__destroy(ctx->auxil, thunk);
25
25
  }
26
26
  goto L<%= format("%04d", onfail) %>;
27
27
  L<%= format("%04d", m) %>:;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  const size_t n = chunk->capts.buf[<%= index %>].range.end - chunk->capts.buf[<%= index %>].range.start;
3
- if (pcc_refill_buffer(ctx, n) < n) goto L<%= format("%04d", onfail) %>;
3
+ if (packcr_refill_buffer(ctx, n) < n) goto L<%= format("%04d", onfail) %>;
4
4
  if (n > 0) {
5
5
  const char *const p = ctx->buffer.buf + ctx->position_offset;
6
6
  const char *const q = ctx->buffer.buf + chunk->capts.buf[<%= index %>].range.start;
@@ -9,7 +9,7 @@
9
9
  if (p[i] != q[i]) goto L<%= format("%04d", onfail) %>;
10
10
  }
11
11
  <%- if gen.location -%>
12
- pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, n);
12
+ packcr_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, n);
13
13
  <%- end -%>
14
14
  ctx->position_offset += n;
15
15
  }
@@ -4,7 +4,7 @@
4
4
  {
5
5
  const size_t p = ctx->position_offset;
6
6
  <%- if gen.location -%>
7
- const pcc_location_t p_loc = ctx->position_offset_loc;
7
+ const packcr_location_t p_loc = ctx->position_offset_loc;
8
8
  <%- end -%>
9
9
  <%= gen.generate_code(expr, l, 4, false) -%>
10
10
  <%- if r != Packcr::CODE_REACH__ALWAYS_FAIL -%>
@@ -3,7 +3,7 @@
3
3
  {
4
4
  const size_t p = ctx->position_offset;
5
5
  <%- if gen.location -%>
6
- const pcc_location_t p_loc = ctx->position_offset_loc;
6
+ const packcr_location_t p_loc = ctx->position_offset_loc;
7
7
  <%- end -%>
8
8
  <%= gen.generate_code(expr, l, 4, false) -%>
9
9
  <%- if r != Packcr::CODE_REACH__ALWAYS_FAIL -%>
@@ -1,8 +1,9 @@
1
1
  {
2
+ <%- r = expr.reachability -%>
2
3
  <%- if min > 0 -%>
3
4
  const size_t p0 = ctx->position_offset;
4
5
  <%- if gen.location -%>
5
- const pcc_location_t p0_loc = ctx->position_offset_loc;
6
+ const packcr_location_t p0_loc = ctx->position_offset_loc;
6
7
  <%- end -%>
7
8
  const size_t n0 = chunk->thunks.len;
8
9
  <%- end -%>
@@ -13,12 +14,13 @@
13
14
  for (i = 0; i < <%= max %>; i++) {
14
15
  <%- end -%>
15
16
  const size_t p = ctx->position_offset;
16
- <%- if gen.location -%>
17
- const pcc_location_t p_loc = ctx->position_offset_loc;
18
- <%- end -%>
17
+ <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
18
+ <%- if gen.location -%>
19
+ const packcr_location_t p_loc = ctx->position_offset_loc;
20
+ <%- end -%>
19
21
  const size_t n = chunk->thunks.len;
22
+ <%- end -%>
20
23
  <%- l = gen.next_label -%>
21
- <%- r = expr.reachability -%>
22
24
  <%= gen.generate_code(expr, l, 8, false) -%>
23
25
  if (ctx->position_offset == p) break;
24
26
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
@@ -28,7 +30,7 @@
28
30
  <%- if gen.location -%>
29
31
  ctx->position_offset_loc = p_loc;
30
32
  <%- end -%>
31
- pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
33
+ packcr_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
32
34
  break;
33
35
  <%- end -%>
34
36
  }
@@ -38,7 +40,7 @@
38
40
  <%- if gen.location -%>
39
41
  ctx->position_offset_loc = p0_loc;
40
42
  <%- end -%>
41
- pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
43
+ packcr_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
42
44
  goto L<%= format("%04d", onfail) %>;
43
45
  }
44
46
  <%- end -%>
@@ -1,13 +1,15 @@
1
+ <%- r = expr.reachability -%>
2
+ <%- if r == Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
3
+ <%= gen.generate_code(expr, nil, 0, true) -%>
4
+ <%- else -%>
1
5
  {
2
6
  <%- l = gen.next_label -%>
3
7
  const size_t p = ctx->position_offset;
4
- <%- if gen.location -%>
5
- const pcc_location_t p_loc = ctx->position_offset_loc;
6
- <%- end -%>
8
+ <%- if gen.location -%>
9
+ const packcr_location_t p_loc = ctx->position_offset_loc;
10
+ <%- end -%>
7
11
  const size_t n = chunk->thunks.len;
8
- <%- r = expr.reachability -%>
9
12
  <%= gen.generate_code(expr, l, 4, false) -%>
10
- <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
11
13
  <%- m = gen.next_label -%>
12
14
  goto L<%= format("%04d", m) %>;
13
15
  L<%= format("%04d", l) %>:;
@@ -15,7 +17,7 @@ L<%= format("%04d", l) %>:;
15
17
  ctx->position_offset_loc = p_loc;
16
18
  <%- end -%>
17
19
  ctx->position_offset = p;
18
- pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
20
+ packcr_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
19
21
  L<%= format("%04d", m) %>:;
20
- <%- end -%>
21
22
  }
23
+ <%- end -%>
@@ -1,13 +1,13 @@
1
+ <%- r = expr.reachability -%>
2
+ <%- if r == Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
3
+ <%- %><%= gen.generate_code(expr, nil, 0, true) -%>
4
+ <%- else -%>
1
5
  <%- l = gen.next_label -%>
2
6
  pos<%= gen.level %> = @position_offset
3
7
  <%- if gen.location -%>
4
8
  p_loc<%= gen.level %> = @position_offset_loc
5
9
  <%- end -%>
6
10
  n<%= gen.level %> = answer.thunks.length
7
- <%- r = expr.reachability -%>
8
- <%- if r == Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
9
- <%- %><%= gen.generate_code(expr, l, 0, false) -%>
10
- <%- else -%>
11
11
  <%- m = gen.next_label -%>
12
12
  catch(<%= m %>) do
13
13
  catch(<%= l %>) do
@@ -1,17 +1,17 @@
1
1
  <%- if index != nil -%>
2
2
  {
3
- pcc_rule_set_t *l = NULL;
4
- if (limits && ctx->position_offset == offset && pcc_rule_set__index(ctx->auxil, limits, pcc_evaluate_rule_<%= name %>) == PCC_VOID_VALUE) {
3
+ packcr_rule_set_t *l = NULL;
4
+ if (limits && ctx->position_offset == offset && packcr_rule_set__index(ctx->auxil, limits, packcr_evaluate_rule_<%= name %>) == PACKCR_VOID_VALUE) {
5
5
  l = limits;
6
6
  }
7
- if (!pcc_apply_rule(ctx, pcc_evaluate_rule_<%= name %>, &chunk->thunks, &(chunk->values.buf[<%= index %>]), offset<% if gen.location %>, offset_loc<% end %>, l)) goto L<%= format("%04d", onfail) %>;
7
+ if (!packcr_apply_rule(ctx, packcr_evaluate_rule_<%= name %>, &chunk->thunks, &(chunk->values.buf[<%= index %>]), offset<% if gen.location %>, offset_loc<% end %>, l)) goto L<%= format("%04d", onfail) %>;
8
8
  }
9
9
  <%- else -%>
10
10
  {
11
- pcc_rule_set_t *l = NULL;
12
- if (limits && ctx->position_offset == offset && pcc_rule_set__index(ctx->auxil, limits, pcc_evaluate_rule_<%= name %>) == PCC_VOID_VALUE) {
11
+ packcr_rule_set_t *l = NULL;
12
+ if (limits && ctx->position_offset == offset && packcr_rule_set__index(ctx->auxil, limits, packcr_evaluate_rule_<%= name %>) == PACKCR_VOID_VALUE) {
13
13
  l = limits;
14
14
  }
15
- if (!pcc_apply_rule(ctx, pcc_evaluate_rule_<%= name %>, &chunk->thunks, NULL, offset<% if gen.location %>, offset_loc<% end %>, l)) goto L<%= format("%04d", onfail) %>;
15
+ if (!packcr_apply_rule(ctx, packcr_evaluate_rule_<%= name %>, &chunk->thunks, NULL, offset<% if gen.location %>, offset_loc<% end %>, l)) goto L<%= format("%04d", onfail) %>;
16
16
  }
17
17
  <%- end -%>
@@ -1,26 +1,26 @@
1
- static pcc_thunk_chunk_t *pcc_evaluate_rule_<%= name %>(pcc_context_t *ctx, size_t offset<% if gen.location %>, pcc_location_t offset_loc<% end %>, pcc_rule_set_t *limits) {
2
- pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx);
1
+ static packcr_thunk_chunk_t *packcr_evaluate_rule_<%= name %>(packcr_context_t *ctx, size_t offset<% if gen.location %>, packcr_location_t offset_loc<% end %>, packcr_rule_set_t *limits) {
2
+ packcr_thunk_chunk_t *const chunk = packcr_thunk_chunk__create(ctx);
3
3
  chunk->pos = ctx->position_offset;
4
4
  <%- if gen.location -%>
5
5
  chunk->pos_loc = ctx->position_offset_loc;
6
6
  <%- end -%>
7
- PCC_DEBUG(ctx->auxil, PCC_DBG_EVALUATE, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
7
+ PACKCR_DEBUG(ctx->auxil, PACKCR_DBG_EVALUATE, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
8
8
  ctx->level++;
9
- pcc_value_table__resize(ctx->auxil, &chunk->values, <%= vars.length %>);
10
- pcc_capture_table__resize(ctx->auxil, &chunk->capts, <%= capts.length %>);
9
+ packcr_value_table__resize(ctx->auxil, &chunk->values, <%= vars.length %>);
10
+ packcr_capture_table__resize(ctx->auxil, &chunk->capts, <%= capts.length %>);
11
11
  <%- if vars.length > 0 -%>
12
- pcc_value_table__clear(ctx->auxil, &chunk->values);
12
+ packcr_value_table__clear(ctx->auxil, &chunk->values);
13
13
  <%- end -%>
14
14
  <%- r = expr.reachability -%>
15
15
  <%- -%><%= gen.generate_code(expr, 0, 4, false) -%>
16
16
  ctx->level--;
17
- PCC_DEBUG(ctx->auxil, PCC_DBG_MATCH, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->position_offset - chunk->pos));
17
+ PACKCR_DEBUG(ctx->auxil, PACKCR_DBG_MATCH, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->position_offset - chunk->pos));
18
18
  return chunk;
19
19
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
20
20
  L0000:;
21
21
  ctx->level--;
22
- PCC_DEBUG(ctx->auxil, PCC_DBG_NOMATCH, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->position_offset - chunk->pos));
23
- pcc_thunk_chunk__destroy(ctx, chunk);
22
+ PACKCR_DEBUG(ctx->auxil, PACKCR_DBG_NOMATCH, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->position_offset - chunk->pos));
23
+ packcr_thunk_chunk__destroy(ctx, chunk);
24
24
  return NULL;
25
25
  <%- end -%>
26
26
  }
@@ -1,11 +1,11 @@
1
1
  if (
2
- pcc_refill_buffer(ctx, <%= n %>) < <%= n %> ||
2
+ packcr_refill_buffer(ctx, <%= n %>) < <%= n %> ||
3
3
  <%- (n - 1).times do |i| -%>
4
4
  (ctx->buffer.buf + ctx->position_offset)[<%= i %>] != '<%= Packcr.escape_character(value[i]) %>' ||
5
5
  <%- end -%>
6
6
  (ctx->buffer.buf + ctx->position_offset)[<%= n - 1 %>] != '<%= Packcr.escape_character(value[n - 1]) %>'
7
7
  ) goto L<%= format("%04d", onfail) %>;
8
8
  <%- if gen.location -%>
9
- pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, n);
9
+ packcr_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, <%= n %>);
10
10
  <%- end -%>
11
11
  ctx->position_offset += <%= n %>;
@@ -1,8 +1,8 @@
1
1
  if (
2
- pcc_refill_buffer(ctx, 1) < 1 ||
2
+ packcr_refill_buffer(ctx, 1) < 1 ||
3
3
  ctx->buffer.buf[ctx->position_offset] != '<%= Packcr.escape_character(value[0]) %>'
4
4
  ) goto L<%= format("%04d", onfail) %>;
5
5
  <%- if gen.location -%>
6
- pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
6
+ packcr_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, 1);
7
7
  <%- end -%>
8
8
  ctx->position_offset++;
data/lib/packcr/util.rb CHANGED
@@ -5,8 +5,8 @@ class Packcr
5
5
  def unescape_string(str, is_charclass)
6
6
  if is_charclass
7
7
  str.gsub!("\\" * 2) { "\\" * 4 }
8
- str.gsub!("\"") { "\\\"" }
9
8
  end
9
+ str.gsub!("\"") { "\\\"" }
10
10
  str.gsub!(/\\(.)/) do
11
11
  c = ::Regexp.last_match(1)
12
12
  case c
@@ -1,3 +1,3 @@
1
1
  class Packcr
2
- VERSION = "0.0.7".freeze
2
+ VERSION = "0.0.8".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packcr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - wanabe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-25 00:00:00.000000000 Z
11
+ date: 2023-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -73,6 +73,8 @@ executables:
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - LICENSE
77
+ - README.md
76
78
  - exe/packcr
77
79
  - lib/packcr.rb
78
80
  - lib/packcr/broadcast.rb
@@ -178,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
180
  - !ruby/object:Gem::Version
179
181
  version: '0'
180
182
  requirements: []
181
- rubygems_version: 3.4.1
183
+ rubygems_version: 3.4.6
182
184
  signing_key:
183
185
  specification_version: 4
184
186
  summary: Parser generator for C or Ruby