From: Fred Drake Date: Fri, 27 Mar 1998 05:16:10 +0000 (+0000) Subject: Lots and lots and lots..... X-Git-Tag: v1.5.1~294 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=42b31a5536e167c75c406a72639cac3b0def307c;p=python Lots and lots and lots..... Implemented some new features of python.sty for methods & members. Fixed some bugs. Cleaned up some perl code and made some basic regular expressions more robust. --- diff --git a/Doc/perl/python.perl b/Doc/perl/python.perl index a29220eef9..3536f32d6e 100644 --- a/Doc/perl/python.perl +++ b/Doc/perl/python.perl @@ -104,14 +104,18 @@ sub do_cmd_email{ &use_sans_serif(@_); } sub do_cmd_mimetype{ &use_sans_serif(@_); } sub do_cmd_var{ &use_italics(@_); } -sub do_cmd_dfn{ &use_italics(@_); } +sub do_cmd_dfn{ &use_italics(@_); } # make an index entry? sub do_cmd_emph{ &use_italics(@_); } sub do_cmd_envvar{ local($_) = @_; - s/$next_pair_pr_rx/\$\2/; - $_; + s/$next_pair_pr_rx//; + my($br_id,$envvar) = ($1, $2); + my($name,$aname,$ahref) = link_info($br_id); + add_index_entry("environment variables!$envvar@\$$envvar", $ahref); + add_index_entry("$envvar@\$$envvar", $ahref); + "$aname\$$envvar" . $_; } sub do_cmd_url{ @@ -126,8 +130,8 @@ sub do_cmd_url{ sub do_cmd_manpage{ # two parameters: \manpage{name}{section} local($_) = @_; - my $any_next_pair_pr_rx3 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\3$CP"; - s|$pair_pr_rx$any_next_pair_pr_rx3|\2(\4)|; + my $rx = "$next_pair_pr_rx$any_next_pair_pr_rx3"; + s|$rx|\2(\4)|; $_; } @@ -157,12 +161,9 @@ sub do_cmd_strong{ sub do_cmd_deprecated{ # two parameters: \deprecated{version}{whattodo} local($_) = @_; - my $any_next_pair_pr_rx3 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\3$CP"; - my($release,$action) = ($2, $4); - s/$next_pair_pr_rx$any_next_pair_pr_rx3//; - "Deprecated since release $release." - . "\n$action

" - . $_; + my $rx = "$next_pair_pr_rx$any_next_pair_pr_rx3"; + s|$rx|Deprecated since release \2.\n\4

