packcr 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,23 +1,23 @@
1
1
  <%- if a -%>
2
2
  if (
3
3
  refill_buffer(1) < 1 ||
4
- @buffer[@cur] == "<%= Packcr.escape_character(charclass[0]) %>"
4
+ @buffer[@position_offset] == "<%= Packcr.escape_character(charclass[0]) %>"
5
5
  )
6
6
  throw(<%= onfail %>)
7
7
  end
8
8
  <%- if gen.location -%>
9
- @cur_loc = @cur_loc.forward(@buffer, @cur, 1)
9
+ @position_offset_loc = @position_offset_loc.forward(@buffer, @position_offset, 1)
10
10
  <%- end -%>
11
- @cur += 1
11
+ @position_offset += 1
12
12
  <%- else -%>
13
13
  if (
14
14
  refill_buffer(1) < 1 ||
15
- @buffer[@cur] != "<%= Packcr.escape_character(charclass[0]) %>"
15
+ @buffer[@position_offset] != "<%= Packcr.escape_character(charclass[0]) %>"
16
16
  )
17
17
  throw(<%= onfail %>)
18
18
  end
19
19
  <%- if gen.location -%>
20
- @cur_loc = @cur_loc.forward(@buffer, @cur, 1)
20
+ @position_offset_loc = @position_offset_loc.forward(@buffer, @position_offset, 1)
21
21
  <%- end -%>
22
- @cur += 1
22
+ @position_offset += 1
23
23
  <%- end -%>
@@ -3,7 +3,7 @@
3
3
  {
4
4
  int u;
5
5
  const size_t n = pcc_get_char_as_utf32(ctx, &u);
6
- if (n == 0) goto L<%= "%04d" % onfail %>;
6
+ if (n == 0) goto L<%= format("%04d", onfail) %>;
7
7
  <%- if charclass && !(a && n == 1) # not '.' or '[^]' -%>
8
8
  <%- u0 = 0 -%>
9
9
  <%- r = false -%>
@@ -20,12 +20,12 @@
20
20
  <%- i += 1 -%>
21
21
  <%- if r -%>
22
22
  <%- # character range -%>
23
- (u >= 0x<%= "%06x" % u0 %> && u <= 0x<%= "%06x" % u %>)<% if i < n %> ||<% end %>
23
+ (u >= 0x<%= format("%06x", u0) %> && u <= 0x<%= format("%06x", u) %>)<% if i < n %> ||<% end %>
24
24
  <%- u0 = 0 -%>
25
25
  <%- r = false -%>
26
26
  <%- elsif charclass[i] != "-" || i == n - 1 # the individual '-' character is valid when it is at the first or the last position -%>
27
27
  <%- # single character -%>
28
- u == 0x<%= "%06x" % u %><% if i < n %> ||<% end %>
28
+ u == 0x<%= format("%06x", u) %><% if i < n %> ||<% end %>
29
29
  <%- u0 = 0 -%>
30
30
  <%- r = false -%>
31
31
  <%- elsif charclass[i] == "-" -%>
@@ -37,13 +37,13 @@
37
37
  <%- end -%>
38
38
  <%- end -%>
39
39
  <%- if a -%>
40
- ) goto L<%= "%04d" % onfail %>;
40
+ ) goto L<%= format("%04d", onfail) %>;
41
41
  <%- else -%>
42
- )) goto L<%= "%04d" % onfail %>;
42
+ )) goto L<%= format("%04d", onfail) %>;
43
43
  <%- end -%>
44
44
  <%- end -%>
45
45
  <%- if gen.location -%>
46
- pcc_location_forward(&ctx->cur_loc, ctx->buffer.buf + ctx->cur, n);
46
+ pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, n);
47
47
  <%- end -%>
48
- ctx->cur += n;
48
+ ctx->position_offset += n;
49
49
  }
@@ -3,7 +3,7 @@
3
3
  if refill_buffer(1) < 1
4
4
  throw(<%= onfail %>)
5
5
  end
6
- u<%= gen.level %> = @buffer[@cur]
6
+ u<%= gen.level %> = @buffer[@position_offset]
7
7
  <%- if charclass && !(a && n == 1) # not '.' or '[^]' -%>
