зеркало из https://github.com/github/ruby.git
[PRISM] Add --dump=prism mode (#8643)
This commit is contained in:
Родитель
34add1e595
Коммит
d705885286
21
common.mk
21
common.mk
|
@ -15327,6 +15327,25 @@ ruby.$(OBJEXT): $(top_srcdir)/internal/thread.h
|
||||||
ruby.$(OBJEXT): $(top_srcdir)/internal/variable.h
|
ruby.$(OBJEXT): $(top_srcdir)/internal/variable.h
|
||||||
ruby.$(OBJEXT): $(top_srcdir)/internal/vm.h
|
ruby.$(OBJEXT): $(top_srcdir)/internal/vm.h
|
||||||
ruby.$(OBJEXT): $(top_srcdir)/internal/warnings.h
|
ruby.$(OBJEXT): $(top_srcdir)/internal/warnings.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/defines.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/node.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/pack.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/parser.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/prism.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/regexp.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/unescape.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_buffer.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_char.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_constant_pool.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_list.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_memchr.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_newline_list.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_state_stack.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_string.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_string_list.h
|
||||||
|
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_strpbrk.h
|
||||||
ruby.$(OBJEXT): {$(VPATH)}assert.h
|
ruby.$(OBJEXT): {$(VPATH)}assert.h
|
||||||
ruby.$(OBJEXT): {$(VPATH)}atomic.h
|
ruby.$(OBJEXT): {$(VPATH)}atomic.h
|
||||||
ruby.$(OBJEXT): {$(VPATH)}backward/2/assume.h
|
ruby.$(OBJEXT): {$(VPATH)}backward/2/assume.h
|
||||||
|
@ -15504,6 +15523,8 @@ ruby.$(OBJEXT): {$(VPATH)}missing.h
|
||||||
ruby.$(OBJEXT): {$(VPATH)}node.h
|
ruby.$(OBJEXT): {$(VPATH)}node.h
|
||||||
ruby.$(OBJEXT): {$(VPATH)}onigmo.h
|
ruby.$(OBJEXT): {$(VPATH)}onigmo.h
|
||||||
ruby.$(OBJEXT): {$(VPATH)}oniguruma.h
|
ruby.$(OBJEXT): {$(VPATH)}oniguruma.h
|
||||||
|
ruby.$(OBJEXT): {$(VPATH)}prism/ast.h
|
||||||
|
ruby.$(OBJEXT): {$(VPATH)}prism/version.h
|
||||||
ruby.$(OBJEXT): {$(VPATH)}rjit.h
|
ruby.$(OBJEXT): {$(VPATH)}rjit.h
|
||||||
ruby.$(OBJEXT): {$(VPATH)}ruby.c
|
ruby.$(OBJEXT): {$(VPATH)}ruby.c
|
||||||
ruby.$(OBJEXT): {$(VPATH)}ruby_assert.h
|
ruby.$(OBJEXT): {$(VPATH)}ruby_assert.h
|
||||||
|
|
27
ruby.c
27
ruby.c
|
@ -56,6 +56,7 @@
|
||||||
#include "internal/thread.h"
|
#include "internal/thread.h"
|
||||||
#include "internal/ruby_parser.h"
|
#include "internal/ruby_parser.h"
|
||||||
#include "internal/variable.h"
|
#include "internal/variable.h"
|
||||||
|
#include "prism/prism.h"
|
||||||
#include "ruby/encoding.h"
|
#include "ruby/encoding.h"
|
||||||
#include "ruby/thread.h"
|
#include "ruby/thread.h"
|
||||||
#include "ruby/util.h"
|
#include "ruby/util.h"
|
||||||
|
@ -153,6 +154,8 @@ enum feature_flag_bits {
|
||||||
SEP \
|
SEP \
|
||||||
X(parsetree_with_comment) \
|
X(parsetree_with_comment) \
|
||||||
SEP \
|
SEP \
|
||||||
|
X(prism) \
|
||||||
|
SEP \
|
||||||
X(insns) \
|
X(insns) \
|
||||||
SEP \
|
SEP \
|
||||||
X(insns_without_opt) \
|
X(insns_without_opt) \
|
||||||
|
@ -166,7 +169,7 @@ enum dump_flag_bits {
|
||||||
DUMP_BIT(parsetree_with_comment)),
|
DUMP_BIT(parsetree_with_comment)),
|
||||||
dump_exit_bits = (DUMP_BIT(yydebug) | DUMP_BIT(syntax) |
|
dump_exit_bits = (DUMP_BIT(yydebug) | DUMP_BIT(syntax) |
|
||||||
DUMP_BIT(parsetree) | DUMP_BIT(parsetree_with_comment) |
|
DUMP_BIT(parsetree) | DUMP_BIT(parsetree_with_comment) |
|
||||||
DUMP_BIT(insns) | DUMP_BIT(insns_without_opt))
|
DUMP_BIT(prism) | DUMP_BIT(insns) | DUMP_BIT(insns_without_opt))
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
@ -353,7 +356,7 @@ usage(const char *name, int help, int highlight, int columns)
|
||||||
|
|
||||||
static const struct ruby_opt_message help_msg[] = {
|
static const struct ruby_opt_message help_msg[] = {
|
||||||
M("--copyright", "", "print the copyright"),
|
M("--copyright", "", "print the copyright"),
|
||||||
M("--dump={insns|parsetree|...}[,...]", "",
|
M("--dump={insns|parsetree|prism|...}[,...]", "",
|
||||||
"dump debug information. see below for available dump list"),
|
"dump debug information. see below for available dump list"),
|
||||||
M("--enable={jit|rubyopt|...}[,...]", ", --disable={jit|rubyopt|...}[,...]",
|
M("--enable={jit|rubyopt|...}[,...]", ", --disable={jit|rubyopt|...}[,...]",
|
||||||
"enable or disable features. see below for available features"),
|
"enable or disable features. see below for available features"),
|
||||||
|
@ -372,6 +375,7 @@ usage(const char *name, int help, int highlight, int columns)
|
||||||
M("yydebug(+error-tolerant)", "", "yydebug of yacc parser generator"),
|
M("yydebug(+error-tolerant)", "", "yydebug of yacc parser generator"),
|
||||||
M("parsetree(+error-tolerant)","", "AST"),
|
M("parsetree(+error-tolerant)","", "AST"),
|
||||||
M("parsetree_with_comment(+error-tolerant)", "", "AST with comments"),
|
M("parsetree_with_comment(+error-tolerant)", "", "AST with comments"),
|
||||||
|
M("prism", "", "Prism AST with comments"),
|
||||||
};
|
};
|
||||||
static const struct ruby_opt_message features[] = {
|
static const struct ruby_opt_message features[] = {
|
||||||
M("gems", "", "rubygems (only for debugging, default: "DEFAULT_RUBYGEMS_ENABLED")"),
|
M("gems", "", "rubygems (only for debugging, default: "DEFAULT_RUBYGEMS_ENABLED")"),
|
||||||
|
@ -2333,6 +2337,25 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
|
||||||
rb_define_global_function("chomp", rb_f_chomp, -1);
|
rb_define_global_function("chomp", rb_f_chomp, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dump & (DUMP_BIT(prism))) {
|
||||||
|
pm_parser_t parser;
|
||||||
|
if (opt->e_script) {
|
||||||
|
size_t len = RSTRING_LEN(opt->e_script);
|
||||||
|
pm_parser_init(&parser, (const uint8_t *) RSTRING_PTR(opt->e_script), len, "-e");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pm_string_t input;
|
||||||
|
char *filepath = RSTRING_PTR(opt->script_name);
|
||||||
|
pm_string_mapped_init(&input, filepath);
|
||||||
|
pm_parser_init(&parser, pm_string_source(&input), pm_string_length(&input), filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
pm_node_t *node = pm_parse(&parser);
|
||||||
|
pm_print_node(&parser, node);
|
||||||
|
pm_node_destroy(&parser, node);
|
||||||
|
pm_parser_free(&parser);
|
||||||
|
}
|
||||||
|
|
||||||
if (dump & (DUMP_BIT(parsetree)|DUMP_BIT(parsetree_with_comment))) {
|
if (dump & (DUMP_BIT(parsetree)|DUMP_BIT(parsetree_with_comment))) {
|
||||||
rb_io_write(rb_stdout, rb_parser_dump_tree(ast->body.root, dump & DUMP_BIT(parsetree_with_comment)));
|
rb_io_write(rb_stdout, rb_parser_dump_tree(ast->body.root, dump & DUMP_BIT(parsetree_with_comment)));
|
||||||
rb_io_flush(rb_stdout);
|
rb_io_flush(rb_stdout);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче