Skip Menu |

This queue is for tickets about the Object-Pad CPAN distribution.

Report information
The Basics
Id: 132903
Status: resolved
Priority: 0/
Queue: Object-Pad

People
Owner: Nobody in particular
Requestors: ilmari [...] ilmari.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.31



Subject: One-line "class NAME VERSION extends NAME" doesnt parse
Date: Sun, 28 Jun 2020 23:11:39 +0100
To: bug-Object-Pad [...] rt.cpan.org
From: ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker)
The following does not parse, but complains that it expected a block or a semicolon: class Foo 1.23 extends Bar; Putting a newline before "extends" makes it work. This is because prescan_version() returns an error "Invalid version format (non-numeric data)" when there's anything other than a newline, semicolon or curly brace after the version number. This seems to be because that (and scan_version()) are only prepared to parse the version bit in a "package NAME VERSION" statement, where it must be followed by a semicolon or a block. One workaround could be to scan forward to a space, curly or semicolon manually, then copy the version string into a temporary buffer before handing it to (pre)scan_version(). - ilmari -- - Twitter seems more influential [than blogs] in the 'gets reported in the mainstream press' sense at least. - Matt McLeod - That'd be because the content of a tweet is easier to condense down to a mainstream media article. - Calle Dybedahl
On Sun Jun 28 18:21:34 2020, ilmari@ilmari.org wrote: Show quoted text
> This is because prescan_version() returns an error "Invalid version > format (non-numeric data)" when there's anything other than a newline, > semicolon or curly brace after the version number. This seems to be > because that (and scan_version()) are only prepared to parse the version > bit in a "package NAME VERSION" statement, where it must be followed by > a semicolon or a block.
Huh. I wonder if that should be technically a core bug - should we report it as such? Show quoted text
> One workaround could be to scan forward to a space, curly or semicolon > manually, then copy the version string into a temporary buffer before > handing it to (pre)scan_version().
Yeah that sounds easy enough. -- Paul Evans
On Tue Jun 30 10:37:45 2020, PEVANS wrote: Show quoted text
> > One workaround could be to scan forward to a space, curly or > > semicolon > > manually, then copy the version string into a temporary buffer before > > handing it to (pre)scan_version().
> > Yeah that sounds easy enough.
Seems fairly simple, though now I've basically reïmplemented the version parsing logic somewhat. Hopefully it is sufficient close to core. -- Paul Evans
Subject: rt132903.patch
=== modified file 'hax/lexer-additions.c.inc' --- old/hax/lexer-additions.c.inc 2020-06-15 09:42:01 +0000 +++ new/hax/lexer-additions.c.inc 2020-06-30 14:49:08 +0000 @@ -239,16 +239,28 @@ #define lex_scan_version(flags) MY_lex_scan_version(aTHX_ flags) static SV *MY_lex_scan_version(pTHX_ int flags) { - const char *err = NULL; - const char *endp = prescan_version(PL_parser->bufptr, FALSE, &err, NULL, NULL, NULL, NULL); - - if(endp == PL_parser->bufptr && (flags & PARSE_OPTIONAL)) + I32 c; + SV *tmpsv = sv_2mortal(newSVpvs("")); + + /* scan_version() expects a version to end in linefeed, semicolon or + * openbrace; gets confused if other keywords are fine. We'll have to + * extract it first. + * https://rt.cpan.org/Ticket/Display.html?id=132903 + */ + + while((c = lex_peek_unichar(0))) { + /* Allow a single leading v before accepting only digits, dot, underscore */ + if((!SvCUR(tmpsv) && (c == 'v')) || strchr("0123456789._", c)) + sv_cat_c(tmpsv, lex_read_unichar(0)); + else + break; + } + + if(!SvCUR(tmpsv) && (flags & PARSE_OPTIONAL)) return NULL; SV *ret = newSV(0); - endp = scan_version(PL_parser->bufptr, ret, FALSE); - - lex_read_to((char *)endp); + scan_version(SvPVX(tmpsv), ret, FALSE); return ret; } === modified file 't/05extends.t' --- old/t/05extends.t 2020-06-12 18:38:49 +0000 +++ new/t/05extends.t 2020-06-30 14:49:08 +0000 @@ -18,7 +18,7 @@ is( $Animal::VERSION, 1.23, 'Versioned class has $VERSION' ); -class Spider extends Animal { +class Spider 4.56 extends Animal { sub BUILDARGS { my $self = shift; return $self->SUPER::BUILDARGS( 8 ); @@ -29,6 +29,8 @@ } } +is( $Spider::VERSION, 4.56, 'Versioned subclass has $VERSION' ); + { my $spider = Spider->new; is( $spider->describe, "An animal with 8 legs",
Fixed in 0.31 -- Paul Evans