This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
msgrcv: properly downgrade the receive buffer
[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 */
3328ab5a
FC
30 char *re_eval_start; /* start of "(?{..." text */
31 SV *re_eval_str; /* "(?{...})" text */
d794b522
FC
32} LEXSHARED;
33
22735491 34typedef struct yy_parser {
199e78b7
DM
35
36 /* parser state */
37
22735491 38 struct yy_parser *old_parser; /* previous value of PL_parser */
5912531f 39 YYSTYPE yylval; /* value of lookahead symbol, set by yylex() */
9bd87817 40 int yychar; /* The lookahead symbol. */
5912531f
DM
41
42 /* Number of tokens to shift before error messages enabled. */
43 int yyerrstatus;
44
22735491 45 yy_stack_frame *stack; /* base of stack */
df13534a 46 yy_stack_frame *stack_max1;/* (top-1)th element of allocated stack */
5912531f 47 yy_stack_frame *ps; /* current stack frame */
3a6446ca 48 int yylen; /* length of active reduction */
199e78b7
DM
49
50 /* lexer state */
51
3a6446ca 52 I32 lex_formbrack; /* bracket count at outer format level */
78cdf107 53 I32 lex_brackets; /* square and curly bracket count */
199e78b7
DM
54 I32 lex_casemods; /* casemod count */
55 char *lex_brackstack;/* what kind of brackets to pop */
56 char *lex_casestack; /* what kind of case mods in effect */
651b5b28 57 U8 lex_defer; /* state after determined token */
cc624add
FC
58 U8 lex_dojoin; /* doing an array interpolation
59 1 = @{...} 2 = ->@ */
53a7735b 60 U8 expect; /* how to interpret ambiguous tokens */
25e092d6 61 bool preambled;
bb4e4c38 62 bool sub_no_recover; /* can't recover from a sublex error */
3a6446ca 63 U8 sub_error_count; /* the number of errors before sublexing */
199e78b7 64 OP *lex_inpat; /* in pattern $) and $| are special */
199e78b7
DM
65 OP *lex_op; /* extra info to pass back on op */
66 SV *lex_repl; /* runtime replacement from s/// */
651b5b28 67 U16 lex_inwhat; /* what kind of quoting are we in */
5ed5d9db 68 OPCODE last_lop_op; /* last named list or unary operator */
199e78b7
DM
69 I32 lex_starts; /* how many interps done on level */
70 SV *lex_stuff; /* runtime pattern from m// or s/// */
71 I32 multi_start; /* 1st line of multi-line string */
670a9cb2 72 I32 multi_end; /* last line of multi-line string */
6745174b
FC
73 UV multi_open; /* delimiter of said string */
74 UV multi_close; /* delimiter of said string */
3a54fd60 75 bool lex_re_reparsing; /* we're doing G_RE_REPARSING */
7ef70b3d
FC
76 U8 lex_super_state;/* lexer state to save */
77 U16 lex_sub_inwhat; /* "lex_inwhat" to use in sublex_push */
25e092d6 78 I32 lex_allbrackets;/* (), [], {}, ?: bracket count */
7ef70b3d
FC
79 OP *lex_sub_op; /* current op in y/// or pattern */
80 SV *lex_sub_repl; /* repl of s/// used in sublex_push */
d794b522 81 LEXSHARED *lex_shared;
bdc0bf6f 82 SV *linestr; /* current chunk of src text */
a0dffe9b
FC
83 char *bufptr; /* carries the cursor (current parsing
84 position) from one invocation of yylex
85 to the next */
86 char *oldbufptr; /* in yylex, beginning of current token */
87 char *oldoldbufptr; /* in yylex, beginning of previous token */
f06b5848
DM
88 char *bufend;
89 char *linestart; /* beginning of most recently read line */
90 char *last_uni; /* position of last named-unary op */
91 char *last_lop; /* position of last list operator */
1f68b13b
FC
92 /* copline is used to pass a specific line number to newSTATEOP. It
93 is a one-time line number, as newSTATEOP invalidates it (sets it to
94 NOLINE) after using it. The purpose of this is to report line num-
95 bers in multiline constructs using the number of the first line. */
96 line_t copline;
12bd6ede 97 U16 in_my; /* we're compiling a "my"/"our" declaration */
bc177e6b 98 U8 lex_state; /* next token is determined */
1f0c31d7 99 U8 error_count; /* how many compile errors so far, max 10 */
12bd6ede 100 HV *in_my_stash; /* declared class of this "my" declaration */
2f9285f8 101 PerlIO *rsfp; /* current source file pointer */
5486870f 102 AV *rsfp_filters; /* holds chain of active source filters */
199e78b7 103
fb205e7a
DM
104 YYSTYPE nextval[5]; /* value of next token, if any */
105 I32 nexttype[5]; /* type of next token */
73465289 106 U8 nexttoke;
b1ca4fe2
FC
107 U8 form_lex_state; /* remember lex_state when parsing fmt */
108 U8 lex_fakeeof; /* precedence at which to fake EOF */
109 U8 lex_flags;
4e46c5e2
FC
110 COP *saved_curcop; /* the previous PL_curcop */
111 char tokenbuf[256];
112 line_t herelines; /* number of lines in here-doc */
113 line_t preambling; /* line # when processing $ENV{PERL5DB} */
b1ca4fe2 114
241bf533 115 /* these are valid while parsing a subroutine signature */
e6158756
DM
116 UV sig_elems; /* number of signature elements seen so far */
117 UV sig_optelems; /* number of optional signature elems seen */
d3d9da4a 118 char sig_slurpy; /* the sigil of the slurpy var (or null) */
3a6446ca 119 bool sig_seen; /* the currently parsing sub has a signature */
b1ca4fe2 120
efa571ab
KW
121 bool recheck_utf8_validity;
122
b1ca4fe2
FC
123 PERL_BITFIELD16 in_pod:1; /* lexer is within a =pod section */
124 PERL_BITFIELD16 filtered:1; /* source filters in evalbytes */
125 PERL_BITFIELD16 saw_infix_sigil:1; /* saw & or * or % operator */
126 PERL_BITFIELD16 parsed_sub:1; /* last thing parsed was a sub */
5912531f 127} yy_parser;
5912531f 128
f0e67a1d
Z
129/* flags for lexer API */
130#define LEX_STUFF_UTF8 0x00000001
131#define LEX_KEEP_PREVIOUS 0x00000002
17e00314 132
27fcb6ee
FC
133#ifdef PERL_CORE
134# define LEX_START_SAME_FILTER 0x00000001
60d63348
FC
135# define LEX_IGNORE_UTF8_HINTS 0x00000002
136# define LEX_EVALBYTES 0x00000004
0abcdfa4 137# define LEX_START_COPIED 0x00000008
87606032 138# define LEX_DONT_CLOSE_RSFP 0x00000010
60d63348 139# define LEX_START_FLAGS \
0abcdfa4 140 (LEX_START_SAME_FILTER|LEX_START_COPIED \
87606032 141 |LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES|LEX_DONT_CLOSE_RSFP)
27fcb6ee 142#endif
f0e67a1d 143
361d9b55
Z
144/* flags for parser API */
145#define PARSE_OPTIONAL 0x00000001
146
78cdf107
Z
147/* values for lex_fakeeof */
148enum {
149 LEX_FAKEEOF_NEVER, /* don't fake EOF */
150 LEX_FAKEEOF_CLOSING, /* fake EOF at unmatched closing punctuation */
151 LEX_FAKEEOF_NONEXPR, /* ... and at token that can't be in expression */
152 LEX_FAKEEOF_LOWLOGIC, /* ... and at low-precedence logic operator */
153 LEX_FAKEEOF_COMMA, /* ... and at comma */
154 LEX_FAKEEOF_ASSIGN, /* ... and at assignment operator */
155 LEX_FAKEEOF_IFELSE, /* ... and at ?: operator */
156 LEX_FAKEEOF_RANGE, /* ... and at range operator */
157 LEX_FAKEEOF_LOGIC, /* ... and at logic operator */
158 LEX_FAKEEOF_BITWISE, /* ... and at bitwise operator */
159 LEX_FAKEEOF_COMPARE, /* ... and at comparison operator */
160 LEX_FAKEEOF_MAX
161};
162
e9a8c099 163/*
14d04a33 164 * ex: set ts=8 sts=4 sw=4 et:
e9a8c099 165 */