summaryrefslogtreecommitdiff
path: root/support/splint/cweb/common.w
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-10-12 03:04:00 +0000
committerNorbert Preining <norbert@preining.info>2020-10-12 03:04:00 +0000
commit0ce40abb18ec02ec6fd6bcc5f21612c88daa7578 (patch)
tree416289fe1448873fd8ca33051f50ad85bffa8aaa /support/splint/cweb/common.w
parentfdb18507cd80dc17f5a5256153d34668b4f4e61c (diff)
CTAN sync 202010120303
Diffstat (limited to 'support/splint/cweb/common.w')
-rw-r--r--support/splint/cweb/common.w66
1 files changed, 51 insertions, 15 deletions
diff --git a/support/splint/cweb/common.w b/support/splint/cweb/common.w
index 3ab5af93b4..0f50fdcabd 100644
--- a/support/splint/cweb/common.w
+++ b/support/splint/cweb/common.w
@@ -1,4 +1,4 @@
-@q Copyright 2012-2014, Alexander Shibakov@>
+@q Copyright 2012-2020, Alexander Shibakov@>
@q This file is part of SPLinT@>
@q SPLinT is free software: you can redistribute it and/or modify@>
@@ -14,7 +14,7 @@
@q You should have received a copy of the GNU General Public License@>
@q along with SPLinT. If not, see <http://www.gnu.org/licenses/>.@>
-@** Forcing \bison\ and \flex\ to output \TeX.
+@** Forcing \eatone{bison}\bison\ and \eatone{flex}\flex\ to output \TeX.
Instead of implementing a \bison\ (or \flex) `plugin' for outputting
\TeX\ parser, the code that follows produces a separate executable
that outputs all the required tables after the inclusion of an
@@ -25,6 +25,11 @@ assumed to be merely |printf()| statements that output the `real'
output an `action switch' appropriate for use with \TeX. In every
other respect, the included parser or scanner can use any features
allowed in `real' parsers and scanners.
+\def\action#1{\hbox{$\hbox{\\{action}}_{#1}$}}
+\def\actionn{\action{n}}
+
+@s action1 TeX
+@s actionn TeX
@*1 Common routines.
The `top' level of the scanner and parser `drivers' is very similar,
@@ -43,9 +48,6 @@ software. All the essential routines are presented in the sections
below, though.
@<\Cee\ postamble@>=
-@<Outer definitions@>;
-@<Global variables and types@>@;
-@<Auxiliary function declarations@>@;
@<Auxiliary function definitions@>@;
int main( int argc, char **argv ) {
@@ -64,9 +66,13 @@ int main( int argc, char **argv ) {
}
+ fprintf( stderr, "Outputting tables and actions\n" );
+
if ( tables_out ) {
+ fprintf( stderr, " tables ... " );
@<Perform output@>@;
+ fprintf( stderr, "actions ... " );
@<Output action switch, if any@>@;
} else {
@@ -76,6 +82,8 @@ int main( int argc, char **argv ) {
}
+ fprintf( stderr, "done, cleaning up\n" );
+
@<Clean up@>@;
return 0;
@@ -122,7 +130,7 @@ example, the |yyrthree| array, which is necessary for processing
mentioned in the previous sentence. There does not seem to be any
other way to access this information. A number of tools (GNU and
otherwise) have taken the path of narrowing the field of application
-to a few use cases invisioned by the maintainers. This includes
+to a few use cases envisioned by the maintainers. This includes
compilers, as well.
There is a strange
@@ -228,8 +236,8 @@ is to provide a general pattern.
static int optimize_tables = 0;
@ It is set using the command line option below.
-@<Raw option list@>=
- _register_option("optimize-tables", no_argument, &optimize_tables, 1, "")@;
+@<Options without arguments@>=
+ register_option_("optimize-tables", no_argument, &optimize_tables, 1, "")@;
@ The reason to implement the table output routine as a macro is to avoid
writing separate functions for tables of different types of data
@@ -408,9 +416,9 @@ the processing of the action code.
The last argument of the `flexible' macro below is supposed to be an
extended description of each option which can be later utilized by a
|usage()| function.
-@<Raw option list@>=
- _register_option("bare-actions", no_argument, &bare_actions, 1, "")@;
- _register_option("optimize-actions", no_argument, &optimize_actions, 1, "")@;
+@<Options without arguments@>=
+ register_option_("bare-actions", no_argument, &bare_actions, 1, "")@;
+ register_option_("optimize-actions", no_argument, &optimize_actions, 1, "")@;
@ The rest of the action output code mimics that for table output, starting with
the descriptor. To make the output format more flexible, this
@@ -470,11 +478,21 @@ macros which produces undesirable typesetting artefacts.}.
@d TeXf( string ) TeX_( string )
@d TeXfo( string ) TeX_( string )
@d TeXao( string ) TeX_( string )
+@d YY_FATAL_ERROR( message ) fprintf( tables_out, " /yylexcomplain{%s}/yylexerrterminate%%\n", message )
@q \CWEB\ is not aware of variadic macros, so this has to be done the old way@>
@<\Cee\ preamble@>=
#define TeX__( string, ... ) @[fprintf( tables_out, " " string "%s\n", __VA_ARGS__, "%" )@]
+@ If a full parser is not needed, the lexing mechanism is not required. To satisfy the compiler
+and the linker, the lexer and other functions still have to be declared and defined, since these functions
+are referred to in the body of the parser. The details of these declarations can be found in the driver
+code.
+@<\Cee\ preamble@>=
+ @<Outer definitions@>;
+ @<Global variables and types@>@;
+ @<Auxiliary function declarations@>@;
+
@ We begin with a few macros to facilitate the output
of tables in the format that \TeX\ can understand. As there is no
perfect way to represent an array in \TeX\ a rather weak compromise
@@ -710,7 +728,7 @@ specific cases are added to in the course of adding new features.
FOREVER {
- c = getopt_long (argc, argv, ":" @<Short option list@>, long_options, &option_index);
+ c = getopt_long (argc, argv, ( char [] ){':'@t, @>@<Short option list@>}, long_options, &option_index);
if (c == -1) break;
@@ -763,9 +781,11 @@ specific cases are added to in the course of adding new features.
}
@ @<Long options array@>=
-#define _register_option(name, arg_flag, loc, val, exp) @[{name, arg_flag, loc, val},@[@]@]
- @<Raw option list@>@;
-#undef _register_option
+#define register_option_(name, arg_flag, loc, val, exp) @[{name, arg_flag, loc, val},@[@]@]
+ @<Options without shortcuts@>@;
+ @<Options with shortcuts@>@;
+ @<Options without arguments@>@;
+#undef register_option_
@ In addition to spelling out the full command line option name (such
as \.{--help}) |getopt_long| gives the user a choice of using a
@@ -775,12 +795,28 @@ this section (and a number of others) empty to be filled in with the
driver specific code to pacify \CWEAVE.
@<Short option list@>=
+#define dd_optional_argument @[@[@], ':', ':'@]
+#define dd_required_argument @[@[@], ':'@]
+#define dd_no_argument
+#define register_option_(name, arg_flag, loc, val, ...) @[@[@], val dd_##arg_flag@]
+ @<Options with shortcuts@>@;
+#undef register_option_
+#undef dd_optional_argument
+#undef dd_required_argument
+#undef dd_no_argument
@ Some options have one-letter `shortcuts', whereas others only exist
in `fully spelled-out' form. To easily keep track of the latter, a
special enumerated list is declared. To add to this list, simply add
to the \CWEB\ section below.
@<Higher index options@>=
+#define register_option_(name, arg_flag, loc, val, ...) @[val,@[@]@]
+ @<Options without shortcuts@>@;
+#undef register_option_
+
+@ @<Options with shortcuts@>=
+
+@ @<Options without shortcuts@>=
@ @<Cases affecting the whole program@>=