Skip to content

Commit ed667e5

Browse files
authored
Merge pull request #1 from nobu/parser_state
Fix parser state compilation errors
2 parents c5b5831 + 351a9fd commit ed667e5

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

lib/lrama/grammar/parser_state.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ def states_functions
4545
# define YYPUSH_STATE_#{state_name.upcase}(value) \\
4646
do \\
4747
{ \\
48-
if (#{stack_prefix} + #{states_stack_size_name} - 1 <= #{stack_prefix}_p) \\
49-
YYSTATE_STACK_INCREASE (#{stack_prefix}_a, #{stack_prefix}, #{stack_prefix}_p, #{states_stack_size_name}, "#{state_name}"); \\
50-
YYDPRINTF ((stderr, "Push %s to #{state_name}\\n", #{state_name_macro} (value))); \\
51-
*++#{stack_prefix}_p = value; \\
48+
if (#{stack_prefix}_b + #{states_stack_size_name} - 1 <= #{stack_prefix}_p) \\
49+
YYSTATE_STACK_INCREASE (#{stack_prefix}_a, #{stack_prefix}_b, #{stack_prefix}_p, #{states_stack_size_name}, "#{state_name}"); \\
50+
YYDPRINTF ((stderr, "Push %s to #{state_name}\\n", #{state_name_macro} (yyparser_state_ ## value))); \\
51+
*++#{stack_prefix}_p = yyparser_state_ ## value; \\
5252
} \\
5353
while (0)
5454
5555
# define YYPOP_STATE_#{state_name.upcase}() \\
5656
do \\
5757
{ \\
5858
YYDPRINTF ((stderr, "Pop #{state_name}\\n")); \\
59-
if (#{stack_prefix}_p != #{stack_prefix}) \\
59+
if (#{stack_prefix}_p != #{stack_prefix}_b) \\
6060
{ \\
6161
#{stack_prefix}_p -= 1; \\
6262
} \\
@@ -70,8 +70,8 @@ def states_functions
7070
# define YYSET_STATE_#{state_name.upcase}(value) \\
7171
do \\
7272
{ \\
73-
YYDPRINTF ((stderr, "Set %s to #{state_name}\\n", #{state_name_macro} (value))); \\
74-
*#{stack_prefix}_p = value; \\
73+
YYDPRINTF ((stderr, "Set %s to #{state_name}\\n", #{state_name_macro} (yyparser_state_ ## value))); \\
74+
*#{stack_prefix}_p = yyparser_state_ ## value; \\
7575
} \\
7676
while (0)
7777
@@ -81,8 +81,8 @@ def states_functions
8181

8282
def states_clean_up_stack
8383
<<~CODE
84-
if (#{stack_prefix} != #{stack_prefix}_a)
85-
YYSTACK_FREE (#{stack_prefix});
84+
if (#{stack_prefix}_b != #{stack_prefix}_a)
85+
YYSTACK_FREE (#{stack_prefix}_b);
8686
CODE
8787
end
8888

@@ -97,8 +97,8 @@ def states_stacks
9797
9898
/* The parser state stack (#{stack_prefix}): array, bottom, top. */
9999
int #{stack_prefix}_a[YYINITDEPTH];
100-
int *#{stack_prefix} = #{stack_prefix}_a;
101-
int *#{stack_prefix}_p = #{stack_prefix};
100+
int *#{stack_prefix}_b = #{stack_prefix}_a;
101+
int *#{stack_prefix}_p = #{stack_prefix}_b;
102102
STACKS
103103
end
104104

spec/lrama/grammar/parser_state_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@
5858
# define YYPUSH_STATE_IN_RESCUE(value) \\
5959
do \\
6060
{ \\
61-
if (yyparser_state_in_rescue + yyparser_state_in_rescue_stacksize - 1 <= yyparser_state_in_rescue_p) \\
62-
YYSTATE_STACK_INCREASE (yyparser_state_in_rescue_a, yyparser_state_in_rescue, yyparser_state_in_rescue_p, yyparser_state_in_rescue_stacksize, "in_rescue"); \\
63-
YYDPRINTF ((stderr, "Push %s to in_rescue\\n", YY_STATE_IN_RESCUE_NAME (value))); \\
64-
*++yyparser_state_in_rescue_p = value; \\
61+
if (yyparser_state_in_rescue_b + yyparser_state_in_rescue_stacksize - 1 <= yyparser_state_in_rescue_p) \\
62+
YYSTATE_STACK_INCREASE (yyparser_state_in_rescue_a, yyparser_state_in_rescue_b, yyparser_state_in_rescue_p, yyparser_state_in_rescue_stacksize, "in_rescue"); \\
63+
YYDPRINTF ((stderr, "Push %s to in_rescue\\n", YY_STATE_IN_RESCUE_NAME (yyparser_state_ ## value))); \\
64+
*++yyparser_state_in_rescue_p = yyparser_state_ ## value; \\
6565
} \\
6666
while (0)
6767
6868
# define YYPOP_STATE_IN_RESCUE() \\
6969
do \\
7070
{ \\
7171
YYDPRINTF ((stderr, "Pop in_rescue\\n")); \\
72-
if (yyparser_state_in_rescue_p != yyparser_state_in_rescue) \\
72+
if (yyparser_state_in_rescue_p != yyparser_state_in_rescue_b) \\
7373
{ \\
7474
yyparser_state_in_rescue_p -= 1; \\
7575
} \\
@@ -83,8 +83,8 @@
8383
# define YYSET_STATE_IN_RESCUE(value) \\
8484
do \\
8585
{ \\
86-
YYDPRINTF ((stderr, "Set %s to in_rescue\\n", YY_STATE_IN_RESCUE_NAME (value))); \\
87-
*yyparser_state_in_rescue_p = value; \\
86+
YYDPRINTF ((stderr, "Set %s to in_rescue\\n", YY_STATE_IN_RESCUE_NAME (yyparser_state_ ## value))); \\
87+
*yyparser_state_in_rescue_p = yyparser_state_ ## value; \\
8888
} \\
8989
while (0)
9090
@@ -96,8 +96,8 @@
9696
describe "#states_clean_up_stack" do
9797
it "returns states clean up codes" do
9898
expect(parser_state.states_clean_up_stack).to eq <<~CODE
99-
if (yyparser_state_in_rescue != yyparser_state_in_rescue_a)
100-
YYSTACK_FREE (yyparser_state_in_rescue);
99+
if (yyparser_state_in_rescue_b != yyparser_state_in_rescue_a)
100+
YYSTACK_FREE (yyparser_state_in_rescue_b);
101101
CODE
102102
end
103103
end
@@ -116,8 +116,8 @@
116116
117117
/* The parser state stack (yyparser_state_in_rescue): array, bottom, top. */
118118
int yyparser_state_in_rescue_a[YYINITDEPTH];
119-
int *yyparser_state_in_rescue = yyparser_state_in_rescue_a;
120-
int *yyparser_state_in_rescue_p = yyparser_state_in_rescue;
119+
int *yyparser_state_in_rescue_b = yyparser_state_in_rescue_a;
120+
int *yyparser_state_in_rescue_p = yyparser_state_in_rescue_b;
121121
STACKS
122122
end
123123
end

0 commit comments

Comments
 (0)