Ruby: internal/parse.h Source File

Ruby 3.4.7p58 (2025-10-08 revision 7a5688e2a27668e48f8d6ff4af5b2208b98a2f5e)

parse.h
1#ifndef INTERNAL_PARSE_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_PARSE_H
11#include <limits.h>
12#include "rubyparser.h"
13#include "internal/static_assert.h"
14
15// The default parser to use for Ruby code.
16typedef enum {
17 RB_DEFAULT_PARSER_PARSE_Y,
18 RB_DEFAULT_PARSER_PRISM,
19} ruby_default_parser_enum;
20
21ruby_default_parser_enum rb_ruby_default_parser(void);
22void rb_ruby_default_parser_set(ruby_default_parser_enum parser);
23
24#define rb_ruby_prism_p() (rb_ruby_default_parser() == RB_DEFAULT_PARSER_PRISM)
25
26#ifdef UNIVERSAL_PARSER
27#define rb_encoding const void
28#endif
29
30struct rb_iseq_struct; /* in vm_core.h */
31
32/* structs for managing terminator of string literal and heredocment */
33 typedef struct rb_strterm_literal_struct {
34 long nest;
35 int func; /* STR_FUNC_* (e.g., STR_FUNC_ESCAPE and STR_FUNC_EXPAND) */
36 int paren; /* '(' of `%q(...)` */
37 int term; /* ')' of `%q(...)` */
38} rb_strterm_literal_t;
39
40 typedef struct rb_strterm_heredoc_struct {
41 rb_parser_string_t *lastline; /* the string of line that contains `<<"END"` */
42 long offset; /* the column of END in `<<"END"` */
43 int sourceline; /* lineno of the line that contains `<<"END"` */
44 unsigned length; /* the length of END in `<<"END"` */
45 uint8_t quote;
46 uint8_t func;
47} rb_strterm_heredoc_t;
48
49#define HERETERM_LENGTH_MAX UINT_MAX
50
51 typedef struct rb_strterm_struct {
52 bool heredoc;
53 union {
54 rb_strterm_literal_t literal;
55 rb_strterm_heredoc_t heredoc;
56 } u;
57} rb_strterm_t;
58
59/* parse.y */
60void rb_ruby_parser_mark(void *ptr);
61size_t rb_ruby_parser_memsize(const void *ptr);
62
63void rb_ruby_parser_set_options(rb_parser_t *p, int print, int loop, int chomp, int split);
64rb_parser_t *rb_ruby_parser_set_context(rb_parser_t *p, const struct rb_iseq_struct *base, int main);
65void rb_ruby_parser_set_script_lines(rb_parser_t *p);
66void rb_ruby_parser_error_tolerant(rb_parser_t *p);
67void rb_ruby_parser_keep_tokens(rb_parser_t *p);
68typedef rb_parser_string_t*(rb_parser_lex_gets_func)(struct parser_params*, rb_parser_input_data, int);
69rb_ast_t *rb_parser_compile(rb_parser_t *p, rb_parser_lex_gets_func *gets, VALUE fname, rb_parser_input_data input, int line);
70
71RUBY_SYMBOL_EXPORT_BEGIN
72
73rb_encoding *rb_ruby_parser_encoding(rb_parser_t *p);
74int rb_ruby_parser_end_seen_p(rb_parser_t *p);
75int rb_ruby_parser_set_yydebug(rb_parser_t *p, int flag);
76rb_parser_string_t *rb_str_to_parser_string(rb_parser_t *p, VALUE str);
77void rb_parser_string_free(rb_parser_t *p, rb_parser_string_t *str);
78
79int rb_parser_dvar_defined_ref(struct parser_params*, ID, ID**);
80 ID rb_parser_internal_id(struct parser_params*);
81typedef void (*rb_parser_reg_fragment_error_func)(struct parser_params *, VALUE);
82int rb_parser_reg_fragment_check(struct parser_params*, rb_parser_string_t*, int, rb_parser_reg_fragment_error_func);
83int rb_reg_named_capture_assign_iter_impl(struct parser_params *p, const char *s, long len, rb_encoding *enc, NODE **succ_block, const rb_code_location_t *loc, rb_parser_assignable_func assignable);
84int rb_parser_local_defined(struct parser_params *p, ID id, const struct rb_iseq_struct *iseq);
85NODE *rb_parser_assignable(struct parser_params *p, ID id, NODE *val, const YYLTYPE *loc);
86
87RUBY_SYMBOL_EXPORT_END
88
89#ifndef UNIVERSAL_PARSER
90rb_parser_t *rb_ruby_parser_allocate(void);
91rb_parser_t *rb_ruby_parser_new(void);
92#endif
93
94#ifdef RIPPER
95void ripper_parser_mark(void *ptr);
96void ripper_parser_free(void *ptr);
97size_t ripper_parser_memsize(const void *ptr);
98void ripper_error(struct parser_params *p);
99 VALUE ripper_value(struct parser_params *p);
100int rb_ruby_parser_get_yydebug(rb_parser_t *p);
101void rb_ruby_parser_set_value(rb_parser_t *p, VALUE value);
102int rb_ruby_parser_error_p(rb_parser_t *p);
103 VALUE rb_ruby_parser_debug_output(rb_parser_t *p);
104void rb_ruby_parser_set_debug_output(rb_parser_t *p, VALUE output);
105 VALUE rb_ruby_parser_parsing_thread(rb_parser_t *p);
106void rb_ruby_parser_set_parsing_thread(rb_parser_t *p, VALUE parsing_thread);
107void rb_ruby_parser_ripper_initialize(rb_parser_t *p, rb_parser_lex_gets_func *gets, rb_parser_input_data input, VALUE sourcefile_string, const char *sourcefile, int sourceline);
108 VALUE rb_ruby_parser_result(rb_parser_t *p);
109rb_encoding *rb_ruby_parser_enc(rb_parser_t *p);
110 VALUE rb_ruby_parser_ruby_sourcefile_string(rb_parser_t *p);
111int rb_ruby_parser_ruby_sourceline(rb_parser_t *p);
112int rb_ruby_parser_lex_state(rb_parser_t *p);
113void rb_ruby_ripper_parse0(rb_parser_t *p);
114int rb_ruby_ripper_dedent_string(rb_parser_t *p, rb_parser_string_t *string, int width);
115int rb_ruby_ripper_initialized_p(rb_parser_t *p);
116void rb_ruby_ripper_parser_initialize(rb_parser_t *p);
117long rb_ruby_ripper_column(rb_parser_t *p);
118long rb_ruby_ripper_token_len(rb_parser_t *p);
119rb_parser_string_t *rb_ruby_ripper_lex_lastline(rb_parser_t *p);
120 VALUE rb_ruby_ripper_lex_state_name(struct parser_params *p, int state);
121#ifdef UNIVERSAL_PARSER
122rb_parser_t *rb_ripper_parser_params_allocate(const rb_parser_config_t *config);
123#endif
124struct parser_params *rb_ruby_ripper_parser_allocate(void);
125#endif
126
127#ifdef UNIVERSAL_PARSER
128#undef rb_encoding
129#endif
130
131#endif /* INTERNAL_PARSE_H */
len
int len
Length of the buffer.
Definition io.h:8
parser_params
Definition parse.c:543
rb_iseq_struct
Definition vm_core.h:568
rb_strterm_heredoc_struct
Definition parse.h:40
rb_strterm_literal_struct
Definition parse.h:33
rb_strterm_struct
Definition parse.h:51
ID
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40