xref: /php-src/Zend/zend_language_scanner.h (revision 6335264c)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) Zend Technologies Ltd. (http://www.zend.com)           |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Authors: Andi Gutmans <andi@php.net>                                 |
16    |          Zeev Suraski <zeev@php.net>                                 |
17    +----------------------------------------------------------------------+
18 */
19 
20 #ifndef ZEND_SCANNER_H
21 #define ZEND_SCANNER_H
22 
23 #include "zend_globals.h"
24 
25 typedef struct _zend_lex_state {
26 	unsigned int yy_leng;
27 	unsigned char *yy_start;
28 	unsigned char *yy_text;
29 	unsigned char *yy_cursor;
30 	unsigned char *yy_marker;
31 	unsigned char *yy_limit;
32 	int yy_state;
33 	zend_stack state_stack;
34 	zend_ptr_stack heredoc_label_stack;
35 	zend_stack nest_location_stack; /* for syntax error reporting */
36 
37 	zend_file_handle *in;
38 	uint32_t lineno;
39 	zend_string *filename;
40 
41 	/* original (unfiltered) script */
42 	unsigned char *script_org;
43 	size_t script_org_size;
44 
45 	/* filtered script */
46 	unsigned char *script_filtered;
47 	size_t script_filtered_size;
48 
49 	/* input/output filters */
50 	zend_encoding_filter input_filter;
51 	zend_encoding_filter output_filter;
52 	const zend_encoding *script_encoding;
53 
54 	/* hooks */
55 	void (*on_event)(
56 		zend_php_scanner_event event, int token, int line,
57 		const char *text, size_t length, void *context);
58 	void *on_event_context;
59 
60 	zend_ast *ast;
61 	zend_arena *ast_arena;
62 } zend_lex_state;
63 
64 typedef struct _zend_heredoc_label {
65 	char *label;
66 	int length;
67 	int indentation;
68 	bool indentation_uses_spaces;
69 } zend_heredoc_label;
70 
71 /* Track locations of unclosed {, [, (, etc. for better syntax error reporting */
72 typedef struct _zend_nest_location {
73 	char text;
74 	int  lineno;
75 } zend_nest_location;
76 
77 BEGIN_EXTERN_C()
78 ZEND_API void zend_save_lexical_state(zend_lex_state *lex_state);
79 ZEND_API void zend_restore_lexical_state(zend_lex_state *lex_state);
80 ZEND_API void zend_prepare_string_for_scanning(zval *str, zend_string *filename);
81 ZEND_API void zend_multibyte_yyinput_again(zend_encoding_filter old_input_filter, const zend_encoding *old_encoding);
82 ZEND_API zend_result zend_multibyte_set_filter(const zend_encoding *onetime_encoding);
83 ZEND_API zend_result zend_lex_tstring(zval *zv, unsigned char *ident);
84 
85 END_EXTERN_C()
86 
87 #endif
88