Lines Matching +full:sub +full:- +full:space
3 Mdoc - perl module to parse Mdoc macros
34 def_macro('.Cm', sub { mapwords {'($_)'} @_ } }
77 =item space ( ['on'|'off] )
86 sub { '{', ns, @_, ns, pp('}')}
111 Indicate 'no space' between to members of the list.
132 Print space no matter spacing mode.
165 sub pp {
169 sub gen_encloser {
171 return sub { ($o, ns, @_, ns, pp($c)) };
174 sub mapwords(&@) {
180 $el : $f->();
193 def_macro('Xo', sub { @_ }, concat_until => '.Xc');
195 def_macro('.Ns', sub {ns, @_});
196 def_macro('Ns', sub {ns, @_});
200 def_macro('.Rs', sub { () } );
201 def_macro('.%A', sub {
210 def_macro('.%T', sub { $reference{title} = "@_"; () } );
211 def_macro('.%O', sub { $reference{optional} = "@_"; () } );
213 sub set_Re_callback {
214 my ($sub) = @_;
215 croak 'Not a CODE reference' if not ref $sub eq 'CODE';
216 def_macro('.Re', sub {
217 my @ret = $sub->(\%reference);
224 def_macro('.Bl', sub { die '.Bl - no list callback set' });
225 def_macro('.It', sub { die ".It called outside of list context - maybe near line $." });
226 def_macro('.El', sub { die '.El requires .Bl first' });
230 my $elcb = sub { () };
232 sub set_El_callback {
233 my ($sub) = @_;
234 croak 'Not a CODE reference' if ref $sub ne 'CODE';
235 $elcb = $sub;
239 sub set_Bl_callback {
242 def_macro('.Bl', sub {
250 def_macro('.El', sub {
251 def_macro('.El', delete $orig_el->{run}, %$orig_el);
252 def_macro('.It', delete $orig_it->{run}, %$orig_it);
253 def_macro('.Bl', delete $orig_bl->{run}, %$orig_bl);
254 my @ret = $elcb->(@_);
258 $blcb->(@_)
264 def_macro('.Sm', sub {
267 space($arg);
269 space() eq 'off' ?
270 space('on') :
271 space('off');
275 def_macro('Sm', do { my $off; sub {
293 sub def_macro {
295 my ($macro, $sub, %def) = @_;
296 croak 'Not a CODE reference' if ref $sub ne 'CODE';
299 run => $sub,
305 $macros{ $macros{ $macro }{concat_until} } = { run => sub { @_ } };
311 sub get_macro {
318 sub parse_opts {
322 if ($_ =~ /^\\?-/) {
323 s/^\\?-//;
335 sub _is_control {
338 ref $el eq 'ARRAY' and $el->[0] eq $expected;
348 sub to_string {
366 $_->[1]
378 # space('off') must but one character delayed
385 elsif (_is_control($el, 'spaceon')) { space('on'); }
386 elsif (_is_control($el, 'spacetoggle')) { space() eq 'on' ?
388 space('on') }
398 if ($space_off) { space('off'); $space_off = 0; }
408 sub space { subroutine
421 sub _unquote {
427 sub call_macro {
438 if ($_ =~ /^[A-Z][a-z]+$/ && exists $macros{ $_ }) {
457 ($n_macro, @n_args) = parse_line(undef, sub { push @ret, shift });
471 return $macros{ $macro }{run}->(@ret);
475 return $macros{ $macro }{run}->(@newargs), @ret;
481 sub parse_line {
493 if ($line =~ /^\.[A-z][a-z0-9]+/ || $line =~ /^\.%[A-Z]/ ||
499 $preprocess_sub->(@args) if defined $preprocess_sub;
503 $out_sub->($line);
507 $out_sub->($line);