/usr/share/perl5/Data/Stag/SxprParser.pm is in libdata-stag-perl 0.11-2.
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | # $Id: SxprParser.pm,v 1.22 2008/06/03 17:31:15 cmungall Exp $
#
# Copyright (C) 2002 Chris Mungall <cjm@fruitfly.org>
#
# See also - http://stag.sourceforge.net
#
# This module is free software.
# You may distribute this module under the same terms as perl itself
package Data::Stag::SxprParser;
=head1 NAME
SxprParser.pm - parses Stag S-expression format
=head1 SYNOPSIS
=cut
=head1 DESCRIPTION
=head1 AUTHOR
=cut
use Exporter;
use Carp;
use FileHandle;
use strict;
use Data::Stag qw(:all);
use base qw(Data::Stag::BaseGenerator Exporter);
use vars qw($VERSION);
$VERSION="0.11";
sub fmtstr {
return 'sxpr';
}
sub parse_fh {
my $self = shift;
my $fh = shift;
my $line_no = 0;
my $state = "init";
my $txt = '';
# c: comment ;
# q: quote (double quote only)
# o: opening tag - after round bracket, before whitespace or ()
# 0: body, or awaiting open or close
while (my $line = <$fh>) {
$line_no++;
while (length($line)) {
my $c = substr($line,0,1,'');
if ($state eq 'init') {
if ($c eq '(') {
# at start - do nothing
$state = 0;
}
elsif ($c eq "'") {
# leading quote is allowed [list constructor in lisp]
# (good for editing in emacs)
next;
$state = 0;
}
elsif ($c =~ /\s/) {
next;
}
elsif ($c eq ';') {
$state = 'c';
}
else {
$self->throw("Line: $line_no\n$line\nExpected \"(\" at start of file");
}
}
$state ne 'init' || $self->throw("assertion error: state=$state");
if ($state eq 'c') { # comment
# newline is the only char that can break out of comments
if ($c eq "\n") {
$state = 0;
}
next;
}
$state ne 'c' || $self->throw("assertion error: state=$state");
if ($state eq 'q') {
if ($c eq '"') {
$state = 0;
}
else {
$txt .= $c;
}
next;
}
$state ne 'q' || $self->throw("assertion error: state=$state");
if ($c eq '"') {
$state = 'q';
next;
}
$state ne 'q' || $self->throw("assertion error: state=$state");
if ($c eq ';') {
# can only open comments when NOT in quotes
$state = 'c';
next;
}
if ($c eq '(') {
if ($state eq 'o') {
if (!$txt) {
$self->throw("Line: $line_no\b$line\ndouble open brackets (( not allowed!");
}
$self->start_event($txt);
$txt = '';
}
$state = 'o';
next;
}
if ($c eq ')') {
if ($state eq 'o') {
if (!$txt) {
$self->throw("Line: $line_no\b$line\n () not allowed!");
}
$self->start_event($txt);
$txt = '';
$self->end_event;
}
else {
if ($txt) {
$self->evbody($txt);
}
$txt = '';
$self->end_event;
}
$state=0;
next;
}
if ($state eq 'o') {
if ($c =~ /\s/) {
# reached last char of start event name
$self->start_event($txt);
$txt = '';
$state = 0;
next;
}
else {
$txt .= $c;
next;
}
}
$state == 0 || $self->throw("assertion error: state=$state");
if ($c =~ /\s/) {
next;
}
$txt .= $c;
next;
}
}
if ($txt =~ /\S/) {
$self->throw("text at end: $txt");
}
}
1;
|