8
8
  <%- u0 = nil -%>
9
9
  <%- r = false -%>
@@ -45,6 +45,6 @@ if (!(
45
45
  end
46
46
  <%- end -%>
47
47
  <%- if gen.location -%>
48
- @cur_loc = @cur_loc.forward(@buffer, @cur, 1)
48
+ @position_offset_loc = @position_offset_loc.forward(@buffer, @position_offset, 1)
49
49
  <%- end -%>
50
- @cur += 1
50
+ @position_offset += 1
@@ -1,7 +1,7 @@
1
1
  <%- a = charclass && charclass[0] == '^' -%>
2
2
  <%- i = a ? 1 : 0 -%>
3
3
  if refill_buffer(1) >= 1
4
- u<%= gen.level %> = @buffer[@cur]
4
+ u<%= gen.level %> = @buffer[@position_offset]
5
5
  <%- if charclass && !(a && n == 1) # not '.' or '[^]' -%>
6
6
  <%- u0 = nil -%>
7
7
  <%- r = false -%>
@@ -36,16 +36,16 @@ if refill_buffer(1) >= 1
36
36
  <%- end -%>
37
37
  )
38
38
  <%- if gen.location -%>
39
- @cur_loc = @cur_loc.forward(@buffer, @cur, 1)
39
+ @position_offset_loc = @position_offset_loc.forward(@buffer, @position_offset, 1)
40
40
  <%- end -%>
41
- @cur += 1
41
+ @position_offset += 1
42
42
  throw(<%= onsuccess %>)
43
43
  end
44
44
  <%- else # '.' or '[^]' -%>
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
  throw(<%= onsuccess %>)
50
50
  <%- end -%>
51
51
  end
@@ -1 +1 @@
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,8 +2,8 @@
2
2
  <%- l = gen.next_label -%>
3
3
  <%- m = gen.next_label -%>
4
4
  <%- -%><%= gen.generate_code(expr, l, 4, true) -%>
5
- goto L<%= "%04d" % m %>;
6
- L<%= "%04d" % l %>:;
5
+ goto L<%= format("%04d", m) %>;
6
+ L<%= format("%04d", l) %>:;
7
7
  {
8
8
  pcc_value_t null;
9
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 %>);
@@ -14,15 +14,15 @@ L<%= "%04d" % l %>:;
14
14
  thunk->data.leaf.capts.buf[<%= capt.index %>] = &(chunk->capts.buf[<%= capt.index %>]);
15
15
  <%- end -%>
16
16
  thunk->data.leaf.capt0.range.start = chunk->pos;
17
- thunk->data.leaf.capt0.range.end = ctx->cur;
17
+ thunk->data.leaf.capt0.range.end = ctx->position_offset;
18
18
  <%- if gen.location -%>
19
- thunk->data.leaf.capt0.range.start_loc_ptr = &chunk->pos_loc;
20
- thunk->data.leaf.capt0.range.end_loc_ptr = &ctx->cur_loc;
19
+ thunk->data.leaf.capt0.range.start_loc = chunk->pos_loc;
20
+ thunk->data.leaf.capt0.range.end_loc = ctx->position_offset_loc;
21
21
  <%- end -%>
22
22
  memset(&null, 0, sizeof(pcc_value_t)); /* in case */
23
23
  thunk->data.leaf.action(ctx, thunk, &null);
24
24
  pcc_thunk__destroy(ctx->auxil, thunk);
25
25
  }
26
- goto L<%= "%04d" % onfail %>;
27
- L<%= "%04d" % m %>:;
26
+ goto L<%= format("%04d", onfail) %>;
27
+ L<%= format("%04d", m) %>:;
28
28
  }
