| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
| |
Some of the token types represent simple keywords; some of them do not.
It's easier to read and work out what's going on if all the simple
keyword ones have a common prefix; `KW_...` in this case.
Additionally I've renamed the four `sub`-related keywords to have a bit
more structure to them.
Also added comments.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
These token names are shared between perl.y and toke.c, to communicate
on the nature of various tokens parsed from perl source. The name
FUNCMETH used to refer to a method call with possible arguments
->NAME(...)
whereas METHOD referred to one without even the parens
->NAME
These names are a little confusing, and most importantly, METHOD was in
the way of my adding a new `method` keyword as part of the upcoming work
on 'use feature "class"'.
As such, this simple rename moves them out of the way and makes them
slightly more consistent and easier to read/remember, by calling them
METHCALL and METHCALL0.
This commit also renames the `method` grammar rule to `methodname`, for
similar reasons.
As all of these names are entirely internal to the tokenizer/parser,
there is not expected to be any upstream CPAN incompatibility, or other
issues, caused by these renames.
|
|
|
|
|
|
|
|
|
|
|
|
| |
As suggested in https://github.com/Perl/perl5/issues/19811, this now
outputs the message:
$ ./perl -Mexperimental=try
try { A() }
catch { B() }
catch block requires a (VAR) at - line 2, near "catch {"
Execution of - aborted due to compilation errors.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The new
for my ($x,$y,...) (...) { ... }
syntax has a couple of problems in the degenerate case of a single
variable:
for my ($x) (...) { ... }
First, the loop variable is marked as lexical, but not as a variable
to be introduced. So it behaves roughly as if written like:
{ my $x; for $x (...) { ... } }
I can't think of any user-visible runtime change in behaviour this bug
causes, so I haven't included a test for it.
Second, it was being incorrectly deparsed as
for $x (...) { ... }
(i.e. without the 'my').
This commit fixes both of these issues.
The basic problem is that the parser, in the case of multiple vars,
passes a list subtree of PADSVs as the 'sv' argument of Perl_newFOROP,
but in the case of a single var, passes a single PADSV op instead.
This single PADSV doesn't have the LVINTRO flag set, so is
indistinguishable from plain
my $x; for $x ....
This commit makes the parser set the OPf_PARENS flag on the lone PADSV
to signal to newFOROP() that it's a degenerate 1-var list, and
newFOROP() sets the OPf_PARENS flag on the ENTERITER op to signal to the
deparser that this is "for my (...)" syntax, even if it only has a
single var.
|
| |
|
| |
|
|
|
|
|
| |
- start with `opt` (renamed `siglistornull`)
- employ bison's default rule whenever possible
|
|
|
|
| |
to save few keystrokes ...
|
| |
|
| |
|
| |
|
|
|
|
|
| |
Multiple commas between the lexicals in the list shouldn't change the
parsing.
|
|
|
|
|
|
|
|
|
| |
For example, this now works:
for my ($key, $value) (%hash) { ... }
Only for scalars declared with my as a list in the for loop statement.
As many as you want (unless you want more than 4294967296).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Each 'try' block has a nextstate COP prepended to it. Currently this cop
has the line number of the line following the end of the try block. Fix
it so that it has the line number of the line containing the 'try'
keyword instead.
This is achieved using the same technique as other block-introducing
keywords like 'while': set the .ival of the 'try' token returned by the
lexer to the current line number, then set PL_parser->copline back to that
value after parsing the block but before creating the COP.
This issue was showing up as a failure in
cd t; ./TEST -deparse op/try.t
since that test script is line-number sensitive.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Adds syntax `defer { BLOCK }` to create a deferred block; code that is
deferred until the scope exits. This syntax is guarded by
use feature 'defer';
Adds a new opcode, `OP_PUSHDEFER`, which is a LOGOP whose `op_other` field
gives the start of an optree to be deferred until scope exit. That op
pointer will be stored on the save stack and invoked as part of scope
unwind.
Included is support for `B::Deparse` to deparse the optree back into
syntax.
|
|
|
|
|
|
|
| |
This is a rebasing by @khw of part of GH #18792, which I needed to get
in now to proceed with other commits.
It also strips trailing white space from the affected files.
|
| |
|
|
|
|
|
|
|
|
|
| |
* Add feature, experimental warning, keyword
* Basic parsing
* Basic implementation as optree fragment
See also
https://github.com/Perl/perl5/issues/18504
|
| |
|
|
|
|
| |
f23102e2d6 removed DOROP token (KEY_err) but related grammar remained
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
| |
regardless of the fact that both have same value
their meaning is different and should not be mixed
|
|
|
|
|
| |
Usage of Bison's named references makes actions little bit easier
to read and maintain.
|
|
|
|
|
|
|
|
|
|
|
|
| |
The script alrady stripped out comments from bison 2.4 on the form
/* Line 1234 of yacc.c */
But bison 3.0 changed the comment syntax to
/* yacc.c:1234 */
Let's remove those too.
|
|
|
|
|
|
|
|
|
|
|
| |
This requires copying the `YY_CAST` and `YY_ATTRIBUTE_UNUSED` macros
from the generated code, and extracting the `yysymbol_kind_t` enum if
it's defined.
We must also handle token type names with escaped double-quotes in
them, since it now names the `YYEOF` and `YYUNDEF` tokens `"end of
file"` and `"invalid token"` instead of `$end` and `$undefined`,
respectively.
|
|
|
|
|
|
|
|
|
| |
This lets us replace the deprecated `%pure-parser` directive with
`%define api.pure`, and get rid of some other conditional code.
Bison is only required for developers hacking on the grammar, since we
check in the generated code. Bison 2.4 was released in 2008, and is
included in operating systems as old as Red Hat Enterprise Linux 6.
|
|
|
|
|
| |
Mostly in comments and docs, but some in diagnostic messages and one
case of 'or die die'.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The following code:
sub f ($x,$y) {
study;
}
used to compile as:
a <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq KP ->a
1 <;> nextstate(main 5 p:5) v:%,fea=7 ->2
2 <+> argcheck(2,0) v ->3
3 <;> nextstate(main 3 p:5) v:%,fea=7 ->4
4 <+> argelem(0)[$x:3,5] v/SV ->5
5 <;> nextstate(main 4 p:5) v:%,fea=7 ->6
6 <+> argelem(1)[$y:4,5] v/SV ->7
- <;> ex-nextstate(main 5 p:5) v:%,fea=7 ->7
7 <;> nextstate(main 5 p:6) v:%,fea=7 ->8
9 <1> study sK/1 ->a
- <1> ex-rv2sv sK/1 ->9
8 <$> gvsv(*_) s ->9
Following this commit, it compiles as:
a <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq KP ->a
- <1> ex-argcheck vK/1 ->7
- <@> lineseq vK ->-
1 <;> nextstate(main 5 p:5) v:%,fea=7 ->2
2 <+> argcheck(2,0) v ->3
3 <;> nextstate(main 3 p:5) v:%,fea=7 ->4
4 <+> argelem(0)[$x:3,5] v/SV ->5
5 <;> nextstate(main 4 p:5) v:%,fea=7 ->6
6 <+> argelem(1)[$y:4,5] v/SV ->7
- <;> ex-nextstate(main 5 p:5) v:%,fea=7 ->-
7 <;> nextstate(main 5 p:6) v:%,fea=7 ->8
9 <1> study sK/1 ->a
- <1> ex-rv2sv sK/1 ->9
8 <#> gvsv[*_] s ->9
All the ops associated with the signature have been put in their own
subtree, with an extra NULL ex-argcheck op "on top". The op on top
serves two purposes: first, it makes it easier for Deparse.pm etc to
spot siganure code; secondly, it may at some point in the future be
upgraded to OP_SIGNATURE when signatures get optimised. It's of type
ex-argcheck only because when being created it needs to be an op type
that's in class UNOP_AUX so that the created op will be suitable for
later optimising, and making it an ex-type associated with signatures
helps flag it as such.
There should be no functional changes apart from the shape of the
optree.
|
|
|
|
|
|
|
|
|
|
|
|
| |
This op is of class OP_UNOP_AUX, Ops of this class have an op_aux pointer
which typically points to a variable-length malloced array of IVs,
UVs, etc. However in the specific case of OP_ARGCHECK the data stored
in the aux struct is fixed. So this commit casts the aux pointer to a
struct containing the relevant fields (number of parameters etc), rather
than referring to them as aux[0], aux[1] etc. This makes the code more
readable.
Should be no functional changes.
|