[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp TODO Texinfo/Parser.pm Texinfo/Struc...
From: |
Patrice Dumas |
Subject: |
texinfo/tp TODO Texinfo/Parser.pm Texinfo/Struc... |
Date: |
Mon, 01 Nov 2010 19:18:05 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/11/01 19:18:05
Modified files:
tp : TODO
tp/Texinfo : Parser.pm Structuring.pm
tp/Texinfo/Convert: NodeNameNormalization.pm Text.pm
tp/t : test_utils.pl
Added files:
tp/Texinfo : Commands.pm
Log message:
Add a new modules, Texinfo::Commands to avoid mutual circular
dependencies
between modules. It holds the command definitions, and thus no module
needs to use Texinfo::Parser.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/TODO?cvsroot=texinfo&r1=1.51&r2=1.52
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.140&r2=1.141
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Commands.pm?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/NodeNameNormalization.pm?cvsroot=texinfo&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Text.pm?cvsroot=texinfo&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/test_utils.pl?cvsroot=texinfo&r1=1.43&r2=1.44
Patches:
Index: TODO
===================================================================
RCS file: /sources/texinfo/texinfo/tp/TODO,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- TODO 31 Oct 2010 16:42:33 -0000 1.51
+++ TODO 1 Nov 2010 19:18:04 -0000 1.52
@@ -30,6 +30,8 @@
no warning in
t/19def.t empty_def_arguments
+warn when a @noindent/@indent appears within a paragraph.
+
Also normalize internal nodes as first argument of ref
at_commands_in_refs some_at_commands_in_ref_nodes
Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.140
retrieving revision 1.141
diff -u -b -r1.140 -r1.141
--- Texinfo/Parser.pm 1 Nov 2010 14:46:38 -0000 1.140
+++ Texinfo/Parser.pm 1 Nov 2010 19:18:04 -0000 1.141
@@ -21,7 +21,7 @@
# The organization of the file is the following:
# module definitions.
# default parser state. With explanation of the internal structures.
-# initializations, mostly determination of command types.
+# initializations, determination of command types.
# user visible subroutines.
# internal subroutines, doing the parsing.
# code used to transform a texinfo tree into texinfo text.
@@ -30,14 +30,18 @@
# We need the unicode stuff.
use 5.006;
+use strict;
use Data::Dumper;
+
+# to detect if an encoding may be used to open the files
+use Encode;
+
+# commands definitions
+use Texinfo::Commands;
# to expand file names in @include
use Texinfo::Convert::Text;
# to normalize node name, anchor, float arg, listoffloats and first *ref
argument.
use Texinfo::Convert::NodeNameNormalization;
-# to detect if an encoding may be used to open the files
-use Encode;
-use strict;
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@@ -171,210 +175,26 @@
# fh filehandle for the file
-my %no_brace_commands; # commands never taking braces
-
-foreach my $no_brace_command ('*',' ',"\t","\n",'-', '|', '/',':','!',
- '?','.','@','}','{','\\') {
- $no_brace_commands{$no_brace_command} = 1;
-}
-
-# commands taking a line as argument or no argument.
-# sectioning commands and def* commands are added below.
-# index commands are added dynamically.
-#
-# The values signification is:
-# special: no value and macro expansion, all the line is used, and
-# analysed during parsing (_parse_special_misc_command)
-# lineraw: no value and macro expansion, the line is kept as-is, not
-# analysed
-# skipline: no argument, everything else on the line is skipped
-# skipspace: no argument, following spaces are skipped.
-# noarg: no argument
-# text: the line is parsed as texinfo, and the argument is converted
-# to simple text (in _end_line)
-# line: the line is parsed as texinfo
-# a number: the line is parsed as texinfo and the result should be plain
-# text maybe followed by a comment; the result is analysed
-# during parsing (_parse_line_command_args).
-# The number is an indication of the number of arguments of
-# the command.
-#
-# Beware that @item and @itemx may be like 'line' or 'skipspace' depending
-# on the context.
-my %misc_commands = (
- 'node' => 'line', # special arg
- 'bye' => 'skipline', # no arg
- # set, clear
- 'set' => 'special', # special arg
- 'clear' => 'special', # special arg
- 'unmacro' => 'special',
- # comments
- 'comment' => 'lineraw',
- 'c' => 'lineraw',
- # special
- 'definfoenclose' => 5,
- 'alias' => 3,
- # number of arguments is not known in advance.
- 'columnfractions' => 1,
- # file names
- 'setfilename' => 'text',
- 'verbatiminclude' => 'text',
- 'include' => 'text',
-
- 'raisesections' => 'skipline', # no arg
- 'lowersections' => 'skipline', # no arg
- 'contents' => 'skipline', # no arg
- 'shortcontents' => 'skipline', # no arg
- 'summarycontents' => 'skipline', # no arg
- 'insertcopying' => 'noarg', # no arg
- 'clickstyle' => 'special', # arg should be an @-command
- # more relevant in preamble
- 'setcontentsaftertitlepage' => 'skipline', # no arg
- 'setshortcontentsaftertitlepage' => 'skipline', # no arg
- 'documentencoding' => 'text', # or 1?
- 'novalidate' => 'skipline', # no arg
- 'dircategory' => 'text', # line. Position with regard
- # with direntry is significant
- 'pagesizes' => 'line', # can have 2 args
- # or one? 200mm,150mm 11.5in
- 'finalout' => 'skipline', # no arg
- 'paragraphindent' => 1, # arg none asis
- # or a number and forbids anything else on the line
- 'firstparagraphindent' => 1, # none insert
- 'frenchspacing' => 1, # on off
- 'fonttextsize' => 1, # 10 11
- 'allowcodebreaks' => 1, # false or true
- 'exampleindent' => 1, # asis or a number
- 'footnotestyle' => 1, # end and separate, nothing else on the line
- 'afourpaper' => 'skipline', # no arg
- 'afivepaper' => 'skipline', # no arg
- 'afourlatex' => 'skipline', # no arg
- 'afourwide' => 'skipline', # no arg
- 'headings' => 1, #off on single double singleafter doubleafter
- # interacts with setchapternewpage
- 'setchapternewpage' => 1, # off on odd
-
- # only relevant in TeX, and special
- 'everyheading' => 'lineraw', # @*heading @*footing use @|
- 'everyfooting' => 'lineraw', # + @thispage @thissectionname
- 'evenheading' => 'lineraw', # @thissectionnum @thissection
- 'evenfooting' => 'lineraw', # @thischaptername @thischapternum
- 'oddheading' => 'lineraw', # @thischapter @thistitle @thisfile
- 'oddfooting' => 'lineraw',
-
- 'smallbook' => 'skipline', # no arg
- 'syncodeindex' => 2, # args are index identifiers
- 'synindex' => 2,
- 'defindex' => 1, # one identifier arg
- 'defcodeindex' => 1, # one identifier arg
- 'documentlanguage' => 'text', # language code arg
- 'kbdinputstyle' => 1, # code example distinct
- 'everyheadingmarks' => 1, # top bottom
- 'everyfootingmarks' => 1,
- 'evenheadingmarks' => 1,
- 'oddheadingmarks' => 1,
- 'evenfootingmarks' => 1,
- 'oddfootingmarks' => 1,
- # not valid for info (should be in @iftex)
- 'cropmarks' => 'skipline', # no arg
-
- # formatting
- 'center' => 'line',
- 'printindex' => 1,
- 'listoffloats' => 'line',
- # especially in titlepage
- 'shorttitle' => 'line',
- 'shorttitlepage' => 'line',
- 'settitle' => 'line',
- 'author' => 'line',
- 'subtitle' => 'line',
- 'title' => 'line',
- 'sp' => 1, # numerical arg
- 'page' => 'skipline', # no arg (pagebreak)
- 'need' => 1, # one numerical/real arg
- # formatting
- 'noindent' => 'skipspace', # no arg
- 'indent' => 'skipspace',
- 'exdent' => 'skipspace',
- 'headitem' => 'skipspace',
- 'item' => 'skipspace', # or line, depending on the context
- 'itemx' => 'skipspace',
- 'tab' => 'skipspace',
- # not valid for info (should be in @iftex)
- 'vskip' => 'lineraw', # arg line in TeX
- # obsolete @-commands.
- 'refill' => 'noarg', # no arg (obsolete, to be ignored)
- # Remove spaces and end of lines after the
- # commands? If no, they can lead to empty lines
- 'quote-arg' => 'skipline',
- 'allow-recursion' => 'skipline',
-);
-
-# command with braces. Value is the max number of arguments.
-my %brace_commands;
-
-# accent commands. They may be called with and without braces.
-my %accent_commands;
-
-foreach my $no_arg_command ('TeX','LaTeX','bullet','copyright',
- 'registeredsymbol','dots','enddots','equiv','error','expansion','arrow',
- 'minus','point','print','result','today',
- 'aa','AA','ae','oe','AE','OE','o','O','ss','l','L','DH','dh','TH','th',
- 'exclamdown','questiondown','pounds','ordf','ordm','comma','euro',
- 'geq','leq','tie','textdegree','click',
- 'quotedblleft','quotedblright','quoteleft','quoteright','quotedblbase',
- 'quotesinglbase','guillemetleft','guillemetright','guillemotleft',
- 'guillemotright','guilsinglleft','guilsinglright') {
- $brace_commands{$no_arg_command} = 0;
-}
-
-foreach my $accent_command ('"','~','^','`',"'",',','=',
- 'ringaccent','H','dotaccent','u','ubaraccent',
- 'udotaccent','v','ogonek','tieaccent', 'dotless') {
- $accent_commands{$accent_command} = 1;
- $brace_commands{$accent_command} = 1;
-}
-
-foreach my $one_arg_command ('asis','b','cite','clicksequence','code',
- 'command','ctrl','dfn','dmn','emph','env','file','headitemfont',
- 'i','slanted','sansserif','kbd','key','option','r','samp','sc','strong',
- 't','var', 'w', 'verb', 'indicateurl',
- 'titlefont','hyphenation','anchor') {
- $brace_commands{$one_arg_command} = 1;
-}
-
-# Commands that enclose full texts
-my %context_brace_commands;
-foreach my $context_brace_command ('footnote', 'caption', 'shortcaption',
'math') {
- $context_brace_commands{$context_brace_command} = $context_brace_command;
- $brace_commands{$context_brace_command} = 1;
-}
-
-foreach my $two_arg_command('email','acronym','abbr') {
- $brace_commands{$two_arg_command} = 2;
-}
-
-foreach my $three_arg_command('uref','url','inforef') {
- $brace_commands{$three_arg_command} = 3;
-}
-
-foreach my $five_arg_command('xref','ref','pxref','image') {
- $brace_commands{$five_arg_command} = 5;
-}
-
-
-# commands delimiting blocks, with an @end.
-# Value is either the number of arguments on the line separated by
-# commas or the type of command, 'raw', 'def' or 'multitable'.
-my %block_commands;
-
-# commands that have a possible content before an item
-my %block_item_commands;
+my %no_brace_commands = %Texinfo::Commands::no_brace_commands;
+my %misc_commands = %Texinfo::Commands::misc_commands;
+my %brace_commands = %Texinfo::Commands::brace_commands;
+my %accent_commands = %Texinfo::Commands::accent_commands;
+my %context_brace_commands = %Texinfo::Commands::context_brace_commands;
+my %block_commands = %Texinfo::Commands::block_commands;
+my %block_item_commands = %Texinfo::Commands::block_item_commands;
+my %close_paragraph_commands = %Texinfo::Commands::close_paragraph_commands;
+my %def_map = %Texinfo::Commands::def_map;
+my %def_commands = %Texinfo::Commands::def_commands;
+my %def_aliases = %Texinfo::Commands::def_aliases;
+my %menu_commands = %Texinfo::Commands::menu_commands;
+my %preformatted_commands = %Texinfo::Commands::preformatted_commands;
+my %item_container_commands = %Texinfo::Commands::item_container_commands;
+my %item_line_commands = %Texinfo::Commands::item_line_commands;
+my %deprecated_commands = %Texinfo::Commands::deprecated_commands;
+my %root_commands = %Texinfo::Commands::root_commands;
+my @out_formats = @Texinfo::Commands::out_formats;
-# commands that forces closing an opened paragraph.
-my %close_paragraph_commands;
-# currently not used
# the type of index, f: function, v: variable, t: type
my %index_type_def = (
'f' => ['deffn', 'deftypefn', 'deftypeop', 'defop'],
@@ -389,43 +209,8 @@
}
}
-
-my %def_map = (
- # basic commands.
- # 'arg' and 'argtype' are for everything appearing after the other
- # arguments.
- 'deffn', [ 'category', 'name', 'arg' ],
- 'defvr', [ 'category', 'name' ],
- 'deftypefn', [ 'category', 'type', 'name', 'argtype' ],
- 'deftypeop', [ 'category', 'class' , 'type', 'name', 'argtype' ],
- 'deftypevr', [ 'category', 'type', 'name' ],
- 'defcv', [ 'category', 'class' , 'name' ],
- 'deftypecv', [ 'category', 'class' , 'type', 'name' ],
- 'defop', [ 'category', 'class' , 'name', 'arg' ],
- 'deftp', [ 'category', 'name', 'argtype' ],
- # shortcuts
- # FIXME i18n
- 'defun', {'deffn' => 'Function'},
- 'defmac', {'deffn' => 'Macro'},
- 'defspec', {'deffn' => '{Special Form}'},
- 'defvar', {'defvr' => 'Variable'},
- 'defopt', {'defvr' => '{User Option}'},
- 'deftypefun', {'deftypefn' => 'Function'},
- 'deftypevar', {'deftypevr' => 'Variable'},
- 'defivar', {'defcv' => '{Instance Variable}'},
- 'deftypeivar', {'deftypecv' => '{Instance Variable}'},
- 'defmethod', {'defop' => 'Method'},
- 'deftypemethod', {'deftypeop' => 'Method'},
-);
-
-my %def_commands;
-my %def_aliases;
my %def_prepended_content;
foreach my $def_command(keys %def_map) {
- $block_commands{$def_command} = 'def';
- $misc_commands{$def_command.'x'} = 'line';
- $def_commands{$def_command} = 1;
- $def_commands{$def_command.'x'} = 1;
# prepare what will be prepended when the def command is an alias
if (ref($def_map{$def_command}) eq 'HASH') {
@@ -447,70 +232,9 @@
}
}
-#print STDERR "".Data::Dumper->Dump([\%def_aliases]);
-#print STDERR "".Data::Dumper->Dump([\%def_prepended_content]);
-
-$block_commands{'multitable'} = 'multitable';
-$block_item_commands{'multitable'} = 1;
-
-# block commands in which menu entry and menu comments appear
-my %menu_commands;
-foreach my $menu_command ('menu', 'detailmenu', 'direntry') {
- $menu_commands{$menu_command} = 1;
- $block_commands{$menu_command} = 0;
-};
-
-foreach my $block_command(
- 'cartouche', 'group', 'raggedright', 'flushleft', 'flushright',
- 'titlepage', 'copying', 'documentdescription') {
- $block_commands{$block_command} = 0;
-}
-
-my %preformatted_commands;
-foreach my $preformatted_command(
- 'example', 'smallexample', 'display', 'smalldisplay', 'lisp',
- 'smalllisp', 'format', 'smallformat') {
- $block_commands{$preformatted_command} = 0;
- $preformatted_commands{$preformatted_command} = 1;
-}
-
-my @out_formats = ('html', 'tex', 'xml', 'docbook');
-# macro/rmacro are special
-foreach my $raw_command (@out_formats, 'verbatim',
- 'ignore', 'macro', 'rmacro') {
- $block_commands{$raw_command} = 'raw';
-}
-
-foreach my $command (@out_formats, 'info', 'plaintext') {
- $block_commands{'if' . $command} = 'conditional';
- $block_commands{'ifnot' . $command} = 'conditional';
-}
-
-$block_commands{'ifset'} = 'conditional';
-$block_commands{'ifclear'} = 'conditional';
-
-# 'macro' ?
-foreach my $block_command_one_arg('table', 'ftable', 'vtable',
- 'itemize', 'enumerate', 'quotation', 'small_quotation') {
- $block_commands{$block_command_one_arg} = 1;
- $block_item_commands{$block_command_one_arg} = 1
- unless ($block_command_one_arg =~ /quotation/);
-}
-
$command_index_prefix{'vtable'} = 'v';
$command_index_prefix{'ftable'} = 'f';
-$block_commands{'float'} = 2;
-
-my %item_container_commands;
-foreach my $item_container_command ('itemize', 'enumerate') {
- $item_container_commands{$item_container_command} = 1;
-}
-
-my %item_line_commands;
-foreach my $item_line_command ('table', 'ftable', 'vtable') {
- $item_line_commands{$item_line_command} = 1;
-}
my %type_with_paragraph;
foreach my $type ('before_item', 'text_root', 'document_root',
@@ -518,11 +242,6 @@
$type_with_paragraph{$type} = 1;
}
-my %deprecated_commands = (
- 'ctrl' => '',
- 'allow-recursion' => N__('recursion is always allowed'),
- 'quote-arg' => N__('arguments are quoted by default'),
-);
# key is index name, keys of the reference value are the prefixes.
# value associated with the prefix is 0 if the prefix is not a code-like
@@ -550,45 +269,6 @@
$forbidden_index_name{$other_forbidden_index_name} = 1;
}
-
-# commands that should only appear at the root level and contain up to
-# the next root command. @node and sectioning commands.
-my %root_commands;
-
-foreach my $sectioning_command (
- 'top',
- 'chapter',
- 'unnumbered',
- 'chapheading',
- 'appendix',
- 'section',
- 'unnumberedsec',
- 'heading',
- 'appendixsec',
- 'subsection',
- 'unnumberedsubsec',
- 'subheading',
- 'appendixsubsec',
- 'subsubsection',
- 'unnumberedsubsubsec',
- 'subsubheading',
- 'appendixsubsubsec',
- 'part',
- 'appendixsection',
- 'majorheading',
- 'chapheading',
- 'centerchap'
-) {
- $misc_commands{$sectioning_command} = 'line';
- if ($sectioning_command =~ /heading/) {
- $close_paragraph_commands{$sectioning_command} = 1;
- } else {
- $root_commands{$sectioning_command} = 1;
- }
-}
-
-$root_commands{'node'} = 1;
-
my %default_no_paragraph_commands;
my %begin_line_commands;
Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- Texinfo/Structuring.pm 31 Oct 2010 15:55:10 -0000 1.17
+++ Texinfo/Structuring.pm 1 Nov 2010 19:18:04 -0000 1.18
@@ -24,6 +24,7 @@
use 5.00405;
use strict;
+# for debugging only
use Texinfo::Convert::Text;
use Texinfo::Parser qw(tree_to_texi);
Index: Texinfo/Convert/NodeNameNormalization.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/NodeNameNormalization.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Texinfo/Convert/NodeNameNormalization.pm 29 Oct 2010 19:31:16 -0000
1.2
+++ Texinfo/Convert/NodeNameNormalization.pm 1 Nov 2010 19:18:05 -0000
1.3
@@ -25,8 +25,12 @@
use 5.00405;
use strict;
-use Texinfo::Convert::Text;
use Unicode::Normalize;
+# for the accents definition
+use Texinfo::Commands;
+# reuse some conversion hashes
+use Texinfo::Convert::Text;
+# use the hashes and functions
use Texinfo::Convert::Unicode;
require Exporter;
@@ -37,7 +41,7 @@
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
-# This allows declaration use Texinfo::Covert::Text ':all';
+# This allows declaration use Texinfo::Convert::NodeNameNormalization ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
%EXPORT_TAGS = ( 'all' => [ qw(
@@ -62,11 +66,7 @@
= %Texinfo::Convert::Text::text_no_brace_commands;
$normalize_node_no_brace_commands{'*'} = ' ';
-my %accent_commands;
-foreach my $accent_command
(keys(%Texinfo::Convert::Unicode::unicode_accented_letters),
- 'tieaccent', 'dotless') {
- $accent_commands{$accent_command} = 1;
-}
+my %accent_commands = %Texinfo::Commands::accent_commands;
my %ignored_brace_commands;
foreach my $ignored_brace_command ('xref','ref','pxref','inforef','anchor',
Index: Texinfo/Convert/Text.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Text.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- Texinfo/Convert/Text.pm 27 Oct 2010 22:03:13 -0000 1.10
+++ Texinfo/Convert/Text.pm 1 Nov 2010 19:18:05 -0000 1.11
@@ -22,6 +22,9 @@
use 5.00405;
use strict;
+# accent commands list.
+use Texinfo::Commands;
+
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ISA = qw(Exporter);
@@ -30,7 +33,7 @@
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
-# This allows declaration use Texinfo::Covert::Text ':all';
+# This allows declaration use Texinfo::Convert::Text ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
%EXPORT_TAGS = ( 'all' => [ qw(
@@ -141,12 +144,7 @@
'{', '{',
);
-my %accent_commands;
-foreach my $accent_command ('"','~','^','`',"'",',','=',
- 'ringaccent','H','dotaccent','u','ubaraccent',
- 'udotaccent','v','ogonek','tieaccent', 'dotless') {
- $accent_commands{$accent_command} = 1;
-}
+my %accent_commands = %Texinfo::Commands::accent_commands;
# node?
my %kept_misc_commands;
Index: t/test_utils.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/test_utils.pl,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- t/test_utils.pl 1 Nov 2010 11:40:45 -0000 1.43
+++ t/test_utils.pl 1 Nov 2010 19:18:05 -0000 1.44
@@ -321,7 +321,8 @@
$test_name.' errors');
ok (Data::Compare::Compare($indices, $result_indices{$test_name}),
$test_name.' indices');
- ok (tree_to_texi($result) eq $result_texis{$test_name}, $test_name.'
texi');
+ ok (tree_to_texi($result) eq $result_texis{$test_name},
+ $test_name.' texi');
ok ($converted_text eq $result_texts{$test_name}, $test_name.' text');
#is (tree_to_texi($result), $result_texis{$test_name}, $test_name.' text');
}
Index: Texinfo/Commands.pm
===================================================================
RCS file: Texinfo/Commands.pm
diff -N Texinfo/Commands.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Texinfo/Commands.pm 1 Nov 2010 19:18:04 -0000 1.1
@@ -0,0 +1,381 @@
+# Commands.pm: definition of commands. Common code of other Texinfo modules.
+#
+# Copyright 2010 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Original author: Patrice Dumas <address@hidden>
+# Parts (also from Patrice Dumas) come from texi2html.pl or texi2html.init.
+
+package Texinfo::Commands;
+
+use strict;
+
+# nothing exported.
+require Exporter;
+use vars qw($VERSION);
+$VERSION = '0.01';
+
+# i18n
+sub N__($)
+{
+ return $_[0];
+}
+
+our %no_brace_commands; # commands never taking braces
+
+foreach my $no_brace_command ('*',' ',"\t","\n",'-', '|', '/',':','!',
+ '?','.','@','}','{','\\') {
+ $no_brace_commands{$no_brace_command} = 1;
+}
+
+# commands taking a line as argument or no argument.
+# sectioning commands and def* commands are added below.
+# index commands are added dynamically.
+#
+# The values signification is:
+# special: no value and macro expansion, all the line is used, and
+# analysed during parsing (_parse_special_misc_command)
+# lineraw: no value and macro expansion, the line is kept as-is, not
+# analysed
+# skipline: no argument, everything else on the line is skipped
+# skipspace: no argument, following spaces are skipped.
+# noarg: no argument
+# text: the line is parsed as texinfo, and the argument is converted
+# to simple text (in _end_line)
+# line: the line is parsed as texinfo
+# a number: the line is parsed as texinfo and the result should be plain
+# text maybe followed by a comment; the result is analysed
+# during parsing (_parse_line_command_args).
+# The number is an indication of the number of arguments of
+# the command.
+#
+# Beware that @item and @itemx may be like 'line' or 'skipspace' depending
+# on the context.
+our %misc_commands = (
+ 'node' => 'line', # special arg
+ 'bye' => 'skipline', # no arg
+ # set, clear
+ 'set' => 'special', # special arg
+ 'clear' => 'special', # special arg
+ 'unmacro' => 'special',
+ # comments
+ 'comment' => 'lineraw',
+ 'c' => 'lineraw',
+ # special
+ 'definfoenclose' => 5,
+ 'alias' => 3,
+ # number of arguments is not known in advance.
+ 'columnfractions' => 1,
+ # file names
+ 'setfilename' => 'text',
+ 'verbatiminclude' => 'text',
+ 'include' => 'text',
+
+ 'raisesections' => 'skipline', # no arg
+ 'lowersections' => 'skipline', # no arg
+ 'contents' => 'skipline', # no arg
+ 'shortcontents' => 'skipline', # no arg
+ 'summarycontents' => 'skipline', # no arg
+ 'insertcopying' => 'noarg', # no arg
+ 'clickstyle' => 'special', # arg should be an @-command
+ # more relevant in preamble
+ 'setcontentsaftertitlepage' => 'skipline', # no arg
+ 'setshortcontentsaftertitlepage' => 'skipline', # no arg
+ 'documentencoding' => 'text', # or 1?
+ 'novalidate' => 'skipline', # no arg
+ 'dircategory' => 'text', # line. Position with regard
+ # with direntry is significant
+ 'pagesizes' => 'line', # can have 2 args
+ # or one? 200mm,150mm 11.5in
+ 'finalout' => 'skipline', # no arg
+ 'paragraphindent' => 1, # arg none asis
+ # or a number and forbids anything else on the line
+ 'firstparagraphindent' => 1, # none insert
+ 'frenchspacing' => 1, # on off
+ 'fonttextsize' => 1, # 10 11
+ 'allowcodebreaks' => 1, # false or true
+ 'exampleindent' => 1, # asis or a number
+ 'footnotestyle' => 1, # end and separate, nothing else on the line
+ 'afourpaper' => 'skipline', # no arg
+ 'afivepaper' => 'skipline', # no arg
+ 'afourlatex' => 'skipline', # no arg
+ 'afourwide' => 'skipline', # no arg
+ 'headings' => 1, #off on single double singleafter doubleafter
+ # interacts with setchapternewpage
+ 'setchapternewpage' => 1, # off on odd
+
+ # only relevant in TeX, and special
+ 'everyheading' => 'lineraw', # @*heading @*footing use @|
+ 'everyfooting' => 'lineraw', # + @thispage @thissectionname
+ 'evenheading' => 'lineraw', # @thissectionnum @thissection
+ 'evenfooting' => 'lineraw', # @thischaptername @thischapternum
+ 'oddheading' => 'lineraw', # @thischapter @thistitle @thisfile
+ 'oddfooting' => 'lineraw',
+
+ 'smallbook' => 'skipline', # no arg
+ 'syncodeindex' => 2, # args are index identifiers
+ 'synindex' => 2,
+ 'defindex' => 1, # one identifier arg
+ 'defcodeindex' => 1, # one identifier arg
+ 'documentlanguage' => 'text', # language code arg
+ 'kbdinputstyle' => 1, # code example distinct
+ 'everyheadingmarks' => 1, # top bottom
+ 'everyfootingmarks' => 1,
+ 'evenheadingmarks' => 1,
+ 'oddheadingmarks' => 1,
+ 'evenfootingmarks' => 1,
+ 'oddfootingmarks' => 1,
+ # not valid for info (should be in @iftex)
+ 'cropmarks' => 'skipline', # no arg
+
+ # formatting
+ 'center' => 'line',
+ 'printindex' => 1,
+ 'listoffloats' => 'line',
+ # especially in titlepage
+ 'shorttitle' => 'line',
+ 'shorttitlepage' => 'line',
+ 'settitle' => 'line',
+ 'author' => 'line',
+ 'subtitle' => 'line',
+ 'title' => 'line',
+ 'sp' => 1, # numerical arg
+ 'page' => 'skipline', # no arg (pagebreak)
+ 'need' => 1, # one numerical/real arg
+ # formatting
+ 'noindent' => 'skipspace', # no arg
+ 'indent' => 'skipspace',
+ 'exdent' => 'skipspace',
+ 'headitem' => 'skipspace',
+ 'item' => 'skipspace', # or line, depending on the context
+ 'itemx' => 'skipspace',
+ 'tab' => 'skipspace',
+ # not valid for info (should be in @iftex)
+ 'vskip' => 'lineraw', # arg line in TeX
+ # obsolete @-commands.
+ 'refill' => 'noarg', # no arg (obsolete, to be ignored)
+ # Remove spaces and end of lines after the
+ # commands? If no, they can lead to empty lines
+ 'quote-arg' => 'skipline',
+ 'allow-recursion' => 'skipline',
+);
+
+# command with braces. Value is the max number of arguments.
+our %brace_commands;
+
+
+foreach my $no_arg_command ('TeX','LaTeX','bullet','copyright',
+ 'registeredsymbol','dots','enddots','equiv','error','expansion','arrow',
+ 'minus','point','print','result','today',
+ 'aa','AA','ae','oe','AE','OE','o','O','ss','l','L','DH','dh','TH','th',
+ 'exclamdown','questiondown','pounds','ordf','ordm','comma','euro',
+ 'geq','leq','tie','textdegree','click',
+ 'quotedblleft','quotedblright','quoteleft','quoteright','quotedblbase',
+ 'quotesinglbase','guillemetleft','guillemetright','guillemotleft',
+ 'guillemotright','guilsinglleft','guilsinglright') {
+ $brace_commands{$no_arg_command} = 0;
+}
+
+# accent commands. They may be called with and without braces.
+our %accent_commands;
+foreach my $accent_command ('"','~','^','`',"'",',','=',
+ 'ringaccent','H','dotaccent','u','ubaraccent',
+ 'udotaccent','v','ogonek','tieaccent', 'dotless') {
+ $accent_commands{$accent_command} = 1;
+ $brace_commands{$accent_command} = 1;
+}
+
+foreach my $one_arg_command ('asis','b','cite','clicksequence','code',
+ 'command','ctrl','dfn','dmn','emph','env','file','headitemfont',
+ 'i','slanted','sansserif','kbd','key','option','r','samp','sc','strong',
+ 't','var', 'w', 'verb', 'indicateurl',
+ 'titlefont','hyphenation','anchor') {
+ $brace_commands{$one_arg_command} = 1;
+}
+
+# Commands that enclose full texts
+our %context_brace_commands;
+foreach my $context_brace_command ('footnote', 'caption', 'shortcaption',
'math') {
+ $context_brace_commands{$context_brace_command} = $context_brace_command;
+ $brace_commands{$context_brace_command} = 1;
+}
+
+foreach my $two_arg_command('email','acronym','abbr') {
+ $brace_commands{$two_arg_command} = 2;
+}
+
+foreach my $three_arg_command('uref','url','inforef') {
+ $brace_commands{$three_arg_command} = 3;
+}
+
+foreach my $five_arg_command('xref','ref','pxref','image') {
+ $brace_commands{$five_arg_command} = 5;
+}
+
+
+# commands delimiting blocks, with an @end.
+# Value is either the number of arguments on the line separated by
+# commas or the type of command, 'raw', 'def' or 'multitable'.
+our %block_commands;
+
+# commands that have a possible content before an item
+our %block_item_commands;
+
+# commands that forces closing an opened paragraph.
+our %close_paragraph_commands;
+
+our %def_map = (
+ # basic commands.
+ # 'arg' and 'argtype' are for everything appearing after the other
+ # arguments.
+ 'deffn', [ 'category', 'name', 'arg' ],
+ 'defvr', [ 'category', 'name' ],
+ 'deftypefn', [ 'category', 'type', 'name', 'argtype' ],
+ 'deftypeop', [ 'category', 'class' , 'type', 'name', 'argtype' ],
+ 'deftypevr', [ 'category', 'type', 'name' ],
+ 'defcv', [ 'category', 'class' , 'name' ],
+ 'deftypecv', [ 'category', 'class' , 'type', 'name' ],
+ 'defop', [ 'category', 'class' , 'name', 'arg' ],
+ 'deftp', [ 'category', 'name', 'argtype' ],
+ # shortcuts
+ # FIXME i18n
+ 'defun', {'deffn' => 'Function'},
+ 'defmac', {'deffn' => 'Macro'},
+ 'defspec', {'deffn' => '{Special Form}'},
+ 'defvar', {'defvr' => 'Variable'},
+ 'defopt', {'defvr' => '{User Option}'},
+ 'deftypefun', {'deftypefn' => 'Function'},
+ 'deftypevar', {'deftypevr' => 'Variable'},
+ 'defivar', {'defcv' => '{Instance Variable}'},
+ 'deftypeivar', {'deftypecv' => '{Instance Variable}'},
+ 'defmethod', {'defop' => 'Method'},
+ 'deftypemethod', {'deftypeop' => 'Method'},
+);
+
+our %def_commands;
+our %def_aliases;
+foreach my $def_command(keys %def_map) {
+ $block_commands{$def_command} = 'def';
+ $misc_commands{$def_command.'x'} = 'line';
+ $def_commands{$def_command} = 1;
+ $def_commands{$def_command.'x'} = 1;
+}
+
+#print STDERR "".Data::Dumper->Dump([\%def_aliases]);
+#print STDERR "".Data::Dumper->Dump([\%def_prepended_content]);
+
+$block_commands{'multitable'} = 'multitable';
+$block_item_commands{'multitable'} = 1;
+
+# block commands in which menu entry and menu comments appear
+our %menu_commands;
+foreach my $menu_command ('menu', 'detailmenu', 'direntry') {
+ $menu_commands{$menu_command} = 1;
+ $block_commands{$menu_command} = 0;
+};
+
+foreach my $block_command(
+ 'cartouche', 'group', 'raggedright', 'flushleft', 'flushright',
+ 'titlepage', 'copying', 'documentdescription') {
+ $block_commands{$block_command} = 0;
+}
+
+our %preformatted_commands;
+foreach my $preformatted_command(
+ 'example', 'smallexample', 'display', 'smalldisplay', 'lisp',
+ 'smalllisp', 'format', 'smallformat') {
+ $block_commands{$preformatted_command} = 0;
+ $preformatted_commands{$preformatted_command} = 1;
+}
+
+our @out_formats = ('html', 'tex', 'xml', 'docbook');
+# macro/rmacro are special
+foreach my $raw_command (@out_formats, 'verbatim',
+ 'ignore', 'macro', 'rmacro') {
+ $block_commands{$raw_command} = 'raw';
+}
+
+foreach my $command (@out_formats, 'info', 'plaintext') {
+ $block_commands{'if' . $command} = 'conditional';
+ $block_commands{'ifnot' . $command} = 'conditional';
+}
+
+$block_commands{'ifset'} = 'conditional';
+$block_commands{'ifclear'} = 'conditional';
+
+# 'macro' ?
+foreach my $block_command_one_arg('table', 'ftable', 'vtable',
+ 'itemize', 'enumerate', 'quotation', 'small_quotation') {
+ $block_commands{$block_command_one_arg} = 1;
+ $block_item_commands{$block_command_one_arg} = 1
+ unless ($block_command_one_arg =~ /quotation/);
+}
+
+$block_commands{'float'} = 2;
+
+our %item_container_commands;
+foreach my $item_container_command ('itemize', 'enumerate') {
+ $item_container_commands{$item_container_command} = 1;
+}
+our %item_line_commands;
+foreach my $item_line_command ('table', 'ftable', 'vtable') {
+ $item_line_commands{$item_line_command} = 1;
+}
+
+our %deprecated_commands = (
+ 'ctrl' => '',
+ 'allow-recursion' => N__('recursion is always allowed'),
+ 'quote-arg' => N__('arguments are quoted by default'),
+);
+
+# commands that should only appear at the root level and contain up to
+# the next root command. @node and sectioning commands.
+our %root_commands;
+
+foreach my $sectioning_command (
+ 'top',
+ 'chapter',
+ 'unnumbered',
+ 'chapheading',
+ 'appendix',
+ 'section',
+ 'unnumberedsec',
+ 'heading',
+ 'appendixsec',
+ 'subsection',
+ 'unnumberedsubsec',
+ 'subheading',
+ 'appendixsubsec',
+ 'subsubsection',
+ 'unnumberedsubsubsec',
+ 'subsubheading',
+ 'appendixsubsubsec',
+ 'part',
+ 'appendixsection',
+ 'majorheading',
+ 'chapheading',
+ 'centerchap'
+) {
+ $misc_commands{$sectioning_command} = 'line';
+ if ($sectioning_command =~ /heading/) {
+ $close_paragraph_commands{$sectioning_command} = 1;
+ } else {
+ $root_commands{$sectioning_command} = 1;
+ }
+}
+
+$root_commands{'node'} = 1;
+
+1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp TODO Texinfo/Parser.pm Texinfo/Struc...,
Patrice Dumas <=