mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00

Refactor parser compile functions to reduce the dependence on ruby functions. This commit includes these changes 1. Refactor `gets`, `input` and `gets_` of `parser_params` Parser needs two different data structure to get next line, function (`gets`) and input data (`input`). However `gets_` is used for both function (`call`) and input data (`ptr`). `call` is used for managing general callback function when `rb_ruby_parser_compile_generic` is used. `ptr` is used for managing the current pointer on String when `parser_compile_string` is used. This commit changes parser to used only `gets` and `input` then removes `gets_`. 2. Move parser_compile functions and `gets` functions from parse.y to ruby_parser.c This change reduces the dependence on ruby functions from parser. 3. Change ruby_parser and ripper to take care of `VALUE input` GC mark Move the responsibility of calling `rb_gc_mark` for `VALUE input` from parser to ruby_parser and ripper. `input` is arbitrary data pointer from the viewpoint of parser. 4. Introduce rb_parser_compile_array function Caller of `rb_parser_compile_generic` needs to take care about GC because ruby_parser doesn’t know about the detail of `lex_gets` and `input`. Introduce `rb_parser_compile_array` to reduce the complexity of ast.c.
100 lines
3.7 KiB
C
100 lines
3.7 KiB
C
#ifndef INTERNAL_RUBY_PARSE_H
|
|
#define INTERNAL_RUBY_PARSE_H
|
|
|
|
#include "internal.h"
|
|
#include "internal/bignum.h"
|
|
#include "internal/compilers.h"
|
|
#include "internal/complex.h"
|
|
#include "internal/parse.h"
|
|
#include "internal/rational.h"
|
|
#include "rubyparser.h"
|
|
#include "vm.h"
|
|
|
|
struct lex_pointer_string {
|
|
VALUE str;
|
|
long ptr;
|
|
};
|
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
|
#ifdef UNIVERSAL_PARSER
|
|
const rb_parser_config_t *rb_ruby_parser_config(void);
|
|
rb_parser_t *rb_parser_params_new(void);
|
|
#endif
|
|
VALUE rb_parser_set_context(VALUE, const struct rb_iseq_struct *, int);
|
|
VALUE rb_parser_new(void);
|
|
rb_ast_t *rb_parser_compile_string_path(VALUE vparser, VALUE fname, VALUE src, int line);
|
|
VALUE rb_str_new_parser_string(rb_parser_string_t *str);
|
|
VALUE rb_str_new_mutable_parser_string(rb_parser_string_t *str);
|
|
VALUE rb_parser_lex_get_str(struct lex_pointer_string *ptr_str);
|
|
|
|
VALUE rb_node_str_string_val(const NODE *);
|
|
VALUE rb_node_sym_string_val(const NODE *);
|
|
VALUE rb_node_dstr_string_val(const NODE *);
|
|
VALUE rb_node_regx_string_val(const NODE *);
|
|
VALUE rb_node_dregx_string_val(const NODE *);
|
|
VALUE rb_node_line_lineno_val(const NODE *);
|
|
VALUE rb_node_file_path_val(const NODE *);
|
|
VALUE rb_node_encoding_val(const NODE *);
|
|
|
|
VALUE rb_node_integer_literal_val(const NODE *);
|
|
VALUE rb_node_float_literal_val(const NODE *);
|
|
VALUE rb_node_rational_literal_val(const NODE *);
|
|
VALUE rb_node_imaginary_literal_val(const NODE *);
|
|
RUBY_SYMBOL_EXPORT_END
|
|
|
|
VALUE rb_parser_end_seen_p(VALUE);
|
|
VALUE rb_parser_encoding(VALUE);
|
|
VALUE rb_parser_set_yydebug(VALUE, VALUE);
|
|
VALUE rb_parser_build_script_lines_from(rb_parser_ary_t *script_lines);
|
|
void rb_parser_aset_script_lines_for(VALUE path, rb_parser_ary_t *script_lines);
|
|
void rb_parser_set_options(VALUE, int, int, int, int);
|
|
void *rb_parser_load_file(VALUE parser, VALUE name);
|
|
void rb_parser_set_script_lines(VALUE vparser);
|
|
void rb_parser_error_tolerant(VALUE vparser);
|
|
void rb_parser_keep_tokens(VALUE vparser);
|
|
|
|
rb_ast_t *rb_parser_compile_string(VALUE, const char*, VALUE, int);
|
|
rb_ast_t *rb_parser_compile_file_path(VALUE vparser, VALUE fname, VALUE input, int line);
|
|
rb_ast_t *rb_parser_compile_generic(VALUE vparser, rb_parser_lex_gets_func *lex_gets, VALUE fname, VALUE input, int line);
|
|
rb_ast_t *rb_parser_compile_array(VALUE vparser, VALUE fname, VALUE array, int start);
|
|
|
|
enum lex_state_bits {
|
|
EXPR_BEG_bit, /* ignore newline, +/- is a sign. */
|
|
EXPR_END_bit, /* newline significant, +/- is an operator. */
|
|
EXPR_ENDARG_bit, /* ditto, and unbound braces. */
|
|
EXPR_ENDFN_bit, /* ditto, and unbound braces. */
|
|
EXPR_ARG_bit, /* newline significant, +/- is an operator. */
|
|
EXPR_CMDARG_bit, /* newline significant, +/- is an operator. */
|
|
EXPR_MID_bit, /* newline significant, +/- is an operator. */
|
|
EXPR_FNAME_bit, /* ignore newline, no reserved words. */
|
|
EXPR_DOT_bit, /* right after `.', `&.' or `::', no reserved words. */
|
|
EXPR_CLASS_bit, /* immediate after `class', no here document. */
|
|
EXPR_LABEL_bit, /* flag bit, label is allowed. */
|
|
EXPR_LABELED_bit, /* flag bit, just after a label. */
|
|
EXPR_FITEM_bit, /* symbol literal as FNAME. */
|
|
EXPR_MAX_STATE
|
|
};
|
|
/* examine combinations */
|
|
enum lex_state_e {
|
|
#define DEF_EXPR(n) EXPR_##n = (1 << EXPR_##n##_bit)
|
|
DEF_EXPR(BEG),
|
|
DEF_EXPR(END),
|
|
DEF_EXPR(ENDARG),
|
|
DEF_EXPR(ENDFN),
|
|
DEF_EXPR(ARG),
|
|
DEF_EXPR(CMDARG),
|
|
DEF_EXPR(MID),
|
|
DEF_EXPR(FNAME),
|
|
DEF_EXPR(DOT),
|
|
DEF_EXPR(CLASS),
|
|
DEF_EXPR(LABEL),
|
|
DEF_EXPR(LABELED),
|
|
DEF_EXPR(FITEM),
|
|
EXPR_VALUE = EXPR_BEG,
|
|
EXPR_BEG_ANY = (EXPR_BEG | EXPR_MID | EXPR_CLASS),
|
|
EXPR_ARG_ANY = (EXPR_ARG | EXPR_CMDARG),
|
|
EXPR_END_ANY = (EXPR_END | EXPR_ENDARG | EXPR_ENDFN),
|
|
EXPR_NONE = 0
|
|
};
|
|
|
|
#endif /* INTERNAL_RUBY_PARSE_H */
|