in reply to howto parse (or determining end) of a line of perl

Why bother?

one line: ...code...;

more than one: ...code...;;

But, to parse perl use PPI/PPIx::XPath ( example Perl::Critic::Policy::ValuesAndExpressions:: GivenWhenTryCatchLexicalDollarUnderDefaultVarBindingConfusion )

$ ppi_dumper 2 PPI::Document PPI::Statement::Compound PPI::Token::Word 'for' PPI::Structure::List ( ... ) PPI::Statement PPI::Token::Number '1' PPI::Token::Operator '..' PPI::Token::Number '10' PPI::Structure::Block { ... ??? $ ppi_dumper 3 PPI::Document PPI::Statement::Compound PPI::Token::Word 'for' PPI::Structure::List ( ... ) PPI::Statement PPI::Token::Number '1' PPI::Token::Operator '..' PPI::Token::Number '10' PPI::Statement::Null PPI::Token::Structure ';' PPI::Token::Whitespace '\n'

So a PPI::Statement::Compound without a closing block parenthesis, means continue

$ cat 2 for(1..10){ $ cat 3 for(1..10);

Replies are listed 'Best First'.
Re^2: howto parse (or determining end) of a line of perl
by perl-diddler (Chaplain) on Aug 25, 2016 at 00:58 UTC
    Yikes!

    Yeah, I could do that... did you catch the part about not rewriting a parser? *sigh*...

    Why do it? I want to be able to enter input and see the result as I can in bash (as an example).

    Sure I can exec code, but then I could print the vars from vars that received an assignment in another statement (all of the user-input code in my calc is done in a separate namespace, so vars in that namespace can be preserved.

    PPI might allow me to do what I want, but it certainly doesn't look like a simple upgrade, but more like a redesign or such...

    thanks for the pointer though, might be usable...

    BTW as far as why I would want to display results after entering a line: remember the prog is still a calculator, like:

    > pcalc pcalc V0.1.8: Type 'constants' to see constants (1)> constants Constants: Phi,Φ,phi,ɸ,pi,π,e,c,g = 1 (2)> sub area($){ my $radius=shift; 4*$radius*pi } (3)> area 1 = 12.566370614359173

      Yikes!

      Exactly!