@@ -10,9 +10,9 @@ catch(<%= m %>) do
10
10
  ThunkLeaf.new(
11
11
  :action_<%= gen.rule.name %>_<%= index %>,
12
12
  Capture.new(
13
- answer.pos, @cur,
13
+ answer.pos, @position_offset,
14
14
  <%- if gen.location -%>
15
- answer.pos_loc,@cur_loc,
15
+ answer.pos_loc,@position_offset_loc,
16
16
  <%- end -%>
17
17
  ),
18
18
  <%- if vars.empty? -%>
@@ -1,16 +1,16 @@
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<%= "%04d" % onfail %>;
3
+ if (pcc_refill_buffer(ctx, n) < n) goto L<%= format("%04d", onfail) %>;
4
4
  if (n > 0) {
5
- const char *const p = ctx->buffer.buf + ctx->cur;
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;
7
7
  size_t i;
8
8
  for (i = 0; i < n; i++) {
9
- if (p[i] != q[i]) goto L<%= "%04d" % onfail %>;
9
+ if (p[i] != q[i]) goto L<%= format("%04d", onfail) %>;
10
10
  }
11
11
  <%- if gen.location -%>
12
- pcc_location_forward(&ctx->cur_loc, ctx->buffer.buf + ctx->cur, n);
12
+ pcc_location_forward(&ctx->position_offset_loc, ctx->buffer.buf + ctx->position_offset, n);
13
13
  <%- end -%>
14
- ctx->cur += n;
14
+ ctx->position_offset += n;
15
15
  }
16
16
  }
@@ -4,13 +4,13 @@ if refill_buffer(n<%= gen.level %>) < n<%= gen.level %>
4
4
  throw(<%= onfail %>)
5
5
  end
6
6
  if n<%= gen.level %> > 0
7
- ptr<%= gen.level %> = @buffer[@cur, n<%= gen.level %>]
7
+ ptr<%= gen.level %> = @buffer[@position_offset, n<%= gen.level %>]
8
8
  q<%= gen.level %> = @buffer[capt<%= gen.level %>.range_start, n<%= gen.level %>]
9
9
  if ptr<%= gen.level %> != q<%= gen.level %>
10
10
  throw(<%= onfail %>)
11
11
  end
12
12
  <%- if gen.location -%>
13
- @cur_loc = @cur_loc.forward(@buffer, @cur, n<%= gen.level %>)
13
+ @position_offset_loc = @position_offset_loc.forward(@buffer, @position_offset, n<%= gen.level %>)
14
14
  <%- end -%>
15
- @cur += n<%= gen.level %>
15
+ @position_offset += n<%= gen.level %>
16
16
  end
@@ -2,29 +2,29 @@
2
2
  <%- m = gen.next_label -%>
3
3
  <%- r = expr.reachability -%>
4
4
  {
5
- const size_t p = ctx->cur;
5
+ const size_t p = ctx->position_offset;
6
6
  <%- if gen.location -%>
7
- const pcc_location_t p_loc = ctx->cur_loc;
7
+ const pcc_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 -%>
11
- ctx->cur = p;
11
+ ctx->position_offset = p;
12
12
  <%- if gen.location -%>
13
- ctx->cur_loc = p_loc;
13
+ ctx->position_offset_loc = p_loc;
14
14
  <%- end -%>
15
15
  <%- end -%>
16
16
  <%- if r == Packcr::CODE_REACH__BOTH -%>
17
- goto L<%= "%04d" % m %>;
17
+ goto L<%= format("%04d", m) %>;
18
18
  <%- end -%>
19
19
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
20
- L<%= "%04d" % l %>:;
21
- ctx->cur = p;
20
+ L<%= format("%04d", l) %>:;
21
+ ctx->position_offset = p;
22
22
  <%- if gen.location -%>
23
- ctx->cur_loc = p_loc;
23
+ ctx->position_offset_loc = p_loc;
24
24
  <%- end -%>
25
- goto L<%= "%04d" % onfail %>;
25
+ goto L<%= format("%04d", onfail) %>;
26
26
  <%- end -%>
27
27
  <%- if r == Packcr::CODE_REACH__BOTH -%>
28
- L<%= "%04d" % m %>:;
28
+ L<%= format("%04d", m) %>:;
29
29
  <%- end -%>
30
30
  }
@@ -2,16 +2,16 @@
2
2
  <%- m = gen.next_label -%>
3
3
  <%- r = expr.reachability -%>
