summaryrefslogtreecommitdiff
path: root/perly.h
Commit message (Collapse)AuthorAgeFilesLines
* Rename token types for keywords to add KW_... prefixPaul "LeoNerd" Evans2022-07-021-59/+59
| | | | | | | | | | | 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.
* Rename some grammar rules/tokens to avoid 'method'Paul "LeoNerd" Evans2022-06-281-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* A better error message for `try {} catch {}` missing its (VAR)Paul "LeoNerd" Evans2022-06-131-126/+121
| | | | | | | | | | | | 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.
* for my ($x) ...: fix handling of degenerate 1-varDavid Mitchell2022-04-161-121/+126
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Don't emit experimental::signatures warning (closes #13681)Paul "LeoNerd" Evans2022-02-201-2/+2
|
* Use `optexpr` in anonymous to reduce number of symbolsBranislav Zahradník2022-02-051-1/+1
|
* Unify optional rulesBranislav Zahradník2022-02-051-1/+1
| | | | | - start with `opt` (renamed `siglistornull`) - employ bison's default rule whenever possible
* Introduce rule `empty` returning NULLBranislav Zahradník2022-02-051-1/+1
| | | | to save few keystrokes ...
* Gather all MY variants into single ruleBranislav Zahradník2022-02-051-2/+2
|
* Set the CvSIGNATURE flag on signatured subsPaul "LeoNerd" Evans2022-01-311-1/+1
|
* Implement and test try/catch/finally syntaxPaul "LeoNerd" Evans2022-01-201-125/+121
|
* for my ($foo,,, $bar) { ... } should parse as ($foo, $bar)Nicholas Clark2021-10-151-1/+1
| | | | | Multiple commas between the lexicals in the list shouldn't change the parsing.
* Implement n-at-a-time for loops.Nicholas Clark2021-10-151-1/+1
| | | | | | | | | 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).
* fix line number of try blockDavid Mitchell2021-09-041-122/+127
| | | | | | | | | | | | | | | | | | 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-32/+33
| | | | | | | | | | | | | | | 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.
* Base *.[ch] files: Replace leading tabs with blanksMichael G Schwern2021-05-311-2/+2
| | | | | | | 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 a newTRYCATCHOP(); migrate the custom code out of perly.y into itPaul "LeoNerd" Evans2021-02-141-1/+1
|
* Initial attempt at feature 'try'Paul "LeoNerd" Evans2021-02-041-58/+61
| | | | | | | | | * Add feature, experimental warning, keyword * Basic parsing * Basic implementation as optree fragment See also https://github.com/Perl/perl5/issues/18504
* Use explicit %emptyBranislav Zahradník2020-12-271-1/+1
|
* Cleanup remnants of 'KEY_err' removalBranislav Zahradník2020-12-271-31/+30
| | | | f23102e2d6 removed DOROP token (KEY_err) but related grammar remained
* Distinguish C- and perly- literals - PERLY_DOLLARBranislav Zahradník2020-12-271-96/+97
|
* Distinguish C- and perly- literals - PERLY_SLASHBranislav Zahradník2020-12-271-89/+90
|
* Distinguish C- and perly- literals - PERLY_STARBranislav Zahradník2020-12-271-87/+88
|
* Distinguish C- and perly- literals - PERLY_PAREN_CLOSEBranislav Zahradník2020-12-271-2/+3
|
* Distinguish C- and perly- literals - PERLY_PAREN_OPENBranislav Zahradník2020-12-271-2/+3
|
* Distinguish C- and perly- literals - PERLY_PERCENT_SIGNBranislav Zahradník2020-12-271-88/+89
|
* Distinguish C- and perly- literals - PERLY_SNAILBranislav Zahradník2020-12-271-85/+86
|
* Distinguish C- and perly- literals - PERLY_PLUSBranislav Zahradník2020-12-271-86/+87
|
* Distinguish C- and perly- literals - PERLY_MINUSBranislav Zahradník2020-12-271-86/+87
|
* Distinguish C- and perly- literals - PERLY_QUESTION_MARKBranislav Zahradník2020-12-271-24/+25
|
* Distinguish C- and perly- literals - PERLY_COLONBranislav Zahradník2020-12-271-23/+24
|
* Distinguish C- and perly- literals - PERLY_TILDEBranislav Zahradník2020-12-271-10/+11
|
* Distinguish C- and perly- literals - PERLY_EXCLAMATION_MARKBranislav Zahradník2020-12-271-10/+11
|
* Distinguish C- and perly- literals - PERLY_COMMABranislav Zahradník2020-12-271-84/+85
|
* Distinguish C- and perly- literals - PERLY_AMPERSANDBranislav Zahradník2020-12-271-88/+89
|
* Distinguish C- and perly- literals - PERLY_EQUAL_SIGNBranislav Zahradník2020-12-271-82/+83
|
* Distinguish C- and perly- literals - PERLY_DOTBranislav Zahradník2020-12-271-82/+83
|
* Distinguish C- and perly- literals - PERLY_SEMICOLONBranislav Zahradník2020-12-271-81/+82
|
* Distinguish C- and perly- literals - PERLY_BRACKET_CLOSEBranislav Zahradník2020-12-271-81/+82
|
* Distinguish C- and perly- literals - PERLY_BRACKET_OPENBranislav Zahradník2020-12-271-81/+82
|
* Distinguish C- and perly- literals - PERLY_BRACE_CLOSEBranislav Zahradník2020-12-271-81/+82
|
* Distinguish C- and perly- literals - PERLY_BRACE_OPENBranislav Zahradník2020-12-271-81/+82
| | | | | regardless of the fact that both have same value their meaning is different and should not be mixed
* Use GNU Bison's named referencesBranislav Zahradník2020-12-071-7/+6
| | | | | Usage of Bison's named references makes actions little bit easier to read and maintain.
* regen_perly.pl: remove extraneous comments from bison 3.xDagfinn Ilmari Mannsåker2020-08-171-1/+1
| | | | | | | | | | | | 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.
* Add support for Bison versions up to 3.7Dagfinn Ilmari Mannsåker2020-08-061-1/+1
| | | | | | | | | | | 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.
* Bump minimum required Bison version to 2.4Dagfinn Ilmari Mannsåker2020-08-061-2/+2
| | | | | | | | | 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.
* Fix a bunch of repeated-word typosDagfinn Ilmari Mannsåker2020-05-221-5/+11
| | | | | Mostly in comments and docs, but some in diagnostic messages and one case of 'or die die'.
* chained comparisonsZefram2020-03-121-44/+44
|
* put signature ops in their own subtree.David Mitchell2019-09-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* OP_ARGCHECK: use custom aux structDavid Mitchell2019-09-231-9/+6
| | | | | | | | | | | | 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.