From 77602f2e32a4d9692b29ed1c6a7af41389a7492c Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Fri, 6 Jul 2001 22:43:02 +0000 Subject: Add support for \ulink and hyperlink grammars. do_cmd_verbatiminput(): Write out a text file containing the content of the input file with a .txt extension, and add a link to it at the bottom of the presentation. This easier retrieval of example source code for copy & paste use. --- Doc/perl/python.perl | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 2 deletions(-) diff --git a/Doc/perl/python.perl b/Doc/perl/python.perl index de27a2d..6e2ad3e 100644 --- a/Doc/perl/python.perl +++ b/Doc/perl/python.perl @@ -90,6 +90,8 @@ sub do_cmd_textasciicircum{ '^' . @_[0]; } sub do_cmd_textbar{ '|' . @_[0]; } sub do_cmd_infinity{ '∞' . @_[0]; } sub do_cmd_plusminus{ '±' . @_[0]; } +sub do_cmd_menuselection{ @_[0]; } +sub do_cmd_sub{ ' > ' . @_[0]; } # words typeset in a special way (not in HTML though) @@ -324,6 +326,13 @@ sub do_cmd_rfc{ . "$icon" . $_); } +sub do_cmd_ulink{ + local($_) = @_; + my $text = next_argument(); + my $url = next_argument(); + return "$text" . $_; +} + sub do_cmd_citetitle{ local($_) = @_; my $url = next_optional_argument(); @@ -682,6 +691,135 @@ sub make_str_index_entry{ return "$aname$str"; } + +%TokenToTargetMapping = (); +%DefinedGrammars = (); +%BackpatchGrammarFiles = (); + +sub do_cmd_token{ + local($_) = @_; + my $token = next_argument(); + my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"}; + if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') { + # recursive definition or display-only productionlist + return "$token"; + } + if ($target eq '') { + $target = "<$CURRENT_GRAMMAR><$token>"; + if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) { + print "Adding '$CURRENT_FILE' to back-patch list.\n"; + } + $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1; + } + return "$token" . $_; +} + +sub do_env_productionlist{ + local($_) = @_; + my $lang = next_optional_argument(); + my $filename = "grammar-$lang.txt"; + if ($lang eq '') { + $filename = 'grammar.txt'; + } + local($CURRENT_GRAMMAR) = $lang; + $DefinedGrammars{$lang} .= $_; + return ("
\n" + . "
\n" + . "\n" + . translate_commands(translate_environments($_)) + . "
\n" + . "
\n" + . (($lang eq '*') + ? '' + : ("Download entire grammar as text.\n")) + . "
"); +} + +sub do_cmd_production{ + local($_) = @_; + my $token = next_argument(); + my $defn = next_argument(); + my $lang = $CURRENT_GRAMMAR; + local($CURRENT_TOKEN) = $token; + if ($lang eq '*') { + return ("\n" + . " $token\n" + . "  ::= \n" + . " " + . translate_commands($defn) + . "" + . $_); + } + my $target; + if ($lang eq '') { + $target = "$CURRENT_FILE\#tok-$token"; + } + else { + $target = "$CURRENT_FILE\#tok-$lang-$token"; + } + $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target; + return ("\n" + . " $token\n" + . "  ::= \n" + . " " + . translate_commands($defn) + . "" + . $_); +} + +sub process_grammar_files{ + my $lang; + my $filename; + local($_); + print "process_grammar_files()\n"; + foreach $lang (keys %DefinedGrammars) { + $filename = "grammar-$lang.txt"; + if ($lang eq '*') { + next; + } + if ($lang eq '') { + $filename = 'grammar.txt'; + } + open(GRAMMAR, ">$filename") || die "\n$!\n"; + print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang}); + close(GRAMMAR); + print "Wrote grammar file $filename\n"; + } + my $PATTERN = '<([^>]*)><([^>]*)>'; + foreach $filename (keys %BackpatchGrammarFiles) { + print "\nBack-patching grammar links in $filename\n"; + my $buffer; + open(GRAMMAR, "<$filename") || die "\n$!\n"; + # read all of the file into the buffer + sysread(GRAMMAR, $buffer, 1024*1024); + close(GRAMMAR); + while ($buffer =~ /$PATTERN/) { + my($lang, $token) = ($1, $2); + my $target = $TokenToTargetMapping{"$lang:$token"}; + my $source = "<$lang><$token>"; + $buffer =~ s/$source/$target/g; + } + open(GRAMMAR, ">$filename") || die "\n$!\n"; + print GRAMMAR $buffer; + close(GRAMMAR); + } +} + +sub strip_grammar_markup{ + local($_) = @_; + s/\\production(<<\d+>>)(.+)\1/\n\2 ::= /g; + s/\\token(<<\d+>>)(.+)\1/\2/g; + s/\\e([^a-zA-Z])/\\\1/g; + s/<<\d+>>//g; + s/;SPMgt;/>/g; + s/;SPMlt;/$srcname.txt"); + print MYFILE $text; + close(MYFILE); # # These rewrites convert the raw text to something that will # be properly visible as HTML and also will pass through the @@ -1715,9 +1861,12 @@ sub do_cmd_verbatiminput{ else { $text = 'Could not locate requested file $fname!\n'; } - return ($alltt_start + return ('
'
             . $text
-            . $alltt_end
+            . "
\n
\n" + . "Download as text." + . "\n
\n
" . $_); } -- cgit v0.12