/usr/share/doc/libparse-recdescent-perl/examples/demo_LaTeXish_autoact.pl is in libparse-recdescent-perl 1.965001+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | use Parse::RecDescent;
#$RD_TRACE = 1;
#$RD_HINT = 1;
my $parser = Parse::RecDescent->new(<<'EOGRAMMAR');
<autoaction: { bless \%item, $item{__RULE__} } >
file: element(s)
element: command | literal
command: '\\' literal options(?) args(?)
options: '[' option(s? /,/) ']'
args: '{' element(s?) '}'
option: /[^][\\$&%#_{}~^ \t\n,]+/
literal: /[^][\\$&%#_{}~^ \t\n]+/
EOGRAMMAR
local $/;
my $tree = $parser->file(<DATA>);
use Data::Dumper 'Dumper';
warn Dumper [ $tree ];
$tree->explain(0);
sub file::explain
{
my ($self, $level) = @_;
for (@{$self->{'element(s)'}})
{
$_->explain($level);
print "\n";
}
}
sub element::explain
{
my ($self, $level) = @_;
($self->{command}||$self->{literal})->explain($level)
}
sub command::explain
{
my ($self, $level) = @_;
print "\t"x$level, "Command: $self->{literal}{__PATTERN1__}\n";
print "\t"x$level, "\tOptions:\n";
$self->{'options(?)'}[0]->explain($level+2) if @{$self->{'options(?)'}};
print "\t"x$level, "\tArgs:\n";
$self->{'args(?)'}[0]->explain($level+2) if @{$self->{'args(?)'}};
}
sub options::explain
{
my ($self, $level) = @_;
$_->explain($level) foreach @{$self->{'option(s?)'}};
}
sub args::explain
{
my ($self, $level) = @_;
$_->explain($level) foreach @{$self->{'element(s?)'}};
}
sub option::explain
{
my ($self, $level) = @_;
print "\t"x$level, "Option: $self->{__PATTERN1__}\n";
}
sub literal::explain
{
my ($self, $level) = @_;
print "\t"x$level, "Literal: $self->{__PATTERN1__}\n";
}
__DATA__
\documentclass[a4paper,11pt]{article}
\usepackage{latexsym}
\author{D. Conway}
\title{Parsing \LaTeX{}}
\begin{document}
\maketitle
\tableofcontents
\section{Description}
...is easy \footnote{But not \emph{necessarily} simple}.
\end{document}
|