diff options
-rw-r--r-- | prism/api_pack.c | 9 | ||||
-rw-r--r-- | prism/defines.h | 21 | ||||
-rw-r--r-- | prism/extension.c | 20 | ||||
-rw-r--r-- | prism/pack.h | 4 | ||||
-rw-r--r-- | prism/parser.h | 2 | ||||
-rw-r--r-- | prism/prettyprint.h | 4 | ||||
-rw-r--r-- | prism/prism.c | 10 | ||||
-rw-r--r-- | test/prism/ruby_parser_test.rb | 3 |
8 files changed, 60 insertions, 13 deletions
diff --git a/prism/api_pack.c b/prism/api_pack.c index c9f0b18a39..98509ae65c 100644 --- a/prism/api_pack.c +++ b/prism/api_pack.c @@ -1,5 +1,12 @@ #include "prism/extension.h" +#ifdef PRISM_EXCLUDE_PACK + +void +Init_prism_pack(void) {} + +#else + static VALUE rb_cPrism; static VALUE rb_cPrismPack; static VALUE rb_cPrismPackDirective; @@ -265,3 +272,5 @@ Init_prism_pack(void) { pack_symbol = ID2SYM(rb_intern("pack")); unpack_symbol = ID2SYM(rb_intern("unpack")); } + +#endif diff --git a/prism/defines.h b/prism/defines.h index aca3c6dc08..2fe73fe3d8 100644 --- a/prism/defines.h +++ b/prism/defines.h @@ -182,4 +182,25 @@ #endif #endif +/** + * If PRISM_BUILD_MINIMAL is defined, then we're going to define every possible + * switch that will turn off certain features of prism. + */ +#ifdef PRISM_BUILD_MINIMAL + /** Exclude the serialization API. */ + #define PRISM_EXCLUDE_SERIALIZATION + + /** Exclude the JSON serialization API. */ + #define PRISM_EXCLUDE_JSON + + /** Exclude the Array#pack parser API. */ + #define PRISM_EXCLUDE_PACK + + /** Exclude the prettyprint API. */ + #define PRISM_EXCLUDE_PRETTYPRINT + + /** Exclude the full set of encodings, using the minimal only. */ + #define PRISM_ENCODING_EXCLUDE_FULL +#endif + #endif diff --git a/prism/extension.c b/prism/extension.c index 7c8636e3df..88ba006ac2 100644 --- a/prism/extension.c +++ b/prism/extension.c @@ -270,6 +270,8 @@ file_options(int argc, VALUE *argv, pm_string_t *input, pm_options_t *options) { } } +#ifndef PRISM_EXCLUDE_SERIALIZATION + /******************************************************************************/ /* Serializing the AST */ /******************************************************************************/ @@ -351,6 +353,8 @@ dump_file(int argc, VALUE *argv, VALUE self) { return value; } +#endif + /******************************************************************************/ /* Extracting values for the parse result */ /******************************************************************************/ @@ -1129,6 +1133,8 @@ profile_file(VALUE self, VALUE filepath) { return Qnil; } +#ifndef PRISM_EXCLUDE_PRETTYPRINT + /** * call-seq: * Debug::inspect_node(source) -> inspected @@ -1159,6 +1165,8 @@ inspect_node(VALUE self, VALUE source) { return string; } +#endif + /** * call-seq: * Debug::format_errors(source, colorize) -> String @@ -1349,8 +1357,6 @@ Init_prism(void) { rb_define_const(rb_cPrism, "VERSION", rb_str_new2(EXPECTED_PRISM_VERSION)); // First, the functions that have to do with lexing and parsing. - rb_define_singleton_method(rb_cPrism, "dump", dump, -1); - rb_define_singleton_method(rb_cPrism, "dump_file", dump_file, -1); rb_define_singleton_method(rb_cPrism, "lex", lex, -1); rb_define_singleton_method(rb_cPrism, "lex_file", lex_file, -1); rb_define_singleton_method(rb_cPrism, "parse", parse, -1); @@ -1363,6 +1369,11 @@ Init_prism(void) { rb_define_singleton_method(rb_cPrism, "parse_success?", parse_success_p, -1); rb_define_singleton_method(rb_cPrism, "parse_file_success?", parse_file_success_p, -1); +#ifndef PRISM_EXCLUDE_SERIALIZATION + rb_define_singleton_method(rb_cPrism, "dump", dump, -1); + rb_define_singleton_method(rb_cPrism, "dump_file", dump_file, -1); +#endif + // Next, the functions that will be called by the parser to perform various // internal tasks. We expose these to make them easier to test. VALUE rb_cPrismDebug = rb_define_module_under(rb_cPrism, "Debug"); @@ -1370,10 +1381,13 @@ Init_prism(void) { rb_define_singleton_method(rb_cPrismDebug, "integer_parse", integer_parse, 1); rb_define_singleton_method(rb_cPrismDebug, "memsize", memsize, 1); rb_define_singleton_method(rb_cPrismDebug, "profile_file", profile_file, 1); - rb_define_singleton_method(rb_cPrismDebug, "inspect_node", inspect_node, 1); rb_define_singleton_method(rb_cPrismDebug, "format_errors", format_errors, 2); rb_define_singleton_method(rb_cPrismDebug, "static_inspect", static_inspect, -1); +#ifndef PRISM_EXCLUDE_PRETTYPRINT + rb_define_singleton_method(rb_cPrismDebug, "inspect_node", inspect_node, 1); +#endif + // Next, define the functions that are exposed through the private // Debug::Encoding class. rb_cPrismDebugEncoding = rb_define_class_under(rb_cPrismDebug, "Encoding", rb_cObject); diff --git a/prism/pack.h b/prism/pack.h index cfdc251fe6..0b0b4b19cc 100644 --- a/prism/pack.h +++ b/prism/pack.h @@ -6,6 +6,8 @@ #ifndef PRISM_PACK_H #define PRISM_PACK_H +#include "prism/defines.h" + // We optionally support parsing String#pack templates. For systems that don't // want or need this functionality, it can be turned off with the // PRISM_EXCLUDE_PACK define. @@ -15,8 +17,6 @@ void pm_pack_parse(void); #else -#include "prism/defines.h" - #include <stdint.h> #include <stdlib.h> diff --git a/prism/parser.h b/prism/parser.h index 7e4bb99197..f706a67de7 100644 --- a/prism/parser.h +++ b/prism/parser.h @@ -6,8 +6,8 @@ #ifndef PRISM_PARSER_H #define PRISM_PARSER_H -#include "prism/ast.h" #include "prism/defines.h" +#include "prism/ast.h" #include "prism/encoding.h" #include "prism/options.h" #include "prism/util/pm_constant_pool.h" diff --git a/prism/prettyprint.h b/prism/prettyprint.h index ea11b4a246..5a52b2b6b8 100644 --- a/prism/prettyprint.h +++ b/prism/prettyprint.h @@ -6,14 +6,14 @@ #ifndef PRISM_PRETTYPRINT_H #define PRISM_PRETTYPRINT_H +#include "prism/defines.h" + #ifdef PRISM_EXCLUDE_PRETTYPRINT void pm_prettyprint(void); #else -#include "prism/defines.h" - #include <stdio.h> #include "prism/ast.h" diff --git a/prism/prism.c b/prism/prism.c index 58c70dba69..6f2ab81e9a 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -10842,9 +10842,9 @@ parser_lex(pm_parser_t *parser) { break; } - parser->current.end = breakpoint + 1; - pm_regexp_token_buffer_escape(parser, &token_buffer); breakpoint++; + parser->current.end = breakpoint; + pm_regexp_token_buffer_escape(parser, &token_buffer); token_buffer.base.cursor = breakpoint; /* fallthrough */ @@ -11069,9 +11069,9 @@ parser_lex(pm_parser_t *parser) { // If we hit a \r\n sequence, then we need to treat it // as a newline. - parser->current.end = breakpoint + 1; - pm_token_buffer_escape(parser, &token_buffer); breakpoint++; + parser->current.end = breakpoint; + pm_token_buffer_escape(parser, &token_buffer); token_buffer.cursor = breakpoint; /* fallthrough */ @@ -11321,8 +11321,8 @@ parser_lex(pm_parser_t *parser) { // If we hit a \r\n sequence, then we want to replace it // with a single \n character in the final string. - pm_token_buffer_escape(parser, &token_buffer); breakpoint++; + pm_token_buffer_escape(parser, &token_buffer); token_buffer.cursor = breakpoint; /* fallthrough */ diff --git a/test/prism/ruby_parser_test.rb b/test/prism/ruby_parser_test.rb index e06b7ae438..c9883574a6 100644 --- a/test/prism/ruby_parser_test.rb +++ b/test/prism/ruby_parser_test.rb @@ -68,6 +68,9 @@ module Prism seattlerb/heredoc_bad_hex_escape.txt seattlerb/heredoc_bad_oct_escape.txt seattlerb/heredoc_with_extra_carriage_horrible_mix.txt + seattlerb/heredoc_with_extra_carriage_returns_windows.txt + seattlerb/heredoc_with_only_carriage_returns_windows.txt + seattlerb/heredoc_with_only_carriage_returns.txt spanning_heredoc_newlines.txt spanning_heredoc.txt tilde_heredocs.txt |