Lines Matching +full:sub +full:- +full:space
3 ## Mdoc.pm -- Perl functions for mdoc processing
10 ## AutoOpts is Copyright (C) 1992-2015 by Bruce Korb - all rights reserved
30 Mdoc - perl module to parse Mdoc macros
61 def_macro('.Cm', sub { mapwords {'($_)'} @_ } }
104 =item space ( ['on'|'off] )
113 sub { '{', ns, @_, ns, pp('}')}
138 Indicate 'no space' between to members of the list.
159 Print space no matter spacing mode.
192 sub pp {
196 sub gen_encloser {
198 return sub { ($o, ns, @_, ns, pp($c)) };
201 sub mapwords(&@) {
207 $el : $f->();
220 def_macro('Xo', sub { @_ }, concat_until => '.Xc');
222 def_macro('.Ns', sub {ns, @_});
223 def_macro('Ns', sub {ns, @_});
227 def_macro('.Rs', sub { () } );
228 def_macro('.%A', sub {
237 def_macro('.%T', sub { $reference{title} = "@_"; () } );
238 def_macro('.%O', sub { $reference{optional} = "@_"; () } );
240 sub set_Re_callback {
241 my ($sub) = @_;
242 croak 'Not a CODE reference' if not ref $sub eq 'CODE';
243 def_macro('.Re', sub {
244 my @ret = $sub->(\%reference);
251 def_macro('.Bl', sub { die '.Bl - no list callback set' });
252 def_macro('.It', sub { die ".It called outside of list context - maybe near line $." });
253 def_macro('.El', sub { die '.El requires .Bl first' });
257 my $elcb = sub { () };
259 sub set_El_callback {
260 my ($sub) = @_;
261 croak 'Not a CODE reference' if ref $sub ne 'CODE';
262 $elcb = $sub;
266 sub set_Bl_callback {
269 def_macro('.Bl', sub {
277 def_macro('.El', sub {
278 def_macro('.El', delete $orig_el->{run}, %$orig_el);
279 def_macro('.It', delete $orig_it->{run}, %$orig_it);
280 def_macro('.Bl', delete $orig_bl->{run}, %$orig_bl);
281 my @ret = $elcb->(@_);
285 $blcb->(@_)
291 def_macro('.Sm', sub {
294 space($arg);
296 space() eq 'off' ?
297 space('on') :
298 space('off');
302 def_macro('Sm', do { my $off; sub {
320 sub def_macro {
322 my ($macro, $sub, %def) = @_;
323 croak 'Not a CODE reference' if ref $sub ne 'CODE';
326 run => $sub,
332 $macros{ $macros{ $macro }{concat_until} } = { run => sub { @_ } };
338 sub get_macro {
345 sub parse_opts {
349 if ($_ =~ /^\\?-/) {
350 s/^\\?-//;
362 sub _is_control {
365 ref $el eq 'ARRAY' and $el->[0] eq $expected;
375 sub to_string {
393 $_->[1]
405 # space('off') must but one character delayed
412 elsif (_is_control($el, 'spaceon')) { space('on'); }
413 elsif (_is_control($el, 'spacetoggle')) { space() eq 'on' ?
415 space('on') }
425 if ($space_off) { space('off'); $space_off = 0; }
435 sub space { subroutine
448 sub _unquote {
454 sub call_macro {
465 if ($_ =~ /^[A-Z][a-z]+$/ && exists $macros{ $_ }) {
484 ($n_macro, @n_args) = parse_line(undef, sub { push @ret, shift });
498 return $macros{ $macro }{run}->(@ret);
502 return $macros{ $macro }{run}->(@newargs), @ret;
508 sub parse_line {
520 if ($line =~ /^\.[A-z][a-z0-9]+/ || $line =~ /^\.%[A-Z]/ ||
526 $preprocess_sub->(@args) if defined $preprocess_sub;
530 $out_sub->($line);
534 $out_sub->($line);