|; + $_; } # file and samp are at the end of this file since they screw up fontlock. @@ -191,19 +192,75 @@ sub do_cmd_withsubitem{ local($_) = @_; my $any_next_pair_pr_rx3 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\3$CP"; s/$next_pair_pr_rx$any_next_pair_pr_rx3/\4/; + $INDEX_SUBITEM = $2; $_; } sub do_cmd_makemodindex{ @_[0]; } +# We're in the document subdirectory when this happens! +open(IDXFILE, ">index.dat") || die "\n$!\n"; +open(INTLABELS, ">intlabels.pl") || die "\n$!\n"; +print INTLABELS + "%internal_labels = ();\n1; # hack in case there are no entries\n\n"; + +sub gen_target_name{ + "l2h-" . @_[0]; +} + +sub gen_target{ + ""; +} + +sub gen_link{ + my($node,$target) = @_; + print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n"; + ""; +} + +sub make_index_entry{ + my($br_id,$str) = @_; + my($name,$aname,$ahref) = link_info($br_id); + add_index_entry($str, $ahref); + "$aname$anchor_invisible_mark"; +} + +sub add_index_entry{ + # add an entry to the index structures; ignore the return value + my($str,$ahref) = @_; + $str = gen_index_id($str, ''); + $index{$str} .= $ahref; + print IDXFILE $ahref, "\0", $str, "\n"; +} + +sub link_info{ + my $name = gen_target_name(@_[0]); + my $aname = gen_target($name); + my $ahref = gen_link($CURRENT_FILE, $name); + return ($name, $aname, $ahref); +} + +sub do_cmd_index{ + local($_) = @_; + s/$next_pair_pr_rx[\n]?//o; + my($br_id,$str) = ($1, $2); + # + my($name,$aname,$ahref) = link_info($br_id); + add_index_entry("$str", $ahref); + "$aname$anchor_invisible_mark" . $_; +} + sub do_cmd_indexii{ local($_) = @_; s/$next_pair_pr_rx//o; my($br_id1,$str1) = ($1, $2); - s/$next_pair_pr_rx//o; + s/$next_pair_pr_rx[\n]?//o; my($br_id2,$str2) = ($1, $2); - join('', &make_index_entry($br_id1, "$str1 $str2"), - &make_index_entry($br_id2, "$str2, $str1"), $_); + # + my($name,$aname,$ahref) = link_info($br_id1); + add_index_entry("$str1!$str2", $ahref); + add_index_entry("$str2!$str1", $ahref); + "$aname$anchor_invisible_mark" . $_; } sub do_cmd_indexiii{ @@ -212,12 +269,14 @@ sub do_cmd_indexiii{ my($br_id1,$str1) = ($1, $2); s/$next_pair_pr_rx//o; my($br_id2,$str2) = ($1, $2); - s/$next_pair_pr_rx//o; + s/$next_pair_pr_rx[\n]?//o; my($br_id3,$str3) = ($1, $2); - join('', &make_index_entry($br_id1, "$str1 $str2 $str3"), - &make_index_entry($br_id2, "$str2 $str3, $str1"), - &make_index_entry($br_id3, "$str3, $str1 $str2"), - $_); + # + my($name,$aname,$ahref) = link_info($br_id1); + add_index_entry("$str1!$str2 $str3", $ahref); + add_index_entry("$str2!$str3, $str1", $ahref); + add_index_entry("$str3!$str1 $str2", $ahref); + "$aname$anchor_invisible_mark" . $_; } sub do_cmd_indexiv{ @@ -228,28 +287,33 @@ sub do_cmd_indexiv{ my($br_id2,$str2) = ($1, $2); s/$next_pair_pr_rx//o; my($br_id3,$str3) = ($1, $2); - s/$next_pair_pr_rx//o; + s/$next_pair_pr_rx[\n]?//o; my($br_id4,$str4) = ($1, $2); - join('', &make_index_entry($br_id1, "$str1 $str2 $str3 $str4"), - &make_index_entry($br_id2, "$str2 $str3 $str4, $str1"), - &make_index_entry($br_id3, "$str3 $str4, $str1 $str2"), - &make_index_entry($br_id4, "$str4, $str1 $str2 $str3"), - $_); + # + my($name,$aname,$ahref) = link_info($br_id1); + add_index_entry("$str1!$str2 $str3 $str4", $ahref); + add_index_entry("$str2!$str3 $str4, $str1", $ahref); + add_index_entry("$str3!$str4, $str1 $str2", $ahref); + add_index_entry("$str4!$$str1 $str2 $str3", $ahref); + "$aname$anchor_invisible_mark" . $_; } sub do_cmd_ttindex{ local($_) = @_; - s/$next_pair_pr_rx//; + s/$next_pair_pr_rx[\n]?//; my($br_id,$str) = ($1, $2); &make_index_entry($br_id, $str . &get_indexsubitem) . $_; } sub my_typed_index_helper{ local($word,$_) = @_; - s/$next_pair_pr_rx//o; + s/$next_pair_pr_rx[\n]?//o; my($br_id,$str) = ($1, $2); - join('', &make_index_entry($br_id, "$str $word"), - &make_index_entry($br_id, "$word, $str"), $_); + # + my($name,$aname,$ahref) = link_info($br_id1); + add_index_entry("$str $word", $ahref); + add_index_entry("$word!$str", $ahref); + "$aname$anchor_invisible_mark" . $_; } sub do_cmd_stindex{ &my_typed_index_helper('statement', @_); } @@ -259,9 +323,9 @@ sub do_cmd_obindex{ &my_typed_index_helper('object', @_); } sub my_parword_index_helper{ local($word,$_) = @_; - s/$next_pair_pr_rx//o; + s/$next_pair_pr_rx[\n]?//o; my($br_id,$str) = ($1, $2); - &make_index_entry($br_id, "$str ($word)") . $_; + make_index_entry($br_id, "$str ($word)") . $_; } @@ -275,24 +339,24 @@ $STRIP_INDEX_TT = 0; sub make_mod_index_entry{ my($br_id,$str,$define) = @_; - my $halfref = &make_half_href("$CURRENT_FILE#$br_id"); - # If TITLE is not yet available (i.e the \index command is in the title - # of the current section), use $ref_before. - $TITLE = $ref_before unless $TITLE; - # Save the reference + my($name,$aname,$ahref) = link_info($br_id); + $str =~ s|(.*)|\1| + if $STRIP_INDEX_TT; + # equivalent of add_index_entry() using $define instead of '' + $str = gen_index_id($str, $define); + $index{$str} .= $ahref; + print IDXFILE $ahref, "\0", $str, "\n"; + if ($define eq 'DEF') { + # add to the module index my($nstr,$garbage) = split / /, $str, 2; - $Modules{$nstr} .= $halfref; - } - $str = &gen_index_id($str, $define); - if ($STRIP_INDEX_TT) { - $str =~ s|(.*)|\1|; + $Modules{$nstr} .= $ahref; } - $index{$str} .= $halfref; - "$anchor_invisible_mark"; + "$aname$anchor_invisible_mark"; } $THIS_MODULE = ''; +$THIS_CLASS = ''; sub my_module_index_helper{ local($word, $_) = @_; @@ -301,96 +365,70 @@ sub my_module_index_helper{ my $section_tag = join('', @curr_sec_id); $word = "$word " if $word; $THIS_MODULE = "$str"; - &make_mod_index_entry("SECTION$section_tag", - "$str (${word}module)", 'DEF'); - $_; + make_mod_index_entry("SECTION$section_tag", + "$str (${word}module)", 'DEF') . $_; } sub ref_module_index_helper{ local($word, $_) = @_; - s/$next_pair_pr_rx//o; + s/$next_pair_pr_rx[\n]?//o; my($br_id, $str) = ($1, $2); $word = "$word " if $word; - &make_mod_index_entry($br_id, "$str (${word}module)", 'REF') . $_; + make_mod_index_entry($br_id, "$str (${word}module)", 'REF') . $_; } sub do_cmd_bifuncindex{ local($_) = @_; - s/$next_pair_pr_rx//o; + s/$next_pair_pr_rx[\n]?//o; my($br_id,$str,$fname) = ($1, $2, "$2()"); $fname = "$str()" if $STRIP_INDEX_TT; - &make_index_entry($br_id, "$fname (built-in function)") . $_; + make_index_entry($br_id, "$fname (built-in function)") . $_; } -sub do_cmd_modindex{ &my_module_index_helper('', @_); } -sub do_cmd_bimodindex{ &my_module_index_helper('built-in', @_); } -sub do_cmd_exmodindex{ &my_module_index_helper('extension', @_); } -sub do_cmd_stmodindex{ &my_module_index_helper('standard', @_); } +sub do_cmd_modindex{ my_module_index_helper('', @_); } +sub do_cmd_bimodindex{ my_module_index_helper('built-in', @_); } +sub do_cmd_exmodindex{ my_module_index_helper('extension', @_); } +sub do_cmd_stmodindex{ my_module_index_helper('standard', @_); } # these should be adjusted a bit.... -sub do_cmd_refmodindex{ &ref_module_index_helper('', @_); } -sub do_cmd_refbimodindex{ &ref_module_index_helper('built-in', @_); } -sub do_cmd_refexmodindex{ &ref_module_index_helper('extension', @_); } -sub do_cmd_refstmodindex{ &ref_module_index_helper('standard', @_); } +sub do_cmd_refmodindex{ ref_module_index_helper('', @_); } +sub do_cmd_refbimodindex{ ref_module_index_helper('built-in', @_); } +sub do_cmd_refexmodindex{ ref_module_index_helper('extension', @_); } +sub do_cmd_refstmodindex{ ref_module_index_helper('standard', @_); } -sub do_cmd_nodename{ &do_cmd_label(@_); } +sub do_cmd_nodename{ do_cmd_label(@_); } sub init_myformat{ # XXX need some way for this to be called after &initialise; ??? $anchor_mark = ''; $icons{'anchor_mark'} = ''; + my $cmark = "(?:$comment_mark)?"; # <<2>>...<<2>> - $any_next_pair_rx3 = "$O(\\d+)$C([\\s\\S]*)$O\\3$C"; - $any_next_pair_rx5 = "$O(\\d+)$C([\\s\\S]*)$O\\5$C"; - $any_next_pair_rx7 = "$O(\\d+)$C([\\s\\S]*)$O\\7$C"; - $any_next_pair_rx9 = "$O(\\d+)$C([\\s\\S]*)$O\\9$C"; + $next_pair_rx = "^[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\1$C"; + $any_next_pair_rx3 = "[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\3$C"; + $any_next_pair_rx5 = "[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\5$C"; + $any_next_pair_rx7 = "[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\7$C"; + $any_next_pair_rx9 = "[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\9$C"; # <#2#>...<#2#> - $any_next_pair_pr_rx3 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\3$CP"; - $any_next_pair_pr_rx5 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\5$CP"; - $any_next_pair_pr_rx7 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\7$CP"; - $any_next_pair_pr_rx9 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\9$CP"; -# if (defined &process_commands_wrap_deferred) { -# &process_commands_wrap_deferred(<(.*)|\1|; - } - $index{$nstr} .= &make_half_href("$CURRENT_FILE#$br_id"); - "$str"; + my($name,$aname,$ahref) = link_info($br_id); + $str =~ s|(.*)|\1| + if $STRIP_INDEX_TT; + add_index_entry($str, $ahref); + "$aname$str"; } # Changed from the stock version to indent {verbatim} sections, @@ -405,6 +443,8 @@ sub replace_verbatim { } # (Used with LaTeX2HTML 98.1) +# The HTML this produces is bad; the

 is on the outside of the 
