Module: Prism::Serialize
- Defined in:
- lib/prism/serialize.rb
Overview
A module responsible for deserializing parse results.
Defined Under Namespace
Classes: Loader
Constant Summary collapse
- MAJOR_VERSION =
The major version of prism that we are expecting to find in the serialized strings.
1
- MINOR_VERSION =
The minor version of prism that we are expecting to find in the serialized strings.
2
- PATCH_VERSION =
The patch version of prism that we are expecting to find in the serialized strings.
0
- TOKEN_TYPES =
The token types that can be indexed by their enum values.
[ nil, :EOF, :MISSING, :NOT_PROVIDED, :AMPERSAND, :AMPERSAND_AMPERSAND, :AMPERSAND_AMPERSAND_EQUAL, :AMPERSAND_DOT, :AMPERSAND_EQUAL, :BACKTICK, :BACK_REFERENCE, :BANG, :BANG_EQUAL, :BANG_TILDE, :BRACE_LEFT, :BRACE_RIGHT, :BRACKET_LEFT, :BRACKET_LEFT_ARRAY, :BRACKET_LEFT_RIGHT, :BRACKET_LEFT_RIGHT_EQUAL, :BRACKET_RIGHT, :CARET, :CARET_EQUAL, :CHARACTER_LITERAL, :CLASS_VARIABLE, :COLON, :COLON_COLON, :COMMA, :COMMENT, :CONSTANT, :DOT, :DOT_DOT, :DOT_DOT_DOT, :EMBDOC_BEGIN, :EMBDOC_END, :EMBDOC_LINE, :EMBEXPR_BEGIN, :EMBEXPR_END, :EMBVAR, :EQUAL, :EQUAL_EQUAL, :EQUAL_EQUAL_EQUAL, :EQUAL_GREATER, :EQUAL_TILDE, :FLOAT, :FLOAT_IMAGINARY, :FLOAT_RATIONAL, :FLOAT_RATIONAL_IMAGINARY, :GLOBAL_VARIABLE, :GREATER, :GREATER_EQUAL, :GREATER_GREATER, :GREATER_GREATER_EQUAL, :HEREDOC_END, :HEREDOC_START, :IDENTIFIER, :IGNORED_NEWLINE, :INSTANCE_VARIABLE, :INTEGER, :INTEGER_IMAGINARY, :INTEGER_RATIONAL, :INTEGER_RATIONAL_IMAGINARY, :KEYWORD_ALIAS, :KEYWORD_AND, :KEYWORD_BEGIN, :KEYWORD_BEGIN_UPCASE, :KEYWORD_BREAK, :KEYWORD_CASE, :KEYWORD_CLASS, :KEYWORD_DEF, :KEYWORD_DEFINED, :KEYWORD_DO, :KEYWORD_DO_LOOP, :KEYWORD_ELSE, :KEYWORD_ELSIF, :KEYWORD_END, :KEYWORD_END_UPCASE, :KEYWORD_ENSURE, :KEYWORD_FALSE, :KEYWORD_FOR, :KEYWORD_IF, :KEYWORD_IF_MODIFIER, :KEYWORD_IN, :KEYWORD_MODULE, :KEYWORD_NEXT, :KEYWORD_NIL, :KEYWORD_NOT, :KEYWORD_OR, :KEYWORD_REDO, :KEYWORD_RESCUE, :KEYWORD_RESCUE_MODIFIER, :KEYWORD_RETRY, :KEYWORD_RETURN, :KEYWORD_SELF, :KEYWORD_SUPER, :KEYWORD_THEN, :KEYWORD_TRUE, :KEYWORD_UNDEF, :KEYWORD_UNLESS, :KEYWORD_UNLESS_MODIFIER, :KEYWORD_UNTIL, :KEYWORD_UNTIL_MODIFIER, :KEYWORD_WHEN, :KEYWORD_WHILE, :KEYWORD_WHILE_MODIFIER, :KEYWORD_YIELD, :KEYWORD___ENCODING__, :KEYWORD___FILE__, :KEYWORD___LINE__, :LABEL, :LABEL_END, :LAMBDA_BEGIN, :LESS, :LESS_EQUAL, :LESS_EQUAL_GREATER, :LESS_LESS, :LESS_LESS_EQUAL, :METHOD_NAME, :MINUS, :MINUS_EQUAL, :MINUS_GREATER, :NEWLINE, :NUMBERED_REFERENCE, :PARENTHESIS_LEFT, :PARENTHESIS_LEFT_PARENTHESES, :PARENTHESIS_RIGHT, :PERCENT, :PERCENT_EQUAL, :PERCENT_LOWER_I, :PERCENT_LOWER_W, :PERCENT_LOWER_X, :PERCENT_UPPER_I, :PERCENT_UPPER_W, :PIPE, :PIPE_EQUAL, :PIPE_PIPE, :PIPE_PIPE_EQUAL, :PLUS, :PLUS_EQUAL, :QUESTION_MARK, :REGEXP_BEGIN, :REGEXP_END, :SEMICOLON, :SLASH, :SLASH_EQUAL, :STAR, :STAR_EQUAL, :STAR_STAR, :STAR_STAR_EQUAL, :STRING_BEGIN, :STRING_CONTENT, :STRING_END, :SYMBOL_BEGIN, :TILDE, :UAMPERSAND, :UCOLON_COLON, :UDOT_DOT, :UDOT_DOT_DOT, :UMINUS, :UMINUS_NUM, :UPLUS, :USTAR, :USTAR_STAR, :WORDS_SEP, :__END__, ]
Class Method Summary collapse
-
.load(input, serialized) ⇒ Object
Deserialize the AST represented by the given string into a parse result.
-
.load_tokens(source, serialized) ⇒ Object
Deserialize the tokens represented by the given string into a parse result.
Class Method Details
.load(input, serialized) ⇒ Object
Deserialize the AST represented by the given string into a parse result.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/prism/serialize.rb', line 28 def self.load(input, serialized) input = input.dup source = Source.for(input) loader = Loader.new(source, serialized) result = loader.load_result input.force_encoding(loader.encoding) # This is an extremely niche use-case where the file was marked as binary # but it contained UTF-8-encoded characters. In that case we will actually # put it back to UTF-8 to give the location APIs the best chance of being # correct. if !input.ascii_only? && input.encoding == Encoding::BINARY input.force_encoding(Encoding::UTF_8) input.force_encoding(Encoding::BINARY) unless input.valid_encoding? end result end |
.load_tokens(source, serialized) ⇒ Object
Deserialize the tokens represented by the given string into a parse result.
51 52 53 |
# File 'lib/prism/serialize.rb', line 51 def self.load_tokens(source, serialized) Loader.new(source, serialized).load_tokens_result end |