/usr/share/perl5/Carp/Datum/Parser.y is in libcarp-datum-perl 1:0.1.3-6.
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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | /* -*- Mode: perl -*-
*
* $Id: Parser.y,v 0.1 2001/03/31 10:04:36 ram Exp $
*
* Copyright (c) 2000-2001, Christophe Dehaudt & Raphael Manfredi
*
* You may redistribute only under the terms of the Artistic License,
* as specified in the README file that comes with the distribution.
*
* HISTORY
* $Log: Parser.y,v $
* Revision 0.1 2001/03/31 10:04:36 ram
* Baseline for first Alpha release.
*
* $EndLog$
*/
%{
package Carp::Datum::Parser;
use Carp::Datum::Flags;
BEGIN {
sub TRUE () {1};
sub FALSE () {0};
}
%}
%token FLAGS DEFAULT FILE ROUTINE USE TYPE ALIAS
%token STRING T_WORD T_NUM
%token FLOW REQUIRE ASSERT ENSURE RETURN STACK CLUSTER PANIC PROPAGATE
%token EXEC TRACE EMERGENCY ALERT CRITICAL ERROR
%token AUTOMARK INVARIANT
%token WARNING NOTICE INFO DEBUG TEST DUMP ALL USR1 USR2
%token MEMORY OBJECT STATE STARTUP
%token YES NO LEQ GEQ AS
%token ARGS
%start root
%%
root
:
{
$expect = yy_top;
# allocate the object that is gonna be returned
$result = {};
}
statements
{
$$ = $result;
}
;
statements
: /* empty */
| statements statement
;
statement
: flags_definition
| default_setting
| alias_setting
| file_definition
| cluster_definition
| type_definition
# routine_definition rule is shared.
# Its processing must not always modify the $result variable.
| routine_definition
{
my $new = $1;
if (defined $result->{routine}) {
for my $key (keys %{$new}) {
$result->{routine}->{$key} = $new->{$key};
}
}
else {
$result->{routine} = $new;
}
}
;
flags_definition
: FLAGS ident '{' flags_list '}'
{
if ($4 != 0) {
$result->{define}->{$2} = $4;
}
}
;
default_setting
: DEFAULT ident ';'
{
$result->{default} = {};
if (defined $result->{define}->{$2}) {
merge_flag($result->{default},$result->{define}->{$2});
}
}
| DEFAULT '{' flags_list '}'
{
if ($3 != 0) {
$result->{default} = $3;
}
}
;
alias_setting
: ALIAS STRING AS STRING ';'
{
push @{$result->{alias}}, [$2, $4];
}
file_definition
: FILE string_list '{' flags_or_routines_list '}'
{
if ($4 != 0) {
for my $string (@{$2}) {
$result->{file}->{$string} = $4;
}
}
}
;
cluster_definition
: CLUSTER string_list '{' flags_list '}'
{
if ($4 != 0) {
for my $string (@{$2}) {
$result->{cluster}->{$string}->{flags} = $4;
}
}
}
;
routine_definition
: ROUTINE string_list '{' flags_list '}'
{
my $hash = {};
if ($4 != 0) {
for my $string (@{$2}) {
$hash->{$string}->{flags} = $4;
}
}
$$ = $hash;
}
;
type_definition
: TYPE string_list '{' flags_or_routines_list '}'
{
if ($4 != 0) {
for my $string (@{$2}) {
$result->{type}->{$string} = $4;
}
}
}
;
flags_or_routines_list
: /* empty */ { $$ = 0; }
| flags_or_routines { $$ = $1; }
| flags_or_routines_list flags_or_routines
{
my $current = $1;
my $new = $2;
#
# If new node holds flags, merge them.
#
if (defined $new->{flags}) {
if (defined $current->{flags}) {
merge_flag($current->{flags}, $new->{flags});
}
else {
$current->{flags} = $new->{flags};
}
}
#
# If new node holds routine, merge them.
#
if (defined $new->{routine}) {
if (defined $current->{routine}) {
for my $key (keys %{$new->{routine}}) {
$current->{routine}->{$key} =
$new->{routine}->{$key};
}
}
else {
$current->{routine} = $new->{routine};
}
}
$$ = $current;
}
;
flags_or_routines
: flags_spec ';'
{
my $flag = {};
$flag->{flags} = $1;
$$ = $flag;
}
| routine_definition
{
my $routine = {};
$routine->{routine} = $1;
$$ = $routine;
}
;
flags_list
: /* empty */ { $$ = 0; }
| flags_spec ';' { $$ = $1; }
| flags_list flags_spec ';'
{
my $flag = $1;
my $new = $2;
merge_flag($flag, $new);
$$ = $flag;
}
;
flags_spec
: USE ident_list
{
my $flag = {};
for my $ident (@{$2}) {
if (defined $result->{define}->{$ident}) {
merge_flag($flag, $result->{define}->{$ident});
}
}
$$ = $flag;
}
| trace_spec
{
my $flag = {};
$flag->{trace} = $1;
# If at least one trace flag is set, we need to activate
# tracing. If no flag is set and all are clear, we deactivate
# tracing alltogether.
if ($flag->{trace}->[DTM_SET]) {
$flag->{debug} = [DBG_TRACE, 0];
}
elsif ($flag->{trace}->[DTM_CLEAR] == TRC_ALL) {
$flag->{debug} = [0, DBG_TRACE];
}
$$ = $flag;
}
| flag_spec
{
my $flag = {};
$flag->{debug} = $1;
$$ = $flag;
}
| args_spec
{
my $flag = {};
$flag->{args} = $1;
$$ = $flag;
}
| automark_spec
{
;
}
;
trace_spec
: TRACE '(' yes_or_no ')' trace_flags
{
# create a new flag
$flag = [0, 0];
if ($3) {
$flag->[DTM_SET] = $5;
}
else {
$flag->[DTM_CLEAR] = $5;
}
$$ = $flag;
}
;
trace_flags
: /* empty */ { $$ = TRC_ALL; }
| ':' trace_flag_list { $$ = $2; }
;
trace_flag_list
: trace_flag { $$ = $1; }
| trace_flag_list ',' trace_flag { $$ = $1 | $3; }
;
trace_flag
: trace_flag_token { $$ = $1; }
| cmp_tag trace_flag_token { $$ = &{$1}($2); }
;
cmp_tag
: LEQ { $$ = \&less_or_equal; }
| GEQ { $$ = \&greater_or_equal; }
| '>' { $$ = \&greater; }
| '<' { $$ = \&less; }
;
trace_flag_token
: ALL { $$ = TRC_ALL; }
| EMERGENCY { $$ = TRC_EMERGENCY; }
| ALERT { $$ = TRC_ALERT; }
| CRITICAL { $$ = TRC_CRITICAL; }
| ERROR { $$ = TRC_ERROR; }
| WARNING { $$ = TRC_WARNING; };
| NOTICE { $$ = TRC_NOTICE; }
| INFO { $$ = TRC_INFO; }
| DEBUG { $$ = TRC_DEBUG; }
;
flag_spec
: flag '(' yes_or_no ')'
{
# create a new flag
$flag = [0, 0];
if ($3) {
$flag->[DTM_SET] = $1;
}
else {
$flag->[DTM_CLEAR] = $1;
}
$$ = $flag;
}
;
args_spec
: ARGS '(' args_level ')' { $$ = $3; }
;
args_level
: yes_or_no { $$ = $1 ? -1 : 0; }
| T_NUM { $$ = $1; }
;
automark_spec
: automark_flag
{
;
}
| automark_flag ':' STRING
{
;
}
;
automark_flag
: AUTOMARK '(' yes_or_no ')'
{
;
}
;
yes_or_no
: YES { $$ = TRUE; }
| NO { $$ = FALSE; }
;
flag
: ALL { $$ = DBG_ALL; }
| FLOW { $$ = DBG_FLOW; }
| RETURN { $$ = DBG_RETURN; }
| REQUIRE { $$ = DBG_REQUIRE; }
| ASSERT { $$ = DBG_ASSERT; }
| ENSURE { $$ = DBG_ENSURE; }
| PANIC { $$ = DBG_PANIC; }
| STACK { $$ = DBG_STACK; }
;
ident_list
: ident { $$ = [$1];}
| ident_list ',' ident
{
push @{$1}, $3;
$$ = $1;
}
;
ident
: T_WORD { $$ = $1; }
;
string_list
: string { $$ = [$1]; }
| string_list ',' string
{
push @{$1}, $3;
$$ = $1;
}
;
string
: STRING { $$ = $1; }
;
%%
# Print semantic error
sub yywrong {
my ($msg) = @_;
print STDERR "file $file, line $yylineno: ERROR: $msg\n";
#confess "trace:\n";
yyerror("syntax error");
}
# Print warning
sub yywarn {
my ($msg) = @_;
print STDERR "file $file line $yylineno: WARNING: $msg\n";
}
# Print warning without line number
sub yytell {
my ($msg) = @_;
print STDERR "WARNING: $msg\n";
}
sub yy_lineno {
$yylineno += $yylval =~ tr/\n/\n/;
}
# Print parsing error, trying to give at least next two tokens
sub yyerror {
my ($msg) = @_;
my ($near) = /^\s*(\S+[ \t]*\w*)/;
($near) = /^\s*(\w+[ \t]*\w*)/ if $near eq '';
$near =~ tr/\n\t/ /;
$near =~ tr/ //s;
$near =~ s/\s*$//;
print STDERR "$msg at line $yylineno in file $file";
my ($after) = $yylast =~ /(\w+\s+\w+)$/;
($after) = $yylast =~/(\S+\s*\w+)$/ if $after eq '';
($after) = $yylast =~/(\S+)$/ if $after eq '';
print STDERR " after \"$after\"" unless $after eq '';
print STDERR " near \"$near\"" unless $near eq '';
print STDERR "\n";
die "Abort processing\n";
}
sub yy_top {
&yy_comment if m!/(/|\*)!; # Discard comments
my $kw;
return $kw if defined ($kw = &yy_keyword);
return &yy_dflt;
}
sub yy_skip {
my $in_comment = 0;
$yylval = "";
while ($_ ne '') {
if (!$in_comment) {
my $sp = "";
if ($skip_mode == 0) { # leave what matches for next turn
if (s/^(\s*)($skip_to)/$2/) {
$yylval .= $1;
$sp = $yylval;
$sl = $sp =~ tr/\n/\n/; # Count newlines seen
$yylineno += $sl; # Keep track of line number
return $K_FIND;
}
}
elsif (s/^(\s*)($skip_to)//) {
$yylval .= $1;
$sp = $yylval;
$sl = $sp =~ tr/\n/\n/; # Count newlines seen
$yylineno += $sl; # Keep track of line number
return $K_FIND;
}
}
# skip comment
if (s/^(\/\*)//) {
$in_comment = 1;
$yylval .= $1;
}
if (s/^(.*\*\/)//) {
$in_comment = 0;
$yylval .= $1;
}
s/^(.*)//;
$yylval .= $1;
s/^(\s*)//;
$yylval .= $1;
}
return 0; # Should not reach that point, but if we do...
}
# Strip comment on current lines and subsequent ones, updating $yylineno
# This takes care of comments appearing within lexical parts, whilst global
# ones starting at the beginning of a line are taken care of by &yylex.
# The routine handles both // and /* */ comments.
sub yy_comment {
while (s!^(//.*)!! || s!^(/\*(?:.|\n)*?\*/)!!) {
my $com = $1;
print "yylex: tokener stripped '$com' at line $yylineno\n" if $yydebug;
$yylineno += $com =~ tr/\n/\n/; # Count lines
s/^(\s*)//;
my $sl = $1;
$yylineno += $sl =~ tr/\n/\n/; # Count lines
}
}
sub yy_keyword {
%Keyword = (
'alert' => $ALERT,
'alias' => $ALIAS,
'all' => $ALL,
'args' => $ARGS,
'assert' => $ASSERT,
'automark' => $AUTOMARK,
'cluster' => $CLUSTER,
'critical' => $CRITICAL,
'debug' => $DEBUG,
'default' => $DEFAULT,
'dump' => $DUMP,
'error' => $ERROR,
'emergency' => $EMERGENCY,
'ensure' => $ENSURE,
'exec' => $EXEC,
'file' => $FILE,
'flags' => $FLAGS,
'flow' => $FLOW,
'info' => $INFO,
'memory' => $MEMORY,
'no' => $NO,
'notice' => $NOTICE,
'object' => $OBJECT,
'panic' => $PANIC,
'propagate' => $PROPAGATE,
'require' => $REQUIRE,
'return' => $RETURN,
'routine' => $ROUTINE,
'severe' => $SEVERE,
'stack' => $STACK,
'startup' => $STARTUP,
'state' => $STATE,
'test' => $TEST,
'trace' => $TRACE,
'type' => $TYPE,
'use' => $USE,
'usr1' => $USR1,
'usr2' => $USR2,
'warning' => $WARNING,
'yes' => $YES
) unless defined %Keyword;
return undef unless /^(\w+)/ && exists $Keyword{$1};
my $word = $1;
s/^\w+//;
$yylval = $word;
return $Keyword{$word};
}
sub yy_dflt {
&yy_comment if m!/(/|\*)!; # Discard comments
if (s/^(>=)//) { return $GEQ; }
if (s/^(<=)//) { return $LEQ; }
if (s/^(=>)//) { return $AS; }
# Characters standing for themselves
if (s/^([{}!<>:=;,()\[\]])//) {
return $yylval = ord($1);
}
# Handle special tokens
if (s/^(\*)//) { $yylval = $1; return $T_POINTER }
# handle string
if (s/^\"(.*?)\"//) { $yylval = $1; return $STRING; }
# Handle numbers
if (s/^(0\d+)\b//) { $yylval = oct($1); return $T_NUM; }
if (s/^(0b[01]+)\b//i) { $yylval = bin($1); return $T_NUM }
if (s/^(0x[\da-f]+)\b//i) { $yylval = hex($1); return $T_NUM }
if (s/^(\d+)\b//) { $yylval = int($1); return $T_NUM }
# Words
if (s/^(\w+)//) { $yylval = $1; return $T_WORD }
# Default action: return whatever character we are facing
s/^(.)// and return $yylval = ord($1);
return 0; # Should not reach that point, but if we do...
}
# Lexical parser of the $_ string, along with line count tracking. In order
# to simplify processing of lines, the parsed string must have a leading
# new-line prepended to it before firing off the gramatical analysis.
sub yylex {
my $sp = ''; # Amount of spaces stripped of
my $sl = 0; # True if at the start of a line
if ($expect ne "yy_skip") {
for (;;) {
s/^(\s*)// and $sp = $1; # Spaces are not significant
$sl = $sp =~ tr/\n/\n/; # Count newlines seen
$yylineno += $sl; # Keep track of line number
next if $sl && s|^\s*\//.*\n|\n|; # Skip comments
last;
}
}
if ($yydebug) {
my ($trace) = /^((?:.*)\n*(?:.*)\n*)/m; # Next two lines at most
my $more = length($trace) < length($_) ? "...more...\n" : '';
$trace =~ tr/\n/\n/s; # Avoid succession of new-lines
print "yylex: [line $yylineno] $trace$more";
print "yylex: calling $expect\n";
}
my $ret = $_ ne '' ? &$expect : 0; # 0 signals EOF to yyparse
# Remember last read token for yyerror. Dont forget that it might be
# an ASCII number and convert it back to a char in that case...
$yylast = $yylval eq $ret ? chr($yylval) : $yylval;
$yylast = '<EOF>' unless $ret;
print "yylex: tokener read '$yylast'\n" if $yydebug;
return ($ret, $yylval);
}
sub init_parser {
my ($p) = shift;
$file = shift; # for error message and to store in attribute card info
$yylineno = 0;
}
#################################################################
#
# Routines usefull during the parsing
#
#################################################################
#
# -> merge_flag
#
sub merge_flag {
my ($flag, $new) = @_;
# merge the debug
unless (defined $flag->{debug}) {
$flag->{debug} = [0, 0];
}
if (defined $new->{debug}) {
my $set = ($flag->{debug}->[DTM_SET] &
~$new->{debug}->[DTM_CLEAR]) |
$new->{debug}->[DTM_SET];
my $clear = ($flag->{debug}->[DTM_CLEAR] &
~$new->{debug}->[DTM_SET]) |
$new->{debug}->[DTM_CLEAR];
$flag->{debug}->[DTM_SET] = $set;
$flag->{debug}->[DTM_CLEAR] = $clear;
}
# merge the trace
unless (defined $flag->{trace}) {
$flag->{trace} = [0, 0];
}
if (defined $new->{trace}) {
my $set = ($flag->{trace}->[DTM_SET] &
~$new->{trace}->[DTM_CLEAR]) |
$new->{trace}->[DTM_SET];
my $clear = ($flag->{trace}->[DTM_CLEAR] &
~$new->{trace}->[DTM_SET]) |
$new->{trace}->[DTM_CLEAR];
$flag->{trace}->[DTM_SET] = $set;
$flag->{trace}->[DTM_CLEAR] = $clear;
}
# merge args level
unless (defined $flag->{args}) {
$flag->{args} = -1;
}
if (defined $new->{args}) {
$flag->{args} = $new->{args};
}
}
sub less {
my $flag = shift;
return ($flag - 1);
}
sub less_or_equal {
my $flag = shift;
return less($flag) | $flag;
}
sub greater {
return ~(less_or_equal(@_));
}
sub greater_or_equal {
my $flag = shift;
return greater_or_equal($flag) | $flag;
}
1;
|