App-BatParser

 view release on metacpan or  search on metacpan

lib/App/BatParser.pm  view on Meta::CPAN

package App::BatParser;

use utf8;

use Regexp::Grammars;
use Moo;
use namespace::autoclean;

our $VERSION = '0.011';    # VERSION

# ABSTRACT: Parse DOS .bat and .cmd files

has 'grammar' => (
    is      => 'ro',
    default => sub {
        return qr{
           <nocontext:>
           <File>
    
           <rule: File> (?:<[Lines]>)*

           <rule: Lines> (?: <Comment> | <Label> | <Statement> )\s*\n

           <rule: Comment> \:\:<Text=Token> | REM <Text=Token>

           <rule: Label> \:(?!:)<Identifier=LabelIdentifier>[^\n]*

           <rule: Statement> \@?<Command>
           
           <rule: Command> (?: <SpecialCommand> | <SimpleCommand=Token> )

           <rule: SpecialCommand> <If> | <Call> | <For> | <Goto> | <Set> | <Echo>

           <rule: Echo> echo (?:<EchoModifier> | <Message=Token>)

           <rule: EchoModifier> off

           <rule: If> If (?:<NegatedCondition> | <Condition>) <Statement>

           <rule: Condition> <Exists> | <Comparison>

           <rule: NegatedCondition> NOT <Condition>

           <rule: Exists> EXIST <Path>

           <rule: Comparison> <LeftOperand=Literal> <Operator> <RightOperand=Literal>

           <rule: Call> call <Token>

           <rule: Goto> Goto :?<Identifier=LabelIdentifier>

           <rule: Set> set <Variable=Token>=<Value=Token>

           <rule: For> for <Token> (?:\s+DO\s+) <Statement>

           <token: Operator> NEQ | EQU | GTR | == | LSS | LEQ | GEQ

           <token: Path> [^:\n\s]+

           <token: Literal> [^\s]+

           <token: Token> [^\n]*?
           
           <token: LabelIdentifier> [^\n\s\:]*

        }xmi;
    }



( run in 1.094 second using v1.01-cache-2.11-cpan-39bf76dae61 )