4
4
  catch(<%= m %>) do
5
- pos<%= gen.level %> = @cur
5
+ pos<%= gen.level %> = @position_offset
6
6
  <%- if gen.location -%>
7
- p_loc<%= gen.level %> = @cur_pos
7
+ p_loc<%= gen.level %> = @position_offset_pos
8
8
  <%- end -%>
9
9
  catch(<%= l %>) do
10
10
  <%- %><%= gen.generate_code(expr, l, 4, false) -%>
11
11
  <%- if r != Packcr::CODE_REACH__ALWAYS_FAIL -%>
12
- @cur = pos<%= gen.level %>
12
+ @position_offset = pos<%= gen.level %>
13
13
  <%- if gen.location -%>
14
- @cur_loc = p_loc<%= gen.level %>
14
+ @position_offset_loc = p_loc<%= gen.level %>
15
15
  <%- end -%>
16
16
  <%- end -%>
17
17
  <%- if r == Packcr::CODE_REACH__BOTH -%>
@@ -19,9 +19,9 @@ catch(<%= m %>) do
19
19
  <%- end -%>
20
20
  end
21
21
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
22
- @cur = pos<%= gen.level %>
22
+ @position_offset = pos<%= gen.level %>
23
23
  <%- if gen.location -%>
24
- @cur_loc = p_loc<%= gen.level %>
24
+ @position_offset_loc = p_loc<%= gen.level %>
25
25
  <%- end -%>
26
26
  throw(<%= onfail %>)
27
27
  <%- end -%>
@@ -1,23 +1,23 @@
1
1
  <%- l = gen.next_label -%>
2
2
  <%- r = expr.reachability -%>
3
3
  {
4
- const size_t p = ctx->cur;
4
+ const size_t p = ctx->position_offset;
5
5
  <%- if gen.location -%>
6
- const pcc_location_t p_loc = ctx->cur_loc;
6
+ const pcc_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 -%>
10
- ctx->cur = p;
10
+ ctx->position_offset = p;
11
11
  <%- if gen.location -%>
12
- ctx->cur_loc = p_loc;
12
+ ctx->position_offset_loc = p_loc;
13
13
  <%- end -%>
14
- goto L<%= "%04d" % onfail %>;
14
+ goto L<%= format("%04d", onfail) %>;
15
15
  <%- end -%>
16
16
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
17
- L<%= "%04d" % l %>:;
18
- ctx->cur = p;
17
+ L<%= format("%04d", l) %>:;
18
+ ctx->position_offset = p;
19
19
  <%- if gen.location -%>
20
- ctx->cur_loc = p_loc;
20
+ ctx->position_offset_loc = p_loc;
21
21
  <%- end -%>
22
22
  <%- end -%>
23
23
  }
@@ -1,22 +1,22 @@
1
1
  <%- l = gen.next_label -%>
2
2
  <%- r = expr.reachability -%>
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
  catch(<%= l %>) do
8
8
  <%- %><%= gen.generate_code(expr, l, 2, false) -%>
9
9
  <%- if r != Packcr::CODE_REACH__ALWAYS_FAIL -%>
10
- @cur = pos<%= gen.level %>
10
+ @position_offset = pos<%= gen.level %>
11
11
  <%- if gen.location -%>
12
- @cur_loc = p_loc<%= gen.level %>
12
+ @position_offset_loc = p_loc<%= gen.level %>
13
13
  <%- end -%>
14
14
  throw(<%= onfail %>)
15
15
  <%- end -%>
16
16
  end
17
17
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
18
- @cur = pos<%= gen.level %>
18
+ @position_offset = pos<%= gen.level %>
19
19
  <%- if gen.location -%>
20
- @cur_loc = p_loc<%= gen.level %>
20
+ @position_offset_loc = p_loc<%= gen.level %>
21
21
  <%- end -%>
22
22
  <%- end -%>
