Debian Codegraph @

meta/make_internal_pm.pl

raw
1 # Copyright 2022 Jeffrey Kegler
2 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
3 # redistribute it and/or modify it under the terms of the GNU Lesser
4 # General Public License as published by the Free Software Foundation,
5 # either version 3 of the License, or (at your option) any later version.
6 #
7 # Marpa::R2 is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11 #
12 # You should have received a copy of the GNU Lesser
13 # General Public License along with Marpa::R2. If not, see
14 # http://www.gnu.org/licenses/.
15
16 use 5.010001;
17 use strict;
18 use warnings;
19 use Carp;
20 use English qw( -no_match_vars );
21
22 our $HEADER;
23
24 sub offset {
25 my ($desc) = @_;
26 my @fields = split q{ }, $desc;
27 my $offset = -1;
28 my $in_comment = 0;
29
30 no strict 'refs';
31 FIELD: for my $field (@fields) {
32
33 if ($in_comment) {
34 $in_comment = $field ne ':}' && $field ne '}';
35 next FIELD;
36 }
37
38 PROCESS_OPTION: {
39 last PROCESS_OPTION if $field !~ /\A [{:] /xms;
40 if ( $field =~ / \A [:] package [=] (.*) /xms ) {
41 say "\npackage $1;";
42 $offset = -1;
43 next FIELD;
44 }
45 if ( $field =~ / \A [:]? [{] /xms ) {
46 $in_comment++;
47 next FIELD;
48 }
49 } ## end PROCESS_OPTION:
50
51
52 if ((substr $field, 0, 1) eq '=') {
53 $field = substr $field, 1;
54 } else {
55 $offset++;
56 }
57 die "Unacceptable field name: $field"
58 if $field =~ /[^A-Z0-9_]/xms;
59 say "use constant $field => $offset;"
60
61 } ## end for my $field (@fields)
62 return 1;
63 } ## end sub Marpa::R2::offset
64
65 $HEADER =~ s/!!!PROGRAM_NAME!!!/$PROGRAM_NAME/;
66 say $HEADER;
67 $RS = undef;
68 offset(<DATA>);
69 say "\n1;";
70
71 BEGIN {
72
73 $HEADER = <<'END_OF_HEADER';
74 # Copyright 2022 Jeffrey Kegler
75 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
76 # redistribute it and/or modify it under the terms of the GNU Lesser
77 # General Public License as published by the Free Software Foundation,
78 # either version 3 of the License, or (at your option) any later version.
79 #
80 # Marpa::R2 is distributed in the hope that it will be useful,
81 # but WITHOUT ANY WARRANTY; without even the implied warranty of
82 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
83 # Lesser General Public License for more details.
84 #
85 # You should have received a copy of the GNU Lesser
86 # General Public License along with Marpa::R2. If not, see
87 # http://www.gnu.org/licenses/.
88
89 # DO NOT EDIT THIS FILE DIRECTLY
90 # It was generated by !!!PROGRAM_NAME!!!
91
92 package Marpa::R2::Internal;
93
94 use 5.010001;
95 use strict;
96 use warnings;
97 use Carp;
98
99 use vars qw($VERSION $STRING_VERSION);
100 $VERSION = '14.000000';
101 $STRING_VERSION = $VERSION;
102 $VERSION = eval $VERSION;
103 END_OF_HEADER
104
105 }
106
107 __DATA__
108
109 :package=Marpa::R2::Internal::Symbol
110 ID { Unique ID }
111 BLESSING
112 LEXEME_SEMANTICS
113 DISPLAY_FORM
114 DSL_FORM
115 LEGACY_NAME
116 DESCRIPTION
117 IF_INACCESSIBLE
118
119 :package=Marpa::R2::Internal::Rule
120
121 ID
122 NAME
123 DISCARD_SEPARATION
124 MASK { Semantic mask of RHS symbols }
125 SLIF_TAG { A tag for use by the SLIF }
126 ACTION_NAME
127 BLESSING
128 DESCRIPTION
129
130 :package=Marpa::R2::Internal::Grammar
131
132 C { A C structure }
133 TRACER { Also contains a copy of the C structure.
134 It is used frequently, so that an easy memoization
135 is probably worthwhile to save a the extra
136 indirection.
137 }
138 RULES { array of rule refs }
139 RULE_ID_BY_TAG
140
141 SYMBOLS { array of symbol refs }
142
143 ACTIONS { Default package in which to find actions }
144 BLESS_PACKAGE { Default package into which nodes are blessed }
145 DEFAULT_ACTION { Action for rules without one }
146 TRACE_FILE_HANDLE
147 WARNINGS { print warnings about grammar? }
148 INTERFACE { currently 'standard' or 'stuifzand' }
149 INTERNAL { internal grammar -- relax various restrictions }
150
151 CHARACTER_CLASSES { an hash of
152 character class regex by symbol name.
153 Used before precomputation. }
154
155 CHARACTER_CLASS_TABLE { An array of symbol ID and
156 regex. Used after precomputation. }
157
158 =LAST_BASIC_DATA_FIELD
159
160 { === Evaluator Fields === }
161
162 DEFAULT_EMPTY_ACTION { default value for empty rules }
163 ACTION_OBJECT
164 INFINITE_ACTION
165
166 =LAST_EVALUATOR_FIELD
167
168 PROBLEMS { fatal problems }
169
170 =LAST_RECOGNIZER_FIELD
171
172 START_NAME { name of original symbol }
173 INACCESSIBLE_OK
174 UNPRODUCTIVE_OK
175 TRACE_RULES
176
177 =LAST_FIELD
178
179 :package=Marpa::R2::Internal::Recognizer
180
181 C { C structure for the recognizer }
182 B_C { C structure for the bocage }
183 O_C { C structure for the Marpa order object }
184 T_C { C structure for the Marpa tree iterator }
185
186 GRAMMAR { the grammar used }
187 TREE_MODE { 'tree' or 'forest' or undef }
188 FINISHED
189 TOKEN_VALUES
190
191 ASF_OR_NODES { memoized or-nodes }
192
193 TRACE_FILE_HANDLE
194 ERROR_MESSAGE { Temporary place to put an error message for later use.
195 One use is when the error occurs in a subroutine, but you want the bail message
196 to have the benefit of a higher-level context.
197 }
198
199 END_OF_PARSE
200 CLOSURES
201 EVENT_IF_EXPECTED
202 MAX_PARSES
203 RANKING_METHOD
204 TRACE_ACTIONS
205 TRACE_AND_NODES
206 TRACE_BOCAGE
207 TRACE_EARLEY_SETS
208 TRACE_OR_NODES
209 TRACE_TERMINALS
210 TRACE_VALUES
211 TRACE_SL
212 WARNINGS
213
214 { The following fields must be reinitialized when
215 evaluation is reset }
216
217 EVENTS
218 NO_PARSE { no parse found in parse series -- memoized }
219 READ_STRING_ERROR
220 NULL_VALUES
221
222 { Fields for new SLIF resolution logic
223 -- must be reinitialized when evaluation is reset }
224 PER_PARSE_CONSTRUCTOR
225 RESOLVE_PACKAGE
226 RESOLVE_PACKAGE_SOURCE
227 REGISTRATIONS
228 CLOSURE_BY_SYMBOL_ID
229 CLOSURE_BY_RULE_ID
230
231 { This is the end of the list of fields which
232 must be reinitialized when evaluation is reset }
233
234 :package=Marpa::R2::Internal::Progress_Report
235
236 RULE_ID
237 POSITION
238 ORIGIN
239 CURRENT
240
241 :package=Marpa::R2::Internal::Glade
242
243 ID
244 SYMCHES
245 VISITED
246 REGISTERED
247
248 :package=Marpa::R2::Internal::Choicepoint
249
250 { An external choicepoint }
251 ASF
252 FACTORING_STACK
253 OR_NODE_IN_USE
254
255 :package=Marpa::R2::Internal::Nook
256
257 PARENT
258 OR_NODE
259 FIRST_CHOICE
260 LAST_CHOICE
261 IS_CAUSE
262 IS_PREDECESSOR
263 CAUSE_IS_EXPANDED
264 PREDECESSOR_IS_EXPANDED
265
266 :package=Marpa::R2::Internal::ASF
267
268 { It is important not to keep any references to choicepoints, direct or
269 indirect in this structure. The resulting circular reference would prevent
270 both structures from being freed, and create a memory leak. }
271
272 SLR { The underlying SLR }
273 LEXEME_RESOLUTIONS
274 RULE_RESOLUTIONS
275
276 FACTORING_MAX
277 RULE_BLESSINGS
278 SYMBOL_BLESSINGS
279
280 SYMCH_BLESSING_PACKAGE
281 FACTORING_BLESSING_PACKAGE
282 PROBLEM_BLESSING_PACKAGE
283 DEFAULT_RULE_BLESSING_PACKAGE
284 DEFAULT_TOKEN_BLESSING_PACKAGE
285
286 OR_NODES {
287 per or-node data,
288 current arrays of sorted and-nodes
289 }
290 GLADES { Memoized forest }
291
292 INTSET_BY_KEY
293 NEXT_INTSET_ID
294
295 { use powersets for choicepoints only
296 -- create a new series if I need them for something else
297 }
298 NIDSET_BY_ID
299 POWERSET_BY_ID
300
301 :package=Marpa::R2::Internal::ASF::Traverse
302
303 ASF
304 VALUES { Memoized values, by glade ID }
305 CODE { The anonymous subtroutine for traversal }
306 PER_TRAVERSE_OBJECT { a "scratch" object for the traversal }
307 GLADE
308 SYMCH_IX
309 FACTORING_IX
310
311 :package=Marpa::R2::Internal::Nidset
312
313 ID
314 NIDS
315
316 :package=Marpa::R2::Internal::Powerset
317
318 ID
319 NIDSET_IDS
320
321 :package=Marpa::R2::Internal::Scanless::G
322
323 C { The thin version of this object }
324
325 THICK_LEX_GRAMMARS
326 THICK_G1_GRAMMAR
327 CHARACTER_CLASS_TABLES
328 DISCARD_EVENT_BY_LEXER_RULE
329 MASK_BY_RULE_ID
330
331 DEFAULT_G1_START_ACTION
332 COMPLETION_EVENT_BY_ID
333 NULLED_EVENT_BY_ID
334 PREDICTION_EVENT_BY_ID
335 LEXEME_EVENT_BY_ID
336 SYMBOL_IDS_BY_EVENT_NAME_AND_TYPE
337
338 { This saves a lot of time at points }
339 CACHE_RULEIDS_BY_LHS_NAME
340
341 TRACE_FILE_HANDLE
342 TRACE_TERMINALS
343
344 :package=Marpa::R2::Internal::Scanless::R
345
346 C { The thin version of this object }
347
348 GRAMMAR
349 THICK_G1_RECCE
350 P_INPUT_STRING
351
352 EXHAUSTION_ACTION
353 REJECTION_ACTION
354 TRACE_FILE_HANDLE
355 TRACE_LEXERS
356 TRACE_TERMINALS
357 READ_STRING_ERROR
358 EVENTS
359
360 { vim: set expandtab shiftwidth=4:
361 }