@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@>
@q it under the terms of the GNU General Public License as published by@>
@q the Free Software Foundation, either version 3 of the License, or@>
@q (at your option) any later version.@>
@q SPLinT is distributed in the hope that it will be useful,@>
@q but WITHOUT ANY WARRANTY; without even the implied warranty of@>
@q MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the@>
@q GNU General Public License for more details.@>
@q You should have received a copy of the GNU General Public License@>
@q along with SPLinT. If not, see .@>
@** The name parser for \ld\ term names.
We take a lazy approach to the typeseting of term names for the \ld\
grammar by creating a dedicated parser for name processing. This way
any pattern we notice can be quickly incorporated into our typesetting scheme.
% We include the macros here since this file is intended to be
% included by the documentation `aggregator' so putting bare \TeX\
% at the beginning of the file runs the risk of producing an error
% of having \TeX\ material inside a \Cee\ section.
\genericprettytokens namespace: ldsmall, tokens: {}, correction: lstokenset.sty, host: ldsmall;
@(ld_small_parser.yy@>=
@G Switch to generic mode.
%{@> @ @=%}
@> @ @=
%union {@> @ @=}
%{@> @ @=%}
@> @ @=
%%
@> @ @=
%%
@g
@ To put the new name parser to work, we need to initialize it. The
initialization is done by the macros below. After the initialization
has been completed, the switch command is replaced by the one that
activates the new name parser.
@=
@G(t)
\genericparser
name: ldsmall,
ptables: ld_small_tab.tex,
ltables: ld_small_dfa.tex,
tokens: {},
asetup: {},
dsetup: {},
rsetup: \let\returnexplicitspace\ignoreexplicitspace, % ignore spaces in names
optimization: {};%
\let\otosmallparser\tosmallparser % /* save the old name parser */
\let\tosmallparser\toldsmallparser
\expandafter\let\csname to\stripbrackets\cwebclinknamespace parser\endcsname\tosmallparser %
/* make the name parser handle the typesetting of \Cee\ variables */
@g
@ @=
@G
%token-table
%debug
%start full_name
@g
@ @=
@G
%token PERCENT_IDENTIFIER
%token IDENTIFIER
%token OPTIONAL
%token K_SUFFIX
%token INTEGER
%token EXTENDED
%token WILDCARD
%token META_IDENTIFIER
@g
@*1 The name parser productions. These macros do a bit more than we
need to typeset the term names. Their core is designed to treat
suffixes and prefixes of a certain form in a special way. In addition,
some productions were left in place from the original name parser in
order to be able to refer to, say, \flex\ options in text. The inline
action in one of the rules for \prodstyle{identifier\_string} was
added to adjust the number and the position of the terms so that the
appropriate action can be reused later for
\prodstyle{qualified\_identifier\_string}.
%\tracebadnamestrue
%\tracenamestrue
%\traceparserstatestrue
%\tracestackstrue
%\tracerulestrue
%\traceactionstrue
%\tracelookaheadtrue
%\traceparseresultstrue
%\tracebadcharstrue
%\yyflexdebugtrue
@=
@G
full_name:
identifier_string suffixes.opt {@> @ @=}
| qualifier '_' identifier_string suffixes.opt {@> @ @=}
| META_IDENTIFIER {@> @ @=}
| '\'' {@> @ @=}
;
identifier_string:
PERCENT_IDENTIFIER {@> @ @=}
| IDENTIFIER {@> @ @=}
| '\'' WILDCARD '\'' {@> @ @=}
| '\'' '_' '\'' {@> @ @=}
| '\'' '.' '\'' {@> @ @=}
@t}\vb{\flatten}{@>
| incomplete_identifier_string {} IDENTIFIER {@> @ @=}
;
@t}\vb{\resetf}{@>
incomplete_identifier_string:
'_' {@> TeX_( "/yy0{/nx/idstr{}{}}" );@=}
| identifier_string '_' {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
| qualified_identifier_string '_' {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
;
qualified_identifier_string:
identifier_string '_' qualifier {@> @ @=}
| qualified_identifier_string '_' qualifier {@> @ @=}
;
suffixes.opt:
{@> TeX_( "/yy0{}" ); @=}
| '.' {@> TeX_( "/yy0{/nx/dotsp/nx/sfxnone}" ); @=}
| '.' suffixes {@> @ @=}
| '.' qualified_suffixes {@> @ @=}
| INTEGER {@> @ @=}
| '_' INTEGER {@> @ @=}
| '_' qualifier {@> @ @=}
;
suffixes:
IDENTIFIER {@> @ @=}
| INTEGER {@> @ @=}
| suffixes '.' {@> @ @=}
| suffixes IDENTIFIER {@> @ @=}
| suffixes INTEGER {@> @ @=}
| qualifier '.' {@> TeX_( "/yy0{/nx/sfxn/the/yy(1)/nx/dotsp}" ); @=}
| suffixes qualifier '.' {@> TeX_( "/yy0{/the/yy(1)/nx/sfxn/the/yy(2)/nx/dotsp}" ); @=}
;
qualified_suffixes:
suffixes qualifier {@> @ @=}
| qualifier {@> @ @=}
;
qualifier:
OPTIONAL {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
| K_SUFFIX {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
| EXTENDED {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
;
@g
@ @=
@[TeX_( "/yy0{/the/yy(1)/the/yy(2)}/namechars/yyval" );@]@;
@ @=
@[TeX_( "/getfirst{/yy(1)}/to/toksa/getsecond{/yy(1)}/to/toksb" );@]@;
@[TeX_( "/yy0{/the/yy(3)/the/yy(4)/nx/dotsp/nx/qual{/the/toksa/nx/_}{/the/toksb/uscoreletter}}/namechars/yyval" );@]@;
@ @=
@[TeX_( "/getfirst{/yy(1)}/to/toksa" );@]@;
@[TeX_( "/getsecond{/yy(1)}/to/toksb" );@]@;
@[TeX_( "/yy0{/nx/idstr{/the/toksa}{/the/toksb}}/namechars/yyval" );@]@;
@ @=
@[TeX_( "/yy0{/nx/chstr{'}{'}}/namechars/yyval" );@]@;
@ @=
@[TeX_( "/getfirst{/yy(1)}/to/toksa" );@]@;
@[TeX_( "/getsecond{/yy(1)}/to/toksb" );@]@;
@[TeX_( "/yy0{/nx/optstr{/the/toksa}{/the/toksb}}" );@]@;
@ @=
@[TeX_( "/getfirst{/yy(1)}/to/toksa" );@]@;
@[TeX_( "/getsecond{/yy(1)}/to/toksb" );@]@;
@[TeX_( "/yy0{/nx/idstr{/the/toksa}{/the/toksb}}" );@]@;
@ @=
@[TeX_( "/getfirst{/yy(2)}/to/toksa" );@]@;
@[TeX_( "/getsecond{/yy(2)}/to/toksb" );@]@;
@[TeX_( "/yy0{/nx/idstr{}{}}" );@]@;
@ @=
@[TeX_( "/getfirst{/yy(2)}/to/toksa" );@]@;
@[TeX_( "/getsecond{/yy(2)}/to/toksb" );@]@;
@[TeX_( "/yy0{/nx/visflag{/nx/termvstring}{}/nx/chstr{/the/toksa}{/the/toksb}}" );@]@;
@ @=
@[TeX_( "/yy0{/nx/visflag{/nx/termvstring}{}/nx/chstr{/nx/_}{_}}" );@]@;
@ @=
@[TeX_( "/yy0{/nx/visflag{/nx/termvstring}{}/nx/chstr{.}{.}}" );@]@;
@ @=
@@;
@ @=
@[TeX_( "/getsecond{/yy(1)}/to/toksa" );@]@;
@[TeX_( "/appendr/toksa{/noexpand/_}" );@]@;
@[TeX_( "/getfirst{/yy(3)}/to/toksb" );@]@;
@[TeX_( "/concat/toksa/toksb" );@]@;
@[TeX_( "/getthird{/yy(1)}/to/toksb" );@]@;
@[TeX_( "/appendr/toksb{/uscoreletter}" );@]@;
@[TeX_( "/getsecond{/yy(3)}/to/toksc" );@]@;
@[TeX_( "/concat/toksb/toksc" );@]@;
@[TeX_( "/yy0{/nx/idstr{/the/toksa}{/the/toksb}}" );@]@;
@ @=
@ @=
@[TeX_( "/yy0{/nx/dotsp/nx/sfxi/the/yy(1)}" );@]@;
@ @=
@[TeX_( "/getfirst{/yy(2)}/to/toksa/getsecond{/yy(2)}/to/toksb" );@]@;
@[TeX_( "/yy0{/nx/dotsp/nx/sfxi{/nx/_/the/toksa}{/uscoreletter/the/toksb}}" );@]@;
@ @=
@[TeX_( "/getfirst{/yy(2)}/to/toksa/getsecond{/yy(2)}/to/toksb" );@]@;
@[TeX_( "/yy0{/nx/dotsp/nx/qual{/nx/_/the/toksa}{/uscoreletter/the/toksb}}" );@]@;
@ @=
@[TeX_( "/yy0{/nx/dotsp/the/yy(2)}" );@]@;
@ @=
@@;
@ @=
@[TeX_( "/yy0{/nx/sfxn/the/yy(1)}" );@]@;
@ @=
@[TeX_( "/yy0{/nx/sfxi/the/yy(1)}" );@]@;
@ @=
@[TeX_( "/yy0{/the/yy(1)/nx/dotsp}" );@]@;
@ @=
@[TeX_( "/yy0{/the/yy(1)/nx/sfxi/the/yy(2)}" );@]@;
@ @=
@[TeX_( "/yy0{/the/yy(1)/nx/sfxn/the/yy(2)}" );@]@;
@ @=
@[TeX_( "/yy0{/the/yy(1)/nx/qual/the/yy(2)}" );@]@;
@ @=
@[TeX_( "/yy0{/nx/qual/the/yy(1)}" );@]@;
@ \Cee\ preamble. In this case, there are no `real' actions that our
grammar performs, only \TeX\ output, so this section is empty.
@=
@ \Cee\ postamble. It is tricky to insert function definitions that use \bison's internal types,
as they have to be inserted in a place that is aware of the internal definitions but before said
definitions are used.
@=
#define YYPRINT(file, type, value) @[yyprint (file, type, value)@]
static void yyprint (FILE *file, int type, YYSTYPE value){}
@ Union of types.
@=
@*1 The name scanner.
%\checktabletrue
@(ld_small_lexer.ll@>=
@G
@> @ @=
%{@> @ @=%}
@> @ @=
%%
@> @ @=
%%
@O
void define_all_states( void ) {
@@;
}
@o
@g
@t}\ifbootstrapmode\yyskipparsetrue\fi{@>
@ @=
@@;
@G(fs1)
aletter [a-zA-Z]
letter (_|{aletter})
wc ([^\\\'\"]{-}[_a-zA-Z0-9]|\\.)
id ({aletter}|{aletter}({aletter}|[0-9])*{aletter})
id_strict {letter}(({letter}|[-0-9])*{letter})?
meta_id "*"{id_strict}"*"?
int [0-9]+
@g
@ @=
#define _register_name( name ) @[Define_State( #name, name )@]
/* nothing for now */
#undef _register_name
@ Strings and characters in directives/rules.
@=
@G
%x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
@g
@ @=
#include
#include
@t}\yyskipparsefalse{@>
@ @=
@G
%option bison-bridge
%option noyywrap nounput noinput reentrant
%option noyy_top_state
%option debug
%option stack
%option outfile="ld_small_lexer.c"
@g
@ @=
@@;
@@;
@ White space skipping.
\traceparserstatestrue
\tracestackstrue
\tracerulestrue
\traceactionstrue
\tracelookaheadtrue
\traceparseresultstrue
\tracebadcharstrue
\yyflexdebugtrue
%
%\prodstyle{abc123}
%
\traceparserstatesfalse
\tracestacksfalse
\tracerulesfalse
\traceactionsfalse
\tracelookaheadfalse
\traceparseresultsfalse
\tracebadcharsfalse
\yyflexdebugfalse
%
@=
@G(fs2)
[ \f\n\t\v] {@> @[TeX_( "/yylexnext" );@]@=}
@g
@ This collection of regular expressions might seem redundant, and in
its present state, it certainly is. However, if later on the
typesetting style for some of the keywords would need to be adjusted,
such changes would be easy to implement, since the template is already
here.
@=
@G(fs2)
"%"({aletter}|[0-9]|[-_]|"%"|[<>])+ {@> @[TeX_( "/yylexreturnval{PERCENT_IDENTIFIER}" );@]@=}
"opt" {@> @[TeX_( "/yylexreturnval{OPTIONAL}" );@]@=}
"K" {@> @[TeX_( "/yylexreturnval{K_SUFFIX}" );@]@=}
"ext" {@> @[TeX_( "/yylexreturnval{EXTENDED}" );@]@=}
[\'._] {@> @[TeX_( "/yylexreturnchar" );@]@=}
{wc} {@> @[TeX_( "/yylexreturnval{WILDCARD}" );@]@=}
{id} {@> @[@@]@=}
{meta_id} {@> @[@@]@=}
{int} {@> @[TeX_( "/yylexreturnval{INTEGER}" );@]@=}
"\"" {@> @[TeX_( "/yylexnext" );@]@=}
. {@> @[@@]@=}
@g
@ @=
@[TeX_( "/yylexreturnval{IDENTIFIER}" );@]@;
@ @=
@[TeX_( "/yylexreturnval{META_IDENTIFIER}" );@]@;
@ \let\hostparsernamespace\ldnamespace\yyskipparsefalse A simple routine to detect
trivial scanning problems.
@=
@[TeX_( "/iftracebadchars" );@]@;
@[TeX_( " /yycomplain{invalid character(s): /the/yytext}" );@]@;
@[TeX_( "/fi" );@]@;
@[TeX_( "/yylexreturn{$undefined}" );@]@;