xref: /PHP-8.3/Zend/zend_language_scanner.h (revision bf1cfc07)
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 typedef struct _zend_lex_state {
24 	unsigned int yy_leng;
25 	unsigned char *yy_start;
26 	unsigned char *yy_text;
27 	unsigned char *yy_cursor;
28 	unsigned char *yy_marker;
29 	unsigned char *yy_limit;
30 	int yy_state;
31 	zend_stack state_stack;
32 	zend_ptr_stack heredoc_label_stack;
33 	zend_stack nest_location_stack; /* for syntax error reporting */
34 
35 	zend_file_handle *in;
36 	uint32_t lineno;
37 	zend_string *filename;
38 
39 	/* original (unfiltered) script */
40 	unsigned char *script_org;
41 	size_t script_org_size;
42 
43 	/* filtered script */
44 	unsigned char *script_filtered;
45 	size_t script_filtered_size;
46 
47 	/* input/output filters */
48 	zend_encoding_filter input_filter;
49 	zend_encoding_filter output_filter;
50 	const zend_encoding *script_encoding;
51 
52 	/* hooks */
53 	void (*on_event)(
54 		zend_php_scanner_event event, int token, int line,
55 		const char *text, size_t length, void *context);
56 	void *on_event_context;
57 
58 	zend_ast *ast;
59 	zend_arena *ast_arena;
60 } zend_lex_state;
61 
62 typedef struct _zend_heredoc_label {
63 	char *label;
64 	int length;
65 	int indentation;
66 	bool indentation_uses_spaces;
67 } zend_heredoc_label;
68 
69 /* Track locations of unclosed {, [, (, etc. for better syntax error reporting */
70 typedef struct _zend_nest_location {
71 	char text;
72 	int  lineno;
73 } zend_nest_location;
74 
75 BEGIN_EXTERN_C()
76 ZEND_API void zend_save_lexical_state(zend_lex_state *lex_state);
77 ZEND_API void zend_restore_lexical_state(zend_lex_state *lex_state);
78 ZEND_API void zend_prepare_string_for_scanning(zval *str, zend_string *filename);
79 ZEND_API void zend_multibyte_yyinput_again(zend_encoding_filter old_input_filter, const zend_encoding *old_encoding);
80 ZEND_API zend_result zend_multibyte_set_filter(const zend_encoding *onetime_encoding);
81 ZEND_API zend_result zend_lex_tstring(zval *zv, unsigned char *ident);
82 
83 END_EXTERN_C()
84 
85 #endif
86