Parse::RecDescent解析子名称



我使用模块Parse::RecDescent
并尝试构建语法来捕获perl子名称为什么在我的代码中https://gist.github.com/1595532

不工作grammaget_sub:NOWORD测试

在'>test1$'上?(可变$perl_code1)

use Modern::Perl;
use Parse::RecDescent;
my $perl_code1  = q{my >test1$ string3 = $object->oldSub(6,7);};
my $perl_code2  = q{test1$ string3 = $object->oldSub(6,7);};
my $perl_code3  = q{my test1$ string3 = $object->oldSub(6,7);};
my @perl_lines  = ( $perl_code1, $perl_code2, $perl_code3 );
my $var         = 'test1';
my $sub_grammar = q{
    get_sub: 
           NOWORD TEST NOWORD
               {print $item[2]}      
           |TEST NOWORD
              {print $item[1]}     
    get_sub2: 
           WORD TEST NOWORD
               {print $item[2]}      
           |TEST NOWORD
              {print $item[1]}     
    WORD: 
        /w+/    
    NOWORD: 
        /W+/            
    TEST: 
        /} . $var . q{/
    };
my $sub_parse = new Parse::RecDescent($sub_grammar);
say 'example1:';
for my $string1 (@perl_lines) {
    say "Valid sub:$string1n" if $sub_parse->get_sub($string1);
}
say 'example2:';
for my $string2 (@perl_lines) {
    say " Valid sub:$string2n" if $sub_parse->get_sub2($string2);
}

您的$perl_code1以字符串my开头,该字符串与规则不匹配。你需要在语法中使用以下内容:

get_sub:
       WORD NOWORD TEST NOWORD
           ...

相关内容

  • 没有找到相关文章

最新更新