Analysis and Conversion of 4Test to Perl

I want to convert 4Test scripts to Perl. I am using Parse :: RecDescent in Perl, but I'm still overloaded with this task. Here is an example.

The 4Test example is something like:

ParseSMSPlans (STRING sDir)
{
STRING sFile;
STRING sDirSMSPlan = sDir + "sms_plans\";
STRING sDirPlan = sDir + "plan\";
STRING sDirDeal = sDir + "deal\";
STRING sDirProduct = sDir + "product\";
STRING sLine, sType, sName;
HFILE hIn;
FILEINFO fiFile;
LIST OF FILEINFO lfInfo = SYS_GetDirContents (sDirSMSPlan);
       ...
}

... This is my Parse :: RecDescent Grammar

my $grammar = q{

#-----------------identifiers and datatypes-------------------#

    identifier : /[a-z]\w+/
    binops : '+' | '-' | '/' | '*' | '%' | '**'
    lbinops: '!' | '<' | '>' | '>='| '<='| '&&'| '||' | '=='
    integer: /\d+/ {print "hello $item[-1]" if $::debugging;}
    number : /(\d+|\d*\.\d+)/ {print "hello $item[-1]" if $::debugging;}
    string : /"(([^"]*)(\\")?)*"/
    operation : number binops number operation(s?)
    datatype : /[a-zA-Z]\w*/
    definition : datatype expression(s) #{print "hello $item[-1]" if $::debugging;}
                |datatype expression(s) "=" expression(s) #{print "hello $item[-1] = $item[-2]" if $::debugging;}
    statement : ifexp | elsexp | elseifexp |forexp | feachexp | whexp | swcexp


#------------------Expressed Values-----------------------------#
    program : expression
    expression :  number {print $item[1] if $::debugging}
                | integer
                | assignment
                | operation
                | identifier binops expression
                | number binops expression

#------------------Conditionals---------------------------------------#

    ifexp  : 'if' '(' expression(s) ')' '{' expression(s) '}' elsexp(?)
    elsexp : 'else' '{' expression(s) '}'
    elseifexp: 'else' 'if' '(' expression(s) ')' '{' expression(s) '}'
    forexp : 'for' '(' expression ';' expression ';' expression ')' '{' expression(s)  }'
           | 'for' assignment 'to' number expression(s) | 'for' assignment 'to' number '{' expression(s) '}'
    feachexp : 'for each' expression 'in' expression '{' expression(s) '}'
    whexp  : 'while' '(' expression ')' '{' expression(s) '}'
    casest : 'case' expression(s /,/) ':'
    swcexp : 'switch' identifier '{' casest(s) '}' expression(s) 'default'
    assignment : identifier(s) '=' expression
};

So, I look at adding "$" to each variable name and shredding data types. For the most part, my grammar works, although I have fully tested it yet, but just because Parse :: RecDescent was a little difficult for me to understand, and I'm not sure if this is the best way to complete my task ... or the fastest if on that’s it.

, -, PRD , () ? , .

+3
1

4Test, . 4Test , , , , - , . , 4Test, Perl + 4Test.

0

Source: https://habr.com/ru/post/1759627/


All Articles