@@ -1,8 +1,8 @@
1
1
  {
2
2
  <%- if min > 0 -%>
3
- const size_t p0 = ctx->cur;
3
+ const size_t p0 = ctx->position_offset;
4
4
  <%- if gen.location -%>
5
- const pcc_location_t p0_loc = ctx->cur_loc;
5
+ const pcc_location_t p0_loc = ctx->position_offset_loc;
6
6
  <%- end -%>
7
7
  const size_t n0 = chunk->thunks.len;
8
8
  <%- end -%>
@@ -12,21 +12,21 @@
12
12
  <%- else -%>
13
13
  for (i = 0; i < <%= max %>; i++) {
14
14
  <%- end -%>
15
- const size_t p = ctx->cur;
15
+ const size_t p = ctx->position_offset;
16
16
  <%- if gen.location -%>
17
- const pcc_location_t p_loc = ctx->cur_loc;
17
+ const pcc_location_t p_loc = ctx->position_offset_loc;
18
18
  <%- end -%>
19
19
  const size_t n = chunk->thunks.len;
20
20
  <%- l = gen.next_label -%>
21
21
  <%- r = expr.reachability -%>
22
22
  <%= gen.generate_code(expr, l, 8, false) -%>
23
- if (ctx->cur == p) break;
23
+ if (ctx->position_offset == p) break;
24
24
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
25
25
  continue;
26
- L<%= "%04d" % l %>:;
27
- ctx->cur = p;
26
+ L<%= format("%04d", l) %>:;
27
+ ctx->position_offset = p;
28
28
  <%- if gen.location -%>
29
- ctx->cur_loc = p_loc;
29
+ ctx->position_offset_loc = p_loc;
30
30
  <%- end -%>
31
31
  pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
32
32
  break;
@@ -34,12 +34,12 @@
34
34
  }
35
35
  <%- if min > 0 -%>
36
36
  if (i < <%= min %>) {
37
- ctx->cur = p0;
37
+ ctx->position_offset = p0;
38
38
  <%- if gen.location -%>
39
- ctx->cur_loc = p0_loc;
39
+ ctx->position_offset_loc = p0_loc;
40
40
  <%- end -%>
41
41
  pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
42
- goto L<%= "%04d" % onfail %>;
42
+ goto L<%= format("%04d", onfail) %>;
43
43
  }
44
44
  <%- end -%>
45
45
  }
@@ -1,7 +1,7 @@
1
1
  <%- if min > 0 -%>
2
- q<%= gen.level %> = @cur
2
+ q<%= gen.level %> = @position_offset
3
3
  <%- if gen.location -%>
4
- q_loc<%= gen.level %> = @cur_loc
4
+ q_loc<%= gen.level %> = @position_offset_loc
5
5
  <%- end -%>
6
6
  m<%= gen.level %> = answer.thunks.length
7
7
  <%- end -%>
@@ -13,33 +13,33 @@ p_loc<%= gen.level %> = nil
13
13
  n<%= gen.level %> = nil
14
14
  <%- l = gen.next_label -%>
15
15
  catch(<%= l %>) do
16
- pos<%= gen.level %> = @cur
16
+ pos<%= gen.level %> = @position_offset
17
17
  <%- if gen.location -%>
18
- p_loc<%= gen.level %> = @cur_loc
18
+ p_loc<%= gen.level %> = @position_offset_loc
19
19
  <%- end -%>
20
20
  n<%= gen.level %> = answer.thunks.length
21
21
  <%- r = expr.reachability -%>
22
22
  <%- %><%= gen.generate_code(expr, l, 2, false) -%>
23
23
  i<%= gen.level %> += 1
24
- if @cur != pos<%= gen.level %><% if max >= 0 %> || i<%= gen.level %> < <%= max %><% end %>
24
+ if @position_offset != pos<%= gen.level %><% if max >= 0 %> || i<%= gen.level %> < <%= max %><% end %>
25
25
  redo
26
26
  end
27
27
  pos<%= gen.level %> = nil
28
28
  end
29
29
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
30
30
  if pos<%= gen.level %>
31
- @cur = pos<%= gen.level %>
31
+ @position_offset = pos<%= gen.level %>
32
32
  <%- if gen.location -%>
33
- @cur_loc = p_loc<%= gen.level %>
33
+ @position_offset_loc = p_loc<%= gen.level %>
34
34
  <%- end -%>
