@@ -15,7 +15,8 @@ module LibRubyParser # :nodoc:
1515 # must align with the build shared library from make/rake.
1616 libprism_in_build = File . expand_path ( "../../build/libprism.#{ RbConfig ::CONFIG [ "SOEXT" ] } " , __dir__ )
1717 libprism_in_libdir = "#{ RbConfig ::CONFIG [ "libdir" ] } /prism/libprism.#{ RbConfig ::CONFIG [ "SOEXT" ] } "
18- if File . exist? libprism_in_build
18+
19+ if File . exist? ( libprism_in_build )
1920 INCLUDE_DIR = File . expand_path ( "../../include" , __dir__ )
2021 ffi_lib libprism_in_build
2122 else
@@ -363,86 +364,28 @@ def dump_common(string, options) # :nodoc:
363364 end
364365
365366 def lex_common ( string , code , options ) # :nodoc:
366- serialized =
367- LibRubyParser ::PrismBuffer . with do |buffer |
368- LibRubyParser . pm_serialize_lex ( buffer . pointer , string . pointer , string . length , dump_options ( options ) )
369- buffer . read
370- end
371-
372- freeze = options . fetch ( :freeze , false )
373- source = Source . for ( code )
374- result = Serialize . load_tokens ( source , serialized , freeze )
375-
376- if freeze
377- source . source . freeze
378- source . offsets . freeze
379- source . freeze
367+ LibRubyParser ::PrismBuffer . with do |buffer |
368+ LibRubyParser . pm_serialize_lex ( buffer . pointer , string . pointer , string . length , dump_options ( options ) )
369+ Serialize . load_lex ( code , buffer . read , options . fetch ( :freeze , false ) )
380370 end
381-
382- result
383371 end
384372
385373 def parse_common ( string , code , options ) # :nodoc:
386374 serialized = dump_common ( string , options )
387- Prism . load ( code , serialized , options . fetch ( :freeze , false ) )
375+ Serialize . load_parse ( code , serialized , options . fetch ( :freeze , false ) )
388376 end
389377
390378 def parse_comments_common ( string , code , options ) # :nodoc:
391379 LibRubyParser ::PrismBuffer . with do |buffer |
392380 LibRubyParser . pm_serialize_parse_comments ( buffer . pointer , string . pointer , string . length , dump_options ( options ) )
393-
394- source = Source . for ( code )
395- loader = Serialize ::Loader . new ( source , buffer . read )
396-
397- loader . load_header
398- loader . load_encoding
399- loader . load_start_line
400-
401- if ( freeze = options . fetch ( :freeze , false ) )
402- source . source . freeze
403- source . offsets . freeze
404- source . freeze
405- end
406-
407- loader . load_comments ( freeze )
381+ Serialize . load_parse_comments ( code , buffer . read , options . fetch ( :freeze , false ) )
408382 end
409383 end
410384
411385 def parse_lex_common ( string , code , options ) # :nodoc:
412386 LibRubyParser ::PrismBuffer . with do |buffer |
413387 LibRubyParser . pm_serialize_parse_lex ( buffer . pointer , string . pointer , string . length , dump_options ( options ) )
414-
415- source = Source . for ( code )
416- loader = Serialize ::Loader . new ( source , buffer . read )
417- freeze = options . fetch ( :freeze , false )
418-
419- tokens = loader . load_tokens ( false )
420- node , comments , magic_comments , data_loc , errors , warnings = loader . load_nodes ( freeze )
421-
422- tokens . each do |token , |
423- token . value . force_encoding ( loader . encoding )
424-
425- if freeze
426- token . value . freeze
427- token . location . freeze
428- token . freeze
429- end
430- end
431-
432- value = [ node , tokens ]
433- result = ParseLexResult . new ( value , comments , magic_comments , data_loc , errors , warnings , source )
434-
435- if freeze
436- source . source . freeze
437- source . offsets . freeze
438- source . freeze
439- tokens . each ( &:freeze )
440- tokens . freeze
441- value . freeze
442- result . freeze
443- end
444-
445- result
388+ Serialize . load_parse_lex ( code , buffer . read , options . fetch ( :freeze , false ) )
446389 end
447390 end
448391
0 commit comments