Debian Codegraph @

xs/create_ops.pl

raw
1 #!perl
2 # Copyright 2022 Jeffrey Kegler
3 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
4 # redistribute it and/or modify it under the terms of the GNU Lesser
5 # General Public License as published by the Free Software Foundation,
6 # either version 3 of the License, or (at your option) any later version.
7 #
8 # Marpa::R2 is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser
14 # General Public License along with Marpa::R2. If not, see
15 # http://www.gnu.org/licenses/.
16
17 use 5.010001;
18 use strict;
19 use warnings;
20 use English qw( -no_match_vars );
21 use autodie;
22
23 # Portability is NOT emphasized here -- this script is part
24 # of the development environment, not the configuration or
25 # installation environment
26
27 if (scalar @ARGV != 0) {
28 die("usage: $PROGRAM_NAME > marpa_slifop.h");
29 }
30
31 my @ops = sort { $a->[0] cmp $b->[0] }
32 [ "alternative", "MARPA_OP_ALTERNATIVE" ],
33 [ "bless", "MARPA_OP_BLESS" ],
34 [ "callback", "MARPA_OP_CALLBACK" ],
35 [ "earleme_complete", "MARPA_OP_EARLEME_COMPLETE" ],
36 [ "end_marker", "MARPA_OP_END_MARKER" ],
37 [ "invalid_char", "MARPA_OP_INVALID_CHAR" ],
38 [ "noop", "MARPA_OP_NOOP" ],
39 [ "pause", "MARPA_OP_PAUSE" ],
40 [ "push_g1_len", "MARPA_OP_PUSH_G1_LEN" ],
41 [ "push_g1_length", "MARPA_OP_PUSH_G1_LENGTH" ],
42 [ "push_g1_start", "MARPA_OP_PUSH_G1_START" ],
43 [ "push_length", "MARPA_OP_PUSH_LENGTH" ],
44 [ "push_constant", "MARPA_OP_PUSH_CONSTANT" ],
45 [ "push_one", "MARPA_OP_PUSH_ONE" ],
46 [ "push_sequence", "MARPA_OP_PUSH_SEQUENCE" ],
47 [ "push_start_location", "MARPA_OP_PUSH_START_LOCATION" ],
48 [ "push_undef", "MARPA_OP_PUSH_UNDEF" ],
49 [ "push_values", "MARPA_OP_PUSH_VALUES" ],
50 [ "result_is_array", "MARPA_OP_RESULT_IS_ARRAY" ],
51 [ "result_is_constant", "MARPA_OP_RESULT_IS_CONSTANT" ],
52 [ "result_is_n_of_sequence", "MARPA_OP_RESULT_IS_N_OF_SEQUENCE" ],
53 [ "result_is_rhs_n", "MARPA_OP_RESULT_IS_RHS_N" ],
54 [ "result_is_token_value", "MARPA_OP_RESULT_IS_TOKEN_VALUE" ],
55 [ "result_is_undef", "MARPA_OP_RESULT_IS_UNDEF" ],
56 [ "retry_or_set_lexer", "MARPA_OP_RETRY_OR_SET_LEXER" ],
57 [ "set_lexer", "MARPA_OP_SET_LEXER" ];
58
59 say <<'END_OF_PREAMBLE';
60 /*
61 * Copyright 2022 Jeffrey Kegler
62 * This file is part of Marpa::R2. Marpa::R2 is free software: you can
63 * redistribute it and/or modify it under the terms of the GNU Lesser
64 * General Public License as published by the Free Software Foundation,
65 * either version 3 of the License, or (at your option) any later version.
66 *
67 * Marpa::R2 is distributed in the hope that it will be useful,
68 * but WITHOUT ANY WARRANTY; without even the implied warranty of
69 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
70 * Lesser General Public License for more details.
71 *
72 * You should have received a copy of the GNU Lesser
73 * General Public License along with Marpa::R2. If not, see
74 * http://www.gnu.org/licenses/.
75 */
76
77 END_OF_PREAMBLE
78
79 say <<END_OF_PREAMBLE;
80 /* Generated automatically by $PROGRAM_NAME
81 * NOTE: Changes made to this file will be lost: look at $PROGRAM_NAME.
82 */
83 END_OF_PREAMBLE
84
85 for (my $i = 0; $i <= $#ops; $i++) {
86 my (undef, $macro) = @{$ops[$i]};
87 say "#define $macro $i";
88 }
89 print "\n";
90
91 say q<static struct op_data_s op_by_name_object[] = {>;
92 for (my $i = 0; $i <= $#ops; $i++) {
93 my ($name, $macro) = @{$ops[$i]};
94 say qq< { "$name", $macro },>;
95 }
96 say q<};>;
97 print "\n";
98
99 say q<static const char* op_name_by_id_object[] = {>;
100 for (my $i = 0; $i <= $#ops; $i++) {
101 my ($name) = @{$ops[$i]};
102 say qq< "$name",>;
103 }
104 say q<};>;
105 print "\n";
106
107 # vim: expandtab shiftwidth=4: