summaryrefslogtreecommitdiff
path: root/support/splint/cweb/np.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/np.w
parentfdb18507cd80dc17f5a5256153d34668b4f4e61c (diff)
CTAN sync 202010120303
Diffstat (limited to 'support/splint/cweb/np.w')
-rw-r--r--support/splint/cweb/np.w141
1 files changed, 91 insertions, 50 deletions
diff --git a/support/splint/cweb/np.w b/support/splint/cweb/np.w
index aa20e551c7..58379649a5 100644
--- a/support/splint/cweb/np.w
+++ b/support/splint/cweb/np.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,8 +14,8 @@
@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/>.@>
-@*1 The name parser. What follows is an example parser for the name
-processing. This approach (i.e. using a `full blown' parser/scanner
+@** The name parser. What follows is an example parser for the term
+name processing. This approach (i.e. using a `full blown' parser/scanner
combination) is probably not the best way to implement such machinery
but its main purpose is to demonstrate a way to create a separate
parser for local purposes.
@@ -51,17 +51,18 @@ parser for local purposes.
@G
%token PERCENT_IDENTIFIER
%token IDENTIFIER
-%token OPTIONAL
-%token NO_ATTR
+%token OPTIONAL NO_ATTR EXTENDED LT RT
%token INTEGER
-%token EXTENDED
-%token WILDCARD
+%token WILDCARD C_ESCCHAR
+%token META_IDENTIFIER
@g
@ @<Parser productions@>=
@G
full_name:
identifier_string suffixes.opt {@> @<Compose the full name@> @=}
+| META_IDENTIFIER {@> @<Turn a \prodstylens{META\_IDENTIFIER}{\smallnamespace} into a full name@> @=}
+| quoted_name suffixes.opt {@> @<Compose the full name@> @=}
;
identifier_string:
@@ -69,17 +70,24 @@ identifier_string:
| IDENTIFIER {@> @<Start with an identifier@> @=}
| '<' IDENTIFIER '>' {@> @<Start with a tag@> @=}
| '\'' WILDCARD '\'' {@> @<Start with a quoted string@> @=}
+| '\'' C_ESCCHAR '\'' {@> @<Start with an escaped character@> @=}
| '\'' '>' '\'' {@> @<Start with a \prodstyle{'>'} string@> @=}
| '\'' '<' '\'' {@> @<Start with a \prodstyle{'<'} string@> @=}
| '\'' '.' '\'' {@> @<Start with a \prodstyle{'.'} string@> @=}
| '\'' '_' '\'' {@> @<Start with an \prodstyle{'\_'} string@> @=}
| '\'' '-' '\'' {@> @<Start with a \prodstyle{'-'} string@> @=}
+| '\'' '$' '\'' {@> @<Start with a \prodstyle{'\$'} string@> @=}
+| '$' {@> @<Prepare a \bison\ stack name@> @=}
| qualifier {@> @<Turn a qualifier into an identifier@> @=}
| identifier_string IDENTIFIER {@> @<Attach an identifier@> @=}
| identifier_string qualifier {@> @<Attach qualifier to a name@> @=}
| identifier_string INTEGER {@> @<Attach an integer@> @=}
;
+quoted_name:
+ '\"' PERCENT_IDENTIFIER '\"' {@> @<Process quoted option@> @=}
+| '\"' IDENTIFIER '\"' {@> @<Process quoted name@> @=}
+;
suffixes.opt:
{@> TeX_( "/yy0{}" ); @=}
| '.' {@> TeX_( "/yy0{/nx/dotsp/nx/sfxnone}" ); @=}
@@ -102,16 +110,24 @@ qualified_suffixes:
| qualifier {@> @<Start suffixes with a qualifier@> @=}
;
+@t}\vb{\inline\flatten}{@>
qualifier:
OPTIONAL {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
| NO_ATTR {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
| EXTENDED {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
+| LT {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
+| RT {@> TeX_( "/yy0{/the/yy(1)}" ); @=}
;
@g
@ @<Compose the full name@>=
@[TeX_( "/yy0{/the/yy(1)/the/yy(2)}/namechars/yyval" );@]@;
+@ @<Turn a \prodstylens{META\_IDENTIFIER}{\smallnamespace} into a full name@>=
+ @[TeX_( "/getfirst{/yy(1)}/to/toksa" );@]@;
+ @[TeX_( "/getsecond{/yy(1)}/to/toksb" );@]@;
+ @[TeX_( "/yy0{/nx/idstr{/the/toksa}{/the/toksb}}/namechars/yyval" );@]@;
+
@ @<Attach option name@>=
@[TeX_( "/getfirst{/yy(1)}/to/toksa" );@]@;
@[TeX_( "/getsecond{/yy(1)}/to/toksb" );@]@;
@@ -130,22 +146,33 @@ qualifier:
@ @<Start with a quoted string@>=
@[TeX_( "/getfirst{/yy(2)}/to/toksa" );@]@;
@[TeX_( "/getsecond{/yy(2)}/to/toksb" );@]@;
- @[TeX_( "/yy0{/nx/chstr{/the/toksa}{/the/toksb}}" );@]@;
+ @[TeX_( "/sansfirst/toksb" );@]@;
+ @[TeX_( "/yy0{/nx/chstr{/the/toksb}{/the/toksb}/nx/visflag{/nx/termvstring}{}}" );@]@;
+
+@ @<Start with an escaped character@>=
+ @[TeX_( "/getsecond{/yy(2)}/to/toksb" );@]@;
+ @[TeX_( "/yy0{/nx/chstr{/the/toksb}{/the/toksb}/nx/visflag{/nx/termvstring}{}}" );@]@;
@ @<Start with a \prodstyle{'<'} string@>=
- @[TeX_( "/yy0{/nx/chstr{<}{<}}" );@]@;
+ @[TeX_( "/yy0{/nx/chstr{<}{<}/nx/visflag{/nx/termvstring}{}}" );@]@;
@ @<Start with a \prodstyle{'>'} string@>=
- @[TeX_( "/yy0{/nx/chstr{/greaterthan}{/greaterthan}}" );@]@;
+ @[TeX_( "/yy0{/nx/chstr{/greaterthan}{/greaterthan}/nx/visflag{/nx/termvstring}{}}" );@]@;
@ @<Start with an \prodstyle{'\_'} string@>=
- @[TeX_( "/yy0{/nx/chstr{/uscoreletter}{/uscoreletter}}" );@]@;
+ @[TeX_( "/yy0{/nx/chstr{/uscoreletter}{/uscoreletter}/nx/visflag{/nx/termvstring}{}}" );@]@;
@ @<Start with a \prodstyle{'-'} string@>=
- @[TeX_( "/yy0{/nx/chstr{-}{-}}" );@]@;
+ @[TeX_( "/yy0{/nx/chstr{-}{-}/nx/visflag{/nx/termvstring}{}}" );@]@;
+
+@ @<Start with a \prodstyle{'\$'} string@>=
+ @[TeX_( "/yy0{/nx/chstr{/safemath}{/safemath}/nx/visflag{/nx/termvstring}{}}" );@]@;
@ @<Start with a \prodstyle{'.'} string@>=
- @[TeX_( "/yy0{/nx/chstr{.}{.}}" );@]@;
+ @[TeX_( "/yy0{/nx/chstr{.}{.}/nx/visflag{/nx/termvstring}{}}" );@]@;
+
+@ @<Prepare a \bison\ stack name@>=
+ @[TeX_( "/yy0{/nx/bidstr{/nx/$}{/safemath}}" );@]@;
@ @<Turn a qualifier into an identifier@>=
@<Start with an identifier@>@;
@@ -164,9 +191,29 @@ qualifier:
@ @<Attach qualifier to a name@>=
@<Attach an identifier@>
-@ @<Attach an integer@>=
- @<Attach an identifier@>@;
+@ An integer at the end of an identifier (such as |id1|) is
+interpreted as a suffix (similar to the way \MF\ treats identifiers,
+and \mft\ typesets them\footnote{This allows, for example, names like
+|$[term0]| while leaving |$[char2int]| in its `natural' form.}) to
+mitigate a well-intentioned but surprisingly inconvenient feature of
+\CTANGLE, namely outputting something like \.{id.1} as \.{id\ .1} in an
+attempt to make sure that integers do not interfere with structure
+dereferences. For this to produce meaningful results, a stricter
+interpretation of \prodstyle{IDENTIFIER} syntax is required,
+represented by the \.{id\_strict} syntax below.
+@<Attach an integer@>=
+ @[TeX_( "/yy0{/the/yy(1)/nx/dotsp/nx/sfxi/the/yy(2)}" );@]@;
+@ @<Process quoted name@>=
+ @[TeX_( "/getfirst{/yy(2)}/to/toksa" );@]@;
+ @[TeX_( "/getsecond{/yy(2)}/to/toksb" );@]@;
+ @[TeX_( "/yy0{/nx/idstr{/the/toksa}{/the/toksb}/nx/visflag{/nx/termvstring}{}}" );@]@;
+
+@ @<Process quoted option@>=
+ @[TeX_( "/getfirst{/yy(2)}/to/toksa" );@]@;
+ @[TeX_( "/getsecond{/yy(2)}/to/toksb" );@]@;
+ @[TeX_( "/yy0{/nx/optstr{/the/toksa}{/the/toksb}/nx/visflag{/nx/termvstring}{}}" );@]@;
+
@ @<Attach suffixes@>=
@[TeX_( "/yy0{/nx/dotsp/the/yy(2)}" );@]@;
@@ -211,8 +258,14 @@ definitions are used.
@<Union of parser types@>=
-@*1 The name scanner.
-%\checktabletrue
+@** The name scanner.
+The scanner for lexing term names is admittedly {\em ad hoc\/} and
+rather redundant. A minor reason for this is to provide some
+flexibility for name typesetting. Another reason is to let the
+existing code serve as a template for similar procedures in other
+projects. At the same time, it must be pointed out that this scanner
+is executed multiple times for every \bison\ section, so its
+efficiency directly affects the speed at which the parser operates.
@(small_lexer.ll@>=
@G
@> @<Lexer definitions@> @=
@@ -230,10 +283,13 @@ void define_all_states( void ) {
@ @<Lexer definitions@>=
@<Lexer states@>@;
-@G
+@G(fs1)
letter [_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]
-wc ([^\\\'\"]{-}[_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9]|\\.)
+c-escchar \\[fnrtv]
+wc ([^\\\'\"$.<>]{-}[_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9]|\\.)
id {letter}({letter}|[-0-9])*
+id_strict {letter}(({letter}|[-0-9])*{letter})?
+meta_id "*"{id_strict}"*"?
int [0-9]+
@g
@@ -268,27 +324,8 @@ int [0-9]+
@<Scan identifiers@>@;
@ White space skipping.
-\traceparserstatestrue
-\tracestackstrue
-\tracerulestrue
-\traceactionstrue
-\tracelookaheadtrue
-\traceparseresultstrue
-\tracebadcharstrue
-\yyflexdebugtrue
-%
-\traceparserstatesfalse
-\tracestacksfalse
-\tracerulesfalse
-\traceactionsfalse
-\tracelookaheadfalse
-\traceparseresultsfalse
-\tracebadcharsfalse
-\yyflexdebugfalse
-%
-\yyskipparsetrue
@<Scan white space@>=
-@G
+@G(fs2)
[ \f\n\t\v] {@> @[TeX_( "/yylexnext" );@]@=}
@g
@@ -297,9 +334,8 @@ 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.
-\yyskipparsefalse % this is not necessary
@<Scan identifiers@>=
-@G
+@G(fs2)
"%binary" {@> @[TeX_( "/yylexreturnval{PERCENT_IDENTIFIER}" );@]@=}
"%code" {@> @[TeX_( "/yylexreturnval{PERCENT_IDENTIFIER}" );@]@=}
"%debug" {@> @[TeX_( "/yylexreturnval{PERCENT_IDENTIFIER}" );@]@=}
@@ -355,26 +391,31 @@ here.
"%pure"[-_]"parser" {@> @[TeX_( "/yylexreturnval{PERCENT_IDENTIFIER}" );@]@=}
"%token"[-_]"table" {@> @[TeX_( "/yylexreturnval{PERCENT_IDENTIFIER}" );@]@=}
"%"({letter}|[0-9]|[-_]|"%"|[<>])+ {@> @[TeX_( "/yylexreturnval{PERCENT_IDENTIFIER}" );@]@=}
-
+@t}\vb{\insertraw{\inscomment{\it suffixes}}}{@>
"opt" {@> @[TeX_( "/yylexreturnval{OPTIONAL}" );@]@=}
"na" {@> @[TeX_( "/yylexreturnval{NO_ATTR}" );@]@=}
"ext" {@> @[TeX_( "/yylexreturnval{EXTENDED}" );@]@=}
-
-[<>._\'] {@> @[TeX_( "/yylexreturnchar" );@]@=}
+"l" {@> @[TeX_( "/yylexreturnval{LT}" );@]@=}
+"r" {@> @[TeX_( "/yylexreturnval{RT}" );@]@=}
+@t}\vb{\insertraw{\inscomment{\it delimeters}}}{@>
+[<>$._\'\"] {@> @[TeX_( "/yylexreturnchar" );@]@=}
+{c-escchar} {@> @[TeX_( "/yylexreturnval{C_ESCCHAR}" );@]@=}
{wc} {@> @[TeX_( "/yylexreturnval{WILDCARD}" );@]@=}
-
-{id} {@> @[@<Prepare to process an identifier@>@]@=}
+@t}\vb{\insertraw{\inscomment{\it identifiers and other names}}}{@>
+{id_strict} {@> @[@<Prepare to process an identifier@>@]@=}
+{meta_id} {@> @[@<Prepare to process a meta-identifier@>@]@=}
{int} {@> @[TeX_( "/yylexreturnval{INTEGER}" );@]@=}
-
-"\"" {@> @[TeX_( "/yylexnext" );@]@=}
+@t}\vb{\insertraw{\inscomment{\it everything else}}}{@>
. {@> @[@<React to a bad character@>@]@=}
@g
@ @<Prepare to process an identifier@>=
@[TeX_( "/yylexreturnval{IDENTIFIER}" );@]@;
+@ @<Prepare to process a meta-identifier@>=
+ @[TeX_( "/yylexreturnval{META_IDENTIFIER}" );@]@;
+
@ @<React to a bad character@>=
@[TeX_( "/iftracebadchars" );@]@;
- @[TeX_( " /yycomplain{invalid character(s): /the/yytext}" );@]@;
+ @[TeX_( " /yyfatal{invalid character(s): /the/yytext}" );@]@;
@[TeX_( "/fi" );@]@;
- @[TeX_( "/yylexreturn{$undefined}" );@]@;