35
35
  answer.thunks[n<%= gen.level %>..-1] = []
36
36
  end
37
37
  <%- end -%>
38
38
  <%- if min > 0 -%>
39
39
  if i<%= gen.level %> < <%= min %>
40
- @cur = q<%= gen.level %>
40
+ @position_offset = q<%= gen.level %>
41
41
  <%- if gen.location -%>
42
- @cur_loc = q_loc<%= gen.level %>
42
+ @position_offset_loc = q_loc<%= gen.level %>
43
43
  <%- end -%>
44
44
  answer.thunks[m<%= gen.level %>..-1] = []
45
45
  throw(<%= onfail %>)
@@ -1,21 +1,21 @@
1
1
  {
2
2
  <%- l = gen.next_label -%>
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
  <%- r = expr.reachability -%>
9
9
  <%= gen.generate_code(expr, l, 4, false) -%>
10
10
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
11
11
  <%- m = gen.next_label -%>
12
- goto L<%= "%04d" % m %>;
13
- L<%= "%04d" % l %>:;
12
+ goto L<%= format("%04d", m) %>;
13
+ L<%= format("%04d", l) %>:;
14
14
  <%- if gen.location -%>
15
- ctx->cur_loc = p_loc;
15
+ ctx->position_offset_loc = p_loc;
16
16
  <%- end -%>
17
- ctx->cur = p;
17
+ ctx->position_offset = p;
18
18
  pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
19
- L<%= "%04d" % m %>:;
19
+ L<%= format("%04d", m) %>:;
20
20
  <%- end -%>
21
21
  }
@@ -1,7 +1,7 @@
1
1
  <%- l = gen.next_label -%>
2
- pos<%= gen.level %> = @cur
2
+ pos<%= gen.level %> = @position_offset
3
3
  <%- if gen.location -%>
4
- p_loc<%= gen.level %> = @cur_loc
4
+ p_loc<%= gen.level %> = @position_offset_loc
5
5
  <%- end -%>
6
6
  n<%= gen.level %> = answer.thunks.length
7
7
  <%- r = expr.reachability -%>
@@ -15,9 +15,9 @@ catch(<%= m %>) do
15
15
  throw(<%= m %>)
16
16
  end
17
17
  <%- if gen.location -%>
18
- @cur_loc = p_loc<%= gen.level %>
18
+ @position_offset_loc = p_loc<%= gen.level %>
19
19
  <%- end -%>
20
- @cur = pos<%= gen.level %>
20
+ @position_offset = pos<%= gen.level %>
21
21
  answer.thunks[n<%= gen.level %>..-1] = []
22
22
  end
23
23
  <%- end -%>
@@ -1,5 +1,17 @@
1
1
  <%- if index != nil -%>
2
- if (!pcc_apply_rule(ctx, pcc_evaluate_rule_<%= name %>, &chunk->thunks, &(chunk->values.buf[<%= index %>]))) goto L<%= "%04d" % onfail %>;
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) {
5
+ l = limits;
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) %>;
8
+ }
3
9
  <%- else -%>
4
- if (!pcc_apply_rule(ctx, pcc_evaluate_rule_<%= name %>, &chunk->thunks, NULL)) goto L<%= "%04d" % onfail %>;
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) {
13
+ l = limits;
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) %>;
16
+ }
5
17
  <%- end -%>
@@ -1,9 +1,21 @@
1
1
  <%- if index != nil -%>
2
- if !apply_rule(:evaluate_rule_<%= name %>, answer.thunks, answer.values, <%= index %>)
3
- throw(<%= onfail %>)
2
+ if limits && @position_offset == offset && !limits[:evaluate_rule_<%= name %>]
3
+ if !apply_rule(:evaluate_rule_<%= name %>, answer.thunks, answer.values, <%= index %>, offset<% if gen.location %>, offset_loc<% end %>, limits: limits)
4
+ throw(<%= onfail %>)
5
+ end
6
+ else
7
+ if !apply_rule(:evaluate_rule_<%= name %>, answer.thunks, answer.values, <%= index %>, offset<% if gen.location %>, offset_loc<% end %>)
8
+ throw(<%= onfail %>)
9
+ end
4
10
  end
