]> perl5.git.perl.org Git - perl5.git/blob - parser.h This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deparse: exclude two new test files
[perl5.git] / parser.h
1 /*    parser.h
2  *
3  *    Copyright (c) 2006, 2007, 2009, 2010, 2011 Larry Wall and others
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
9  * and lexer (perly.c, toke.c).
10  */
11
12 #define YYEMPTY         (-2)
13
14 typedef struct {
15     YYSTYPE val;    /* semantic value */
16     short   state;
17     I32     savestack_ix;       /* size of savestack at this state */
18     CV      *compcv; /* value of PL_compcv when this value was created */
19 #ifdef DEBUGGING
20     const char  *name; /* token/rule name for -Dpv */
21 #endif
22 } yy_stack_frame;
23
24 /* Fields that need to be shared with (i.e., visible to) inner lex-
25    ing scopes. */
26 typedef struct yy_lexshared {
27     struct yy_lexshared *ls_prev;
28     SV                  *ls_linestr;    /* mirrors PL_parser->linestr */
29     char                *ls_bufptr;     /* mirrors PL_parser->bufptr */
30     char                *re_eval_start; /* start of "(?{..." text */
31     SV                  *re_eval_str;   /* "(?{...})" text */
32 } LEXSHARED;
33
34 /* Opaque struct of data relevant during parsing and construction of a
35  * subroutine signature. Defined and used exclusively by op.c */
36 typedef struct yy_parser_signature yy_parser_signature;
37
38 typedef struct yy_parser {
39
40     /* parser state */
41
42     struct yy_parser *old_parser; /* previous value of PL_parser */
43     YYSTYPE         yylval;     /* value of lookahead symbol, set by yylex() */
44     int             yychar;     /* The lookahead symbol.  */
45
46     /* Number of tokens to shift before error messages enabled.  */
47     int             yyerrstatus;
48
49     yy_stack_frame  *stack;     /* base of stack */
50     yy_stack_frame  *stack_max1;/* (top-1)th element of allocated stack */
51     yy_stack_frame  *ps;        /* current stack frame */
52     int             yylen;      /* length of active reduction */
53
54     /* lexer state */
55
56     I32         lex_formbrack;  /* bracket count at outer format level */
57     I32         lex_brackets;   /* square and curly bracket count */
58     I32         lex_casemods;   /* casemod count */
59     char        *lex_brackstack;/* what kind of brackets to pop */
60     char        *lex_casestack; /* what kind of case mods in effect */
61     U8          lex_defer;      /* state after determined token */
62     U8          lex_dojoin;     /* doing an array interpolation
63                                    1 = @{...}  2 = ->@ */
64     U8          expect;         /* how to interpret ambiguous tokens */
65     bool        preambled;
66     bool        sub_no_recover; /* can't recover from a sublex error */
67     U8          sub_error_count; /* the number of errors before sublexing */
68     OP          *lex_inpat;     /* in pattern $) and $| are special */
69     OP          *lex_op;        /* extra info to pass back on op */
70     SV          *lex_repl;      /* runtime replacement from s/// */
71     U16         lex_inwhat;     /* what kind of quoting are we in */
72     OPCODE      last_lop_op;    /* last named list or unary operator */
73     I32         lex_starts;     /* how many interps done on level */
74     SV          *lex_stuff;     /* runtime pattern from m// or s/// */
75     I32         multi_start;    /* 1st line of multi-line string */
76     I32         multi_end;      /* last line of multi-line string */
77     UV          multi_open;     /* delimiter code point of said string */
78     UV          multi_close;    /* delimiter code point of said string */
79     bool        lex_re_reparsing; /* we're doing G_RE_REPARSING */
80     U8          lex_super_state;/* lexer state to save */
81     U16         lex_sub_inwhat; /* "lex_inwhat" to use in sublex_push */
82     I32         lex_allbrackets;/* (), [], {}, ?: bracket count */
83     OP          *lex_sub_op;    /* current op in y/// or pattern */
84     SV          *lex_sub_repl;  /* repl of s/// used in sublex_push */
85     LEXSHARED   *lex_shared;
86     SV          *linestr;       /* current chunk of src text */
87     char        *bufptr;        /* carries the cursor (current parsing
88                                    position) from one invocation of yylex
89                                    to the next */
90     char        *oldbufptr;     /* in yylex, beginning of current token */
91     char        *oldoldbufptr;  /* in yylex, beginning of previous token */
92     char        *bufend;        
93     char        *linestart;     /* beginning of most recently read line */
94     char        *last_uni;      /* position of last named-unary op */
95     char        *last_lop;      /* position of last list operator */
96     /* copline is used to pass a specific line number to newSTATEOP.  It
97        is a one-time line number, as newSTATEOP invalidates it (sets it to
98        NOLINE) after using it.  The purpose of this is to report line num-
99        bers in multiline constructs using the number of the first line. */
100     line_t      copline;
101     U16         in_my;          /* we're compiling a "my"/"our" declaration */
102     U8          lex_state;      /* next token is determined */
103     U8          error_count;    /* how many compile errors so far, max 10 */
104     HV          *in_my_stash;   /* declared class of this "my" declaration */
105     PerlIO      *rsfp;          /* current source file pointer */
106     AV          *rsfp_filters;  /* holds chain of active source filters */
107
108     YYSTYPE     nextval[5];     /* value of next token, if any */
109     I32         nexttype[5];    /* type of next token */
110     U8          nexttoke;
111     U8          form_lex_state; /* remember lex_state when parsing fmt */
112     U8          lex_fakeeof;    /* precedence at which to fake EOF */
113     U8          lex_flags;
114     COP         *saved_curcop;  /* the previous PL_curcop */
115     char        tokenbuf[256];
116     line_t      herelines;      /* number of lines in here-doc */
117     line_t      preambling;     /* line # when processing $ENV{PERL5DB} */
118
119     yy_parser_signature *signature; /* parser state of a subroutine signature */
120     bool        sig_seen;       /* the currently parsing sub has a signature */
121
122     bool        recheck_charset_validity;
123
124     PERL_BITFIELD16     in_pod:1;      /* lexer is within a =pod section */
125     PERL_BITFIELD16     filtered:1;    /* source filters in evalbytes */
126     PERL_BITFIELD16     saw_infix_sigil:1; /* saw & or * or % operator */
127     PERL_BITFIELD16     parsed_sub:1;  /* last thing parsed was a sub */
128 } yy_parser;
129
130 /* flags for lexer API */
131 #define LEX_STUFF_UTF8          0x00000001
132 #define LEX_KEEP_PREVIOUS       0x00000002
133
134 #ifdef PERL_CORE
135 # define LEX_START_SAME_FILTER  0x00000001
136 # define LEX_IGNORE_UTF8_HINTS  0x00000002
137 # define LEX_EVALBYTES          0x00000004
138 # define LEX_START_COPIED       0x00000008
139 # define LEX_DONT_CLOSE_RSFP    0x00000010
140 # define LEX_START_FLAGS \
141         (LEX_START_SAME_FILTER|LEX_START_COPIED \
142         |LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES|LEX_DONT_CLOSE_RSFP)
143 #endif
144
145 /* flags for parser API */
146 #define PARSE_OPTIONAL          0x00000001
147
148 /* values for lex_fakeeof */
149 enum {
150     LEX_FAKEEOF_NEVER,      /* don't fake EOF */
151     LEX_FAKEEOF_CLOSING,    /* fake EOF at unmatched closing punctuation */
152     LEX_FAKEEOF_NONEXPR,    /* ... and at token that can't be in expression */
153     LEX_FAKEEOF_LOWLOGIC,   /* ... and at low-precedence logic operator */
154     LEX_FAKEEOF_COMMA,      /* ... and at comma */
155     LEX_FAKEEOF_ASSIGN,     /* ... and at assignment operator */
156     LEX_FAKEEOF_IFELSE,     /* ... and at ?: operator */
157     LEX_FAKEEOF_RANGE,      /* ... and at range operator */
158     LEX_FAKEEOF_LOGIC,      /* ... and at logic operator */
159     LEX_FAKEEOF_BITWISE,    /* ... and at bitwise operator */
160     LEX_FAKEEOF_COMPARE,    /* ... and at comparison operator */
161     LEX_FAKEEOF_MAX
162 };
163
164 /*
165  * ex: set ts=8 sts=4 sw=4 et:
166  */