, +# but I haven't found a workaround yet. sub replace_verbatim_hook{ # Modifies $_ my($prefix,$suffix) = ("\n

", "
"); @@ -426,13 +466,13 @@ sub do_env_cfuncdesc{ $return_type = "$2"; $function_name = "$4"; $arg_list = "$6"; - $idx = &make_str_index_entry($3, + $idx = make_str_index_entry($3, "$function_name()" . &get_indexsubitem); $idx =~ s/ \(.*\)//; $idx =~ s/\(\)//; } "
$return_type $idx" - . "($arg_list)\n
$'\n
" + . "($arg_list)\n
$'
" } sub do_env_ctypedesc{ @@ -441,11 +481,11 @@ sub do_env_ctypedesc{ my $cfuncdesc_rx = "$next_pair_rx"; if (/$cfuncdesc_rx/o) { $type_name = "$2"; - $idx = &make_str_index_entry($1, + $idx = make_str_index_entry($1, "$type_name" . &get_indexsubitem); $idx =~ s/ \(.*\)//; } - "
$idx\n
$'\n
" + "
$idx\n
$'
" } sub do_env_cvardesc{ @@ -455,12 +495,12 @@ sub do_env_cvardesc{ if (/$cfuncdesc_rx/o) { $var_type = "$2"; $var_name = "$4"; - $idx = &make_str_index_entry($3, + $idx = make_str_index_entry($3, "$var_name" . &get_indexsubitem); $idx =~ s/ \(.*\)//; } "
$var_type $idx\n" - . "
$'\n
"; + . "
$'"; } sub do_env_funcdesc{ @@ -470,12 +510,12 @@ sub do_env_funcdesc{ if (/$funcdesc_rx/o) { $function_name = "$2"; $arg_list = "$4"; - $idx = &make_str_index_entry($3, "$function_name()" + $idx = make_str_index_entry($3, "$function_name()" . &get_indexsubitem); $idx =~ s/ \(.*\)//; $idx =~ s/\(\)//; } - "
$idx ($arg_list)\n
$'\n
"; + "
$idx ($arg_list)\n
$'
"; } sub do_env_funcdescni{ @@ -490,7 +530,7 @@ sub do_env_funcdescni{ else { $idx = "$function_name"; } } - "
$idx ($arg_list)\n
$'\n
"; + "
$idx ($arg_list)\n
$'
"; } sub do_cmd_funcline{ @@ -501,8 +541,8 @@ sub do_cmd_funcline{ my $function_name = $2; s/$next_pair_pr_rx//o; my($br_id,$arg_list) = ($1, $2); - my $idx = &make_str_index_entry($br_id, "$function_name()" - . &get_indexsubitem); + my $idx = make_str_index_entry($br_id, "$function_name()" + . &get_indexsubitem); $idx =~ s/\(\)//; "
$idx ($arg_list)\n
" . $_; @@ -517,13 +557,12 @@ $INDEX_OPCODES = 0; sub do_env_opcodedesc{ local($_) = @_; my($opcode_name,$arg_list,$stuff,$idx) = ('', '', '', ''); - my $any_next_pair_pr_rx3 = "$OP(\\d+)$CP([\\s\\S]*)$OP\\3$CP"; my $opcodedesc_rx = "$next_pair_rx$any_next_pair_rx3"; if (/$opcodedesc_rx/o) { $opcode_name = "$2"; $arg_list = "$4"; if ($INDEX_OPCODES) { - $idx = &make_str_index_entry($3, + $idx = make_str_index_entry($3, "$opcode_name (byte code instruction)"); $idx =~ s/ \(byte code instruction\)//; } @@ -535,17 +574,17 @@ sub do_env_opcodedesc{ if ($arg_list) { $stuff .= "    $arg_list"; } - $stuff . "\n
$'\n"; + $stuff . "\n
$'"; } sub do_env_datadesc{ local($_) = @_; my $idx = ''; if (/$next_pair_rx/o) { - $idx = &make_str_index_entry($1, "$2" . &get_indexsubitem); + $idx = make_str_index_entry($1, "$2" . &get_indexsubitem); $idx =~ s/ \(.*\)//; } - "
$idx\n
$'\n
" + "
$idx\n
$'
" } sub do_env_datadescni{ @@ -557,7 +596,7 @@ sub do_env_datadescni{ else { $idx = "$2"; } } - "
$idx\n
$'\n
" + "
$idx\n
$'
" } sub do_cmd_dataline{ @@ -565,32 +604,110 @@ sub do_cmd_dataline{ s/$next_pair_pr_rx//o; my($br_id, $data_name) = ($1, $2); - my $idx = &make_str_index_entry($br_id, "$data_name" - . &get_indexsubitem); + my $idx = make_str_index_entry($br_id, "$data_name" + . &get_indexsubitem); $idx =~ s/ \(.*\)//; - "
$idx\n
" . $_; + "
$idx
" . $_; } -sub do_env_excdesc{ &do_env_datadesc(@_); } -#sub do_env_classdesc{ &do_env_funcdesc(@_); } -sub do_env_fulllineitems{ &do_env_itemize(@_); } +sub do_env_excdesc{ + local($_) = @_; + /$next_pair_rx/o; + my($br_id,$excname,$rest) = ($1, $2, $'); + my $idx = make_str_index_entry($br_id, + "$excname (exception in $THIS_MODULE)"); + $idx =~ s/ \(.*\)//; + "
$idx\n
$rest
" +} + +sub do_env_fulllineitems{ do_env_itemize(@_); } sub do_env_classdesc{ local($_) = @_; - my($function_name,$arg_list,$idx) = ('', '', ''); + my($class_name,$arg_list,$idx) = ('', '', ''); my $funcdesc_rx = "$next_pair_rx$any_next_pair_rx3"; if (/$funcdesc_rx/o) { - $function_name = "$2"; + $class_name = "$2"; $arg_list = "$4"; - $idx = &make_str_index_entry($3, - "$function_name (class in $THIS_MODULE)" ); + $THIS_CLASS = $class_name; + $idx = make_str_index_entry($3, + "$class_name (class in $THIS_MODULE)" ); + $idx =~ s/ \(.*\)//; + } + "
$idx ($arg_list)\n
$'
"; +} + + +sub do_env_methoddesc{ + local($_) = @_; + my($class_name,$arg_list,$idx,$extra); + # Predefined $opt_arg_rx & $optional_arg_rx don't work because they + # require the argument to be there. + my $opt_arg_rx = "^\\s*(\\[([^]]*)\\])?"; + my $funcdesc_rx = "$opt_arg_rx$any_next_pair_rx3$any_next_pair_rx5"; + if (/$funcdesc_rx/o) { + $class_name = $2; + $class_name = $THIS_CLASS + unless $class_name; + $method_name = $4; + $arg_list = $6; + if ($class_name) { + $extra = " ($class_name method)"; + } + $idx = make_str_index_entry($3, "$method_name()$extra"); $idx =~ s/ \(.*\)//; + $idx =~ s/\(\)//; } - "
$idx ($arg_list)\n
$'\n
"; + "
$idx ($arg_list)\n
$'
"; } + +sub do_env_methoddescni{ + local($_) = @_; + # Predefined $opt_arg_rx & $optional_arg_rx don't work because they + # require the argument to be there. + my $opt_arg_rx = "^\\s*(\\[([^]]*)\\])?"; + my $funcdesc_rx = "$opt_arg_rx$any_next_pair_rx3$any_next_pair_rx5"; + /$funcdesc_rx/o; + my $method = $4; + my $arg_list = $6; + "
$method ($arg_list)\n
$'
"; +} + + +sub do_env_memberdesc{ + local($_) = @_; + # Predefined $opt_arg_rx & $optional_arg_rx don't work because they + # require the argument to be there. + my $opt_arg_rx = "^\\s*(\\[([^]]*)\\])?"; + my $funcdesc_rx = "$opt_arg_rx$any_next_pair_rx3$any_next_pair_rx5"; + /$funcdesc_rx/o; + my($class,$member,$arg_list) = ($2, $4, $6); + $class = $THIS_CLASS + unless $class; + $extra = " ($class_name attribute)" + if $class; + my $idx = make_str_index_entry($3, "$member()$extra"); + $idx =~ s/ \(.*\)//; + $idx =~ s/\(\)//; + "
$idx\n
$'
"; +} + + +sub do_env_memberdescni{ + local($_) = @_; + # Predefined $opt_arg_rx & $optional_arg_rx don't work because they + # require the argument to be there. + my $opt_arg_rx = "^\\s*(\\[([^]]*)\\])?"; + my $funcdesc_rx = "$opt_arg_rx$any_next_pair_rx3"; + /$funcdesc_rx/o; + my $member = $4; + "
$member\n
$'
"; +} + + @col_aligns = ("", "", ""); sub setup_column_alignments{ @@ -620,7 +737,7 @@ sub do_env_tableii{ $h1 = $6; $h2 = $8; } - my($th1,$th2,$th3) = &setup_column_alignments($2); + my($th1,$th2,$th3) = setup_column_alignments($2); $globals{"lineifont"} = $font; "" . "\n $th1$h1" @@ -653,7 +770,7 @@ sub do_env_tableiii{ $h2 = $8; $h3 = $10; } - my($th1,$th2,$th3) = &setup_column_alignments($2); + my($th1,$th2,$th3) = setup_column_alignments($2); $globals{"lineifont"} = $font; "
" . "\n $th1$h1" @@ -742,15 +859,9 @@ sub do_cmd_maketitle { } -sub do_cmd_inputindex{ - local($_) = @_; - s/$next_pair_pr_rx//; - &do_cmd_input($2); -} - -sub do_cmd_indexlabel{ - "genindex" . @_[0]; -} +# sub do_cmd_indexlabel{ +# "genindex" . @_[0]; +# } # These are located down here since they screw up fontlock. -- used to.