develooper Front page | perl.perl5.porters | Postings from November 2017

Re: Signature parsing compiler functions

Thread Previous
November 14, 2017 12:11
Re: Signature parsing compiler functions
Message ID:
Paul "LeoNerd" Evans wrote:
>The idea here being that at the point in syntax where I might encounter
>a signature I can just call the first, and if it returned a non-NULL
>then when I'm about to parse the block I first call the second which
>gives me the initial bit of optree which performs whatever steps are

It's impossible to separate these two phases.  Signatures contain
arbitrary expressions, and the only way to parse them is to generate
their ops.  Presumably you wanted to install op checkers that would
modify the optree as it's built; in fact you'll need to have your op
checkers in place before parsing the signature.

The original implementation of signatures did have a procedural interface
for parsing them:

    OP *parse_subsignature(void);

You call it after lexing the opening "(" of the signature, it parses the
interior, returns with the lexer facing either the ")" or a syntax error,
and returns the ops that perform the argument checking and unwrapping.

My intent was always that that would become an API function, but I didn't
actually mark it as API.  I don't remember the thought process there, but
it was probably just that we hadn't discussed a parsing API as part of the
rapidly-formed consensus on an initial version of signatures, so I didn't
perceive a mandate to add an API function, even on the experimental basis.

parse_subsignature() wasn't merely an orphaned API function, though.
It was the actual implementation, since I'd found it easier to parse
signatures in a recdescent manner than through yacc.  A subsequent edit
(not by me) moved the bulk of the parsing work into the yacc grammar,
and incidentally removed this function.  (And introduced [perl #131777].)

I'd like there to be an API function for procedural code to invoke
signature parsing, and I'm satisfied with the calling convention of the
original parse_subsignature() for that purpose.  Note that it can exist
as an API regardless of which way the parsing is implemented internally.
It is arguable that having such an API function should be a prerequisite
for removing experimental status from signatures, but the other parse_*()
functions are still experimental in their own right.


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About