5
11
  <%- else -%>
6
- if !apply_rule(:evaluate_rule_<%= name %>, answer.thunks, nil, 0)
7
- throw(<%= onfail %>)
12
+ if limits && @position_offset == offset && !limits[:evaluate_rule_<%= name %>]
13
+ if !apply_rule(:evaluate_rule_<%= name %>, answer.thunks, nil, 0, offset<% if gen.location %>, offset_loc<% end %>, limits: limits)
14
+ throw(<%= onfail %>)
15
+ end
16
+ else
17
+ if !apply_rule(:evaluate_rule_<%= name %>, answer.thunks, nil, 0, offset<% if gen.location %>, offset_loc<% end %>)
18
+ throw(<%= onfail %>)
19
+ end
8
20
  end
9
21
  <%- end -%>
@@ -1,9 +1,21 @@
1
1
  <%- if index != nil -%>
2
- if apply_rule(:evaluate_rule_<%= name %>, answer.thunks, answer.values, <%= index %>)
3
- throw(<%= onsuccess %>)
2
+ if limits && @position_offset == offset && !limits[:evaluate_rule_<%= name %>]
3
+ if apply_rule(:evaluate_rule_<%= name %>, answer.thunks, answer.values, <%= index %>, offset<% if gen.location %>, offset_loc<% end %>, limits: limits)
4
+ throw(<%= onsuccess %>)
5
+ end
6
+ else
7
+ if apply_rule(:evaluate_rule_<%= name %>, answer.thunks, answer.values, <%= index %>, offset<% if gen.location %>, offset_loc<% end %>)
8
+ throw(<%= onsuccess %>)
9
+ end
4
10
  end
5
11
  <%- else -%>
6
- if apply_rule(:evaluate_rule_<%= name %>, answer.thunks, nil, 0)
7
- throw(<%= onsuccess %>)
12
+ if limits && @position_offset == offset && !limits[:evaluate_rule_<%= name %>]
13
+ if apply_rule(:evaluate_rule_<%= name %>, answer.thunks, nil, 0, offset<% if gen.location %>, offset_loc<% end %>, limits: limits)
14
+ throw(<%= onsuccess %>)
15
+ end
16
+ else
17
+ if apply_rule(:evaluate_rule_<%= name %>, answer.thunks, nil, 0, offset<% if gen.location %>, offset_loc<% end %>)
18
+ throw(<%= onsuccess %>)
19
+ end
8
20
  end
9
21
  <%- end -%>
@@ -1,3 +1,9 @@
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);
3
+ chunk->pos = ctx->position_offset;
4
+ <%- if gen.location -%>
5
+ chunk->pos_loc = ctx->position_offset_loc;
6
+ <%- end -%>
1
7
  PCC_DEBUG(ctx->auxil, PCC_DBG_EVALUATE, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
2
8
  ctx->level++;
3
9
  pcc_value_table__resize(ctx->auxil, &chunk->values, <%= vars.length %>);
@@ -8,12 +14,13 @@
8
14
  <%- r = expr.reachability -%>
9
15
  <%- -%><%= gen.generate_code(expr, 0, 4, false) -%>
10
16
  ctx->level--;
11
- PCC_DEBUG(ctx->auxil, PCC_DBG_MATCH, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
17
+ PCC_DEBUG(ctx->auxil, PCC_DBG_MATCH, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->position_offset - chunk->pos));
12
18
  return chunk;
13
19
  <%- if r != Packcr::CODE_REACH__ALWAYS_SUCCEED -%>
14
20
  L0000:;
15
21
  ctx->level--;
16
- PCC_DEBUG(ctx->auxil, PCC_DBG_NOMATCH, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
22
+ PCC_DEBUG(ctx->auxil, PCC_DBG_NOMATCH, "<%= name %>", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->position_offset - chunk->pos));
17
23
  pcc_thunk_chunk__destroy(ctx, chunk);
18
24
  return NULL;
19
25
  <%- end -%>
26
+ }