From d3d9da4a748f12980e8b04fe471398bf91237705 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Thu, 28 Jan 2016 15:14:57 +0000 Subject: sub signatures: use parser rather than lexer Currently the signature of a sub (i.e. the '($a, $b = 1)' bit) is parsed in toke.c using a roll-your-own mini-parser. This commit makes the signature be part of the general grammar in perly.y instead. In theory it should still generate the same optree as before, except that an OP_STUB is no longer appended to each signature optree: it's unnecessary, and I assume that was a hangover from early development of the original signature code. Error messages have changed somewhat: the generic 'Parse error' has changed to the generic 'syntax error', with the addition of ', near "xyz"' now appended to each message. Also, some specific error messages have been added; for example (@a=1) now says that slurpy params can't have a default vale, rather than just giving 'Parse error'. It introduces a new lexer expect state, XSIGVAR, since otherwise when the lexer saw something like '($, ...)' it would see the identifier '$,' rather than the tokens '$' and ','. Since it no longer uses parse_termexpr(), it is no longer subject to the bug (#123010) associated with that; so sub f($x = print, $y) {} is no longer mis-interpreted as sub f($x = print($_, $y)) {} --- perly.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'perly.c') diff --git a/perly.c b/perly.c index 5aed62858c..e8a9506433 100644 --- a/perly.c +++ b/perly.c @@ -25,6 +25,7 @@ #define PERL_IN_PERLY_C #include "perl.h" #include "feature.h" +#include "keywords.h" typedef unsigned char yytype_uint8; typedef signed char yytype_int8; @@ -246,6 +247,7 @@ S_clear_yystack(pTHX_ const yy_parser *parser) int Perl_yyparse (pTHX_ int gramtype) { + dVAR; int yystate; int yyn; int yyresult; -- cgit v1.2.1