Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > ddfdf0b0f2e10c06cbb5bbb1f4ee8dd8 > files > 362

perl-Parse-Eyapp-1.182.0-3.mga4.x86_64.rpm

%%
s:  first '%%' second
;

first:
    A first
  | A
;

second:
    A second
  | A
;

%%

sub Lexer1 {
    my($parser)=shift;

    print "In Lexer 1 \n";
    for (${$parser->YYInput}) {
        m/\G\s*/gc;
        m/\G(%%)/gc and do {
          $parser->YYLexer(\&Lexer2);
          return ($1, undef);
        };
        m/\G(.)/gcs and return($1,$1);
        return('', undef);
    }
}

sub Lexer2 {
    my($parser)=shift;

    print "In Lexer 2 \n";
    for (${$parser->YYInput}) {
        m/\G\s*/gc;
        m/\GB/gc    and return('A','B');
        m/\G(.)/gcs and die "Error. Expected 'B', found $1\n";
    }
        return('', undef);
}

__PACKAGE__->lexer(\&Lexer1);