summaryrefslogtreecommitdiff
path: root/toke.c
Commit message (Collapse)AuthorAgeFilesLines
* Implement and test try/catch/finally syntaxPaul "LeoNerd" Evans2022-01-201-0/+5
|
* Also fix paren-less calls of subs where a filehandle could beDagfinn Ilmari Mannsåker2021-12-161-1/+1
| | | | | | | | If a sub exists, it takes precedence over the filehandle interpretation even without the parens: $ perl -le 'sub foo { "bar" } print foo;' bar
* Fix function calls being misinterpreted as bareword filehandlesDagfinn Ilmari Mannsåker2021-12-161-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | When bareword filehandles are disabled, the parser was interpreting any bareword as a filehandle, even when immediatey followed by parens: $ perl -M-feature=bareword_filehandles -le 'print foo()' Bareword filehandle "foo" not allowed under 'no feature "bareword_filehandles"' at -e line 1. While with the feature enabled, it works and prints the value returned by the function: $ perl -le 'sub foo { @_ } print foo("bar")' bar As for filehandles versus functions, a space before the parens makes the difference: $ perl -le 'print STDOUT ("bar")' bar $ perl -le 'print STDOUT("bar")' Undefined subroutine &main::STDOUT called at -e line 1. This fixes the bug by using the already-existing "immediate_paren" variable to make it consistent when the feature is disabled. Fixes #19271
* newSVpvn_flags().. is more efficient than sv_2mortal(newSVpvn(..))Richard Leach2021-11-291-1/+1
| | | | The same holds for newSVpvs* wrappers around newSVpvn* functions.
* `for my($k, $v) (%hash)` should not be a syntax errorNicholas Clark2021-10-191-21/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | No-one had thought to test for this explicitly. After all, both `for my $foo ...` and `for my$foo ...` are valid syntax, so tweaking the C lexer code to add an optional '(' should work, surely? The problem was that, *as was*, the lexer code didn't "accept" those two syntax variants the way the comments would suggest. `for my $foo ...` was treated as 1) we saw 'my ' 2) we saw the dollar sign 3) success! but `for my$foo ...` was treated as 0) we didn't see 'my ' or 'our ' 1) we saw the literal string 'my' which is valid as a package name 2) we saw the dollar sign 3) success! ie some sort of mangled variant of `for my Dog $spot ...` without 'my' *but* as the lexer was happy with what it saw, it returned that the input stream was valid for a "for" token, and control continues to the grammar. The grammar, of course, didn't make these mistakes, so parsed everything properly and built the correct optree. (And, if presented with `for Dog $spot (...)` the grammar wouldn't match, so all invalid code was correctly rejected) However, all this came unstuck with `for my($k` because that didn't mis-tokenise as some crazy package name 'my(', so it reported a syntax error. Hence rewrite yyl_foreach() to actually tokenise everything correctly. "Correctly", to be clear, is bug-for-bug compatible with the current emergent behaviour for various corner cases for "parses and runs" vs "syntax error". We don't always report identical error messages for certain syntax errors, where the precise message reported was itself emergent behaviour from the bugs in the previous implementation.
* n-at-a-time for loops now warn by default (as 'experimental::for_list').Nicholas Clark2021-10-151-4/+8
|
* Implement n-at-a-time for loops.Nicholas Clark2021-10-151-2/+6
| | | | | | | | | 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).
* Remove NetWare supportDagfinn Ilmari Mannsåker2021-10-081-28/+3
| | | | The build has been broken since 2009.
* Replace "grandfather ..." in toke.c with a full descriptionNicholas Clark2021-09-301-1/+75
| | | | | | | | "grandfather return to old style" only really makes sense if you are familiar with parsing changes between perl 2 and perl 3. For everyone else, add an explanation of a special case which is still relevant to the present day.
* fix line number of try blockDavid Mitchell2021-09-041-0/+1
| | | | | | | | | | | | | | | | | | 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.
* Create `defer` syntax and `OP_PUSHDEFER` opcodePaul "LeoNerd" Evans2021-08-251-0/+5
| | | | | | | | | | | | | | | 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.
* toke.c: Save a '&' instr by casting to U8Karl Williamson2021-07-301-1/+1
|
* Base *.[ch] files: Replace leading tabs with blanksMichael G Schwern2021-05-311-2998/+2998
| | | | | | | 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.
* toke.c: fix format warningsAlyssa Ross2021-05-211-3/+3
| | | | | | | | | | Signed-off-by: James E Keenan <jkeenan@cpan.org> Remove 2nd const from patch originally submitted in https://github.com/Perl/perl5/pull/18726; it was causing two build-time warnings. Alyssa Ross is now a Perl author.
* Initial attempt at feature 'try'Paul "LeoNerd" Evans2021-02-041-0/+12
| | | | | | | | | * Add feature, experimental warning, keyword * Basic parsing * Basic implementation as optree fragment See also https://github.com/Perl/perl5/issues/18504
* Allow blanks within and adjacent to {...} constructsKarl Williamson2021-01-201-7/+24
| | | | | This was the consensus in http://nntp.perl.org/group/perl.perl5.porters/258489
* toke.c: White-space, comment onlyKarl Williamson2021-01-201-3/+3
|
* toke.c: Change variable nameKarl Williamson2021-01-201-17/+17
| | | | | A future commit will need it to represent just the meaning of the new name
* toke.c: Slight simplificationKarl Williamson2021-01-201-6/+6
| | | | | | | Rather than know how far we have advanced in parsing when we have to back up, save the checkpoint position and simply backtrack to it. This results in slightly more maintainable code that a future commit will take advantage of.
* Revamp regcurly(), regpiece() use of itKarl Williamson2021-01-201-2/+2
| | | | | | | | | | | | | | | | | | | | This commit copies portions of new_regcurly(), which has been around since 5.28, into plain regcurly(), as a baby step in preparation for converting entirely to the new one. These functions are used for parsing {m,n} quantifiers. Future commits will add capabilities not available using the old version. The commit adds an optional parameter, to return to the caller information it gleans during parsing. regpiece() is changed by this commit to use this information, instead of itself reparsing the input. Part of the reason for this commit is that changes are planned soon to what is legal syntax. With this commit in place, those changes only have to be done once. This commit also extracts into a function the calculation of the quantifier bounds. This allows the logic for that to be done in one place instead of two.
* Define RSFP_FILENO before using itdlaugt2021-01-051-7/+6
|
* add a bareword_filehandles feature, which is enabled by defaultTony Cook2021-01-041-0/+10
| | | | This disables use of bareword filehandles except for the built-in handles
* Cleanup remnants of 'KEY_err' removalBranislav Zahradník2020-12-271-1/+0
| | | | f23102e2d6 removed DOROP token (KEY_err) but related grammar remained
* Distinguish C- and perly- literals - PERLY_DOLLARBranislav Zahradník2020-12-271-8/+10
|
* Distinguish C- and perly- literals - PERLY_SLASHBranislav Zahradník2020-12-271-1/+2
|
* Distinguish C- and perly- literals - PERLY_STARBranislav Zahradník2020-12-271-5/+7
|
* Distinguish C- and perly- literals - PERLY_PAREN_CLOSEBranislav Zahradník2020-12-271-5/+6
|
* Distinguish C- and perly- literals - PERLY_PAREN_OPENBranislav Zahradník2020-12-271-4/+5
|
* Distinguish C- and perly- literals - PERLY_PERCENT_SIGNBranislav Zahradník2020-12-271-4/+7
|
* Distinguish C- and perly- literals - PERLY_SNAILBranislav Zahradník2020-12-271-8/+14
|
* Distinguish C- and perly- literals - PERLY_PLUSBranislav Zahradník2020-12-271-1/+2
|
* Distinguish C- and perly- literals - PERLY_MINUSBranislav Zahradník2020-12-271-3/+4
|
* Distinguish C- and perly- literals - PERLY_QUESTION_MARKBranislav Zahradník2020-12-271-1/+2
|
* Distinguish C- and perly- literals - PERLY_COLONBranislav Zahradník2020-12-271-2/+3
|
* Distinguish C- and perly- literals - PERLY_TILDEBranislav Zahradník2020-12-271-1/+2
|
* Distinguish C- and perly- literals - PERLY_EXCLAMATION_MARKBranislav Zahradník2020-12-271-2/+3
|
* Distinguish C- and perly- literals - PERLY_COMMABranislav Zahradník2020-12-271-8/+12
|
* Distinguish C- and perly- literals - PERLY_AMPERSANDBranislav Zahradník2020-12-271-5/+6
|
* Distinguish C- and perly- literals - PERLY_EQUAL_SIGNBranislav Zahradník2020-12-271-1/+2
|
* Distinguish C- and perly- literals - PERLY_DOTBranislav Zahradník2020-12-271-1/+2
|
* Distinguish C- and perly- literals - PERLY_SEMICOLONBranislav Zahradník2020-12-271-7/+8
|
* Distinguish C- and perly- literals - PERLY_BRACKET_CLOSEBranislav Zahradník2020-12-271-1/+2
|
* Distinguish C- and perly- literals - PERLY_BRACKET_OPENBranislav Zahradník2020-12-271-5/+4
|
* Distinguish C- and perly- literals - PERLY_BRACE_CLOSEBranislav Zahradník2020-12-271-1/+2
|
* Distinguish C- and perly- literals - PERLY_BRACE_OPENBranislav Zahradník2020-12-271-2/+8
| | | | | regardless of the fact that both have same value their meaning is different and should not be mixed
* toke.c: Eliminate temporary variables base, Base and max.TAKAI Kousuke2020-12-071-9/+6
| | | | | | | | | | | These variables are only used on emitting diagnostic messages. Calculating them on-demand will make the code slightly faster on normal cases. Note: previously bases[], Bases[] and maxima[] may be completely optimized out by fusing array accesses into if-brances. Now they become real arrays, and will slightly increase the number of dynamic relocations on PIC build.
* toke.c: Preserve "0o" prefix on warnings and strings passed to overload hook.TAKAI Kousuke2020-12-071-1/+8
|
* toke.c: Recognize "0odddd" octal literals.TAKAI Kousuke2020-12-071-4/+8
| | | | t/base/num.t: Add some test for "0odddd" octals.
* toke.c: Use SvPV_shrink_to_curKarl Williamson2020-08-221-1/+1
| | | | which is what it is doing, instead of the more general SvPV_renew.
* Use PERL_REVISION in toke.c for -E switch☢ ℕicolas ℝ2020-08-041-1/+1
| | | | | This allows to use the current features bundle defined by the current version of Perl.