This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use PL_parser->lex_shared instead of Sv[IN]VX(PL_linestr)
[perl5.git] / parser.h
CommitLineData
5912531f
DM
1/* parser.h
2 *
2eee27d7 3 * Copyright (c) 2006, 2007, 2009, 2010, 2011 Larry Wall and others
5912531f
DM
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
8 * This file defines the layout of the parser object used by the parser
6cded92d 9 * and lexer (perly.c, toke.c).
5912531f
DM
10 */
11
acdf0a21
DM
12#define YYEMPTY (-2)
13
5912531f
DM
14typedef struct {
15 YYSTYPE val; /* semantic value */
16 short state;
33703721 17 I32 savestack_ix; /* size of savestack at this state */
8c63ea58 18 CV *compcv; /* value of PL_compcv when this value was created */
5912531f
DM
19#ifdef DEBUGGING
20 const char *name; /* token/rule name for -Dpv */
21#endif
22} yy_stack_frame;
23
d794b522
FC
24/* Fields that need to be shared with (i.e., visible to) inner lex-
25 ing scopes. */
26typedef struct yy_lexshared {
27 struct yy_lexshared *ls_prev;
60f40a38
FC
28 SV *ls_linestr; /* mirrors PL_parser->linestr */
29 char *ls_bufptr; /* mirrors PL_parser->bufptr */
d794b522
FC
30 line_t herelines; /* number of lines in here-doc */
31} LEXSHARED;
32
22735491 33typedef struct yy_parser {
199e78b7
DM
34
35 /* parser state */
36
22735491 37 struct yy_parser *old_parser; /* previous value of PL_parser */
5912531f 38 YYSTYPE yylval; /* value of lookahead symbol, set by yylex() */
9bd87817 39 int yychar; /* The lookahead symbol. */
5912531f
DM
40
41 /* Number of tokens to shift before error messages enabled. */
42 int yyerrstatus;
43
44 int stack_size;
45 int yylen; /* length of active reduction */
22735491 46 yy_stack_frame *stack; /* base of stack */
5912531f 47 yy_stack_frame *ps; /* current stack frame */
199e78b7
DM
48
49 /* lexer state */
50
78cdf107 51 I32 lex_brackets; /* square and curly bracket count */
199e78b7
DM
52 I32 lex_casemods; /* casemod count */
53 char *lex_brackstack;/* what kind of brackets to pop */
54 char *lex_casestack; /* what kind of case mods in effect */
651b5b28
NC
55 U8 lex_defer; /* state after determined token */
56 bool lex_dojoin; /* doing an array interpolation */
57 U8 lex_expect; /* expect after determined token */
53a7735b 58 U8 expect; /* how to interpret ambiguous tokens */
199e78b7
DM
59 I32 lex_formbrack; /* bracket count at outer format level */
60 OP *lex_inpat; /* in pattern $) and $| are special */
199e78b7
DM
61 OP *lex_op; /* extra info to pass back on op */
62 SV *lex_repl; /* runtime replacement from s/// */
651b5b28 63 U16 lex_inwhat; /* what kind of quoting are we in */
5ed5d9db 64 OPCODE last_lop_op; /* last named list or unary operator */
199e78b7
DM
65 I32 lex_starts; /* how many interps done on level */
66 SV *lex_stuff; /* runtime pattern from m// or s/// */
67 I32 multi_start; /* 1st line of multi-line string */
670a9cb2 68 I32 multi_end; /* last line of multi-line string */
651b5b28
NC
69 char multi_open; /* delimiter of said string */
70 char multi_close; /* delimiter of said string */
199e78b7
DM
71 char pending_ident; /* pending identifier lookup */
72 bool preambled;
78cdf107 73 I32 lex_allbrackets;/* (), [], {}, ?: bracket count */
199e78b7 74 SUBLEXINFO sublex_info;
d794b522 75 LEXSHARED *lex_shared;
bdc0bf6f 76 SV *linestr; /* current chunk of src text */
a0dffe9b
FC
77 char *bufptr; /* carries the cursor (current parsing
78 position) from one invocation of yylex
79 to the next */
80 char *oldbufptr; /* in yylex, beginning of current token */
81 char *oldoldbufptr; /* in yylex, beginning of previous token */
f06b5848
DM
82 char *bufend;
83 char *linestart; /* beginning of most recently read line */
84 char *last_uni; /* position of last named-unary op */
85 char *last_lop; /* position of last list operator */
1f68b13b
FC
86 /* copline is used to pass a specific line number to newSTATEOP. It
87 is a one-time line number, as newSTATEOP invalidates it (sets it to
88 NOLINE) after using it. The purpose of this is to report line num-
89 bers in multiline constructs using the number of the first line. */
90 line_t copline;
12bd6ede 91 U16 in_my; /* we're compiling a "my"/"our" declaration */
bc177e6b 92 U8 lex_state; /* next token is determined */
1f0c31d7 93 U8 error_count; /* how many compile errors so far, max 10 */
12bd6ede 94 HV *in_my_stash; /* declared class of this "my" declaration */
2f9285f8 95 PerlIO *rsfp; /* current source file pointer */
5486870f 96 AV *rsfp_filters; /* holds chain of active source filters */
583c9d5c 97 U8 form_lex_state; /* remember lex_state when parsing fmt */
199e78b7
DM
98
99#ifdef PERL_MAD
100 SV *endwhite;
101 I32 faketokens;
102 I32 lasttoke;
103 SV *nextwhite;
104 I32 realtokenstart;
105 SV *skipwhite;
106 SV *thisclose;
107 MADPROP * thismad;
108 SV *thisopen;
109 SV *thisstuff;
110 SV *thistoken;
111 SV *thiswhite;
fb205e7a
DM
112
113/* What we know when we're in LEX_KNOWNEXT state. */
114 NEXTTOKE nexttoke[5]; /* value of next token, if any */
115 I32 curforce;
116#else
117 YYSTYPE nextval[5]; /* value of next token, if any */
118 I32 nexttype[5]; /* type of next token */
119 I32 nexttoke;
199e78b7 120#endif
fb205e7a 121
7c4baf47 122 COP *saved_curcop; /* the previous PL_curcop */
14047fc9 123 char tokenbuf[256];
7c4baf47 124
78cdf107 125 U8 lex_fakeeof; /* precedence at which to fake EOF */
286a76ab 126 U8 lex_flags;
7ad221d3
FC
127 PERL_BITFIELD16 in_pod:1; /* lexer is within a =pod section */
128 PERL_BITFIELD16 filtered:1; /* source filters in evalbytes */
5912531f 129} yy_parser;
5912531f 130
f0e67a1d
Z
131/* flags for lexer API */
132#define LEX_STUFF_UTF8 0x00000001
133#define LEX_KEEP_PREVIOUS 0x00000002
17e00314 134
27fcb6ee
FC
135#ifdef PERL_CORE
136# define LEX_START_SAME_FILTER 0x00000001
60d63348
FC
137# define LEX_IGNORE_UTF8_HINTS 0x00000002
138# define LEX_EVALBYTES 0x00000004
0abcdfa4 139# define LEX_START_COPIED 0x00000008
87606032 140# define LEX_DONT_CLOSE_RSFP 0x00000010
60d63348 141# define LEX_START_FLAGS \
0abcdfa4 142 (LEX_START_SAME_FILTER|LEX_START_COPIED \
87606032 143 |LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES|LEX_DONT_CLOSE_RSFP)
27fcb6ee 144#endif
f0e67a1d 145
361d9b55
Z
146/* flags for parser API */
147#define PARSE_OPTIONAL 0x00000001
148
78cdf107
Z
149/* values for lex_fakeeof */
150enum {
151 LEX_FAKEEOF_NEVER, /* don't fake EOF */
152 LEX_FAKEEOF_CLOSING, /* fake EOF at unmatched closing punctuation */
153 LEX_FAKEEOF_NONEXPR, /* ... and at token that can't be in expression */
154 LEX_FAKEEOF_LOWLOGIC, /* ... and at low-precedence logic operator */
155 LEX_FAKEEOF_COMMA, /* ... and at comma */
156 LEX_FAKEEOF_ASSIGN, /* ... and at assignment operator */
157 LEX_FAKEEOF_IFELSE, /* ... and at ?: operator */
158 LEX_FAKEEOF_RANGE, /* ... and at range operator */
159 LEX_FAKEEOF_LOGIC, /* ... and at logic operator */
160 LEX_FAKEEOF_BITWISE, /* ... and at bitwise operator */
161 LEX_FAKEEOF_COMPARE, /* ... and at comparison operator */
162 LEX_FAKEEOF_MAX
163};
164
e9a8c099
MHM
165/*
166 * Local variables:
167 * c-indentation-style: bsd
168 * c-basic-offset: 4
14d04a33 169 * indent-tabs-mode: nil
e9a8c099
MHM
170 * End:
171 *
14d04a33 172 * ex: set ts=8 sts=4 sw=4 et:
e9a8c099 173 */