prism 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/Makefile +6 -0
  4. data/README.md +1 -1
  5. data/config.yml +50 -35
  6. data/docs/fuzzing.md +1 -1
  7. data/docs/serialization.md +28 -29
  8. data/ext/prism/api_node.c +802 -770
  9. data/ext/prism/api_pack.c +20 -9
  10. data/ext/prism/extension.c +464 -162
  11. data/ext/prism/extension.h +1 -1
  12. data/include/prism/ast.h +3173 -763
  13. data/include/prism/defines.h +32 -9
  14. data/include/prism/diagnostic.h +36 -3
  15. data/include/prism/enc/pm_encoding.h +118 -28
  16. data/include/prism/node.h +38 -13
  17. data/include/prism/options.h +204 -0
  18. data/include/prism/pack.h +44 -33
  19. data/include/prism/parser.h +445 -200
  20. data/include/prism/prettyprint.h +12 -1
  21. data/include/prism/regexp.h +16 -2
  22. data/include/prism/util/pm_buffer.h +94 -16
  23. data/include/prism/util/pm_char.h +162 -48
  24. data/include/prism/util/pm_constant_pool.h +126 -32
  25. data/include/prism/util/pm_list.h +68 -38
  26. data/include/prism/util/pm_memchr.h +18 -3
  27. data/include/prism/util/pm_newline_list.h +70 -27
  28. data/include/prism/util/pm_state_stack.h +25 -7
  29. data/include/prism/util/pm_string.h +115 -27
  30. data/include/prism/util/pm_string_list.h +25 -6
  31. data/include/prism/util/pm_strncasecmp.h +32 -0
  32. data/include/prism/util/pm_strpbrk.h +31 -17
  33. data/include/prism/version.h +27 -2
  34. data/include/prism.h +224 -31
  35. data/lib/prism/compiler.rb +6 -3
  36. data/lib/prism/debug.rb +23 -7
  37. data/lib/prism/dispatcher.rb +33 -18
  38. data/lib/prism/dsl.rb +10 -5
  39. data/lib/prism/ffi.rb +132 -80
  40. data/lib/prism/lex_compat.rb +25 -15
  41. data/lib/prism/mutation_compiler.rb +10 -5
  42. data/lib/prism/node.rb +370 -135
  43. data/lib/prism/node_ext.rb +1 -1
  44. data/lib/prism/node_inspector.rb +1 -1
  45. data/lib/prism/pack.rb +79 -40
  46. data/lib/prism/parse_result/comments.rb +7 -2
  47. data/lib/prism/parse_result/newlines.rb +4 -0
  48. data/lib/prism/parse_result.rb +150 -30
  49. data/lib/prism/pattern.rb +11 -0
  50. data/lib/prism/ripper_compat.rb +28 -10
  51. data/lib/prism/serialize.rb +86 -54
  52. data/lib/prism/visitor.rb +10 -3
  53. data/lib/prism.rb +20 -2
  54. data/prism.gemspec +4 -2
  55. data/rbi/prism.rbi +104 -60
  56. data/rbi/prism_static.rbi +16 -2
  57. data/sig/prism.rbs +72 -43
  58. data/sig/prism_static.rbs +14 -1
  59. data/src/diagnostic.c +56 -53
  60. data/src/enc/pm_big5.c +1 -0
  61. data/src/enc/pm_euc_jp.c +1 -0
  62. data/src/enc/pm_gbk.c +1 -0
  63. data/src/enc/pm_shift_jis.c +1 -0
  64. data/src/enc/pm_tables.c +316 -80
  65. data/src/enc/pm_unicode.c +53 -8
  66. data/src/enc/pm_windows_31j.c +1 -0
  67. data/src/node.c +334 -321
  68. data/src/options.c +170 -0
  69. data/src/prettyprint.c +74 -47
  70. data/src/prism.c +1642 -856
  71. data/src/regexp.c +151 -95
  72. data/src/serialize.c +44 -20
  73. data/src/token_type.c +3 -1
  74. data/src/util/pm_buffer.c +45 -15
  75. data/src/util/pm_char.c +103 -57
  76. data/src/util/pm_constant_pool.c +51 -21
  77. data/src/util/pm_list.c +12 -4
  78. data/src/util/pm_memchr.c +5 -3
  79. data/src/util/pm_newline_list.c +20 -12
  80. data/src/util/pm_state_stack.c +9 -3
  81. data/src/util/pm_string.c +95 -85
  82. data/src/util/pm_string_list.c +14 -15
  83. data/src/util/pm_strncasecmp.c +10 -3
  84. data/src/util/pm_strpbrk.c +25 -19
  85. metadata +5 -3
  86. data/docs/prism.png +0 -0
@@ -35,11 +35,11 @@ module Prism
35
35
  class SexpBuilderPP < SexpBuilder
36
36
  private
37
37
 
38
- def _dispatch_event_new
38
+ def _dispatch_event_new # :nodoc:
39
39
  []
40
40
  end
41
41
 
42
- def _dispatch_event_push(list, item)
42
+ def _dispatch_event_push(list, item) # :nodoc:
43
43
  list << item
44
44
  list
45
45
  end
@@ -54,8 +54,16 @@ module Prism
54
54
  end
55
55
  end
56
56
 
57
- attr_reader :source, :lineno, :column
57
+ # The source that is being parsed.
58
+ attr_reader :source
58
59
 
60
+ # The current line number of the parser.
61
+ attr_reader :lineno
62
+
63
+ # The current column number of the parser.
64
+ attr_reader :column
65
+
66
+ # Create a new RipperCompat object with the given source.
59
67
  def initialize(source)
60
68
  @source = source
61
69
  @result = nil
@@ -67,10 +75,12 @@ module Prism
67
75
  # Public interface
68
76
  ############################################################################
69
77
 
78
+ # True if the parser encountered an error during parsing.
70
79
  def error?
71
80
  result.errors.any?
72
81
  end
73
82
 
83
+ # Parse the source and return the result.
74
84
  def parse
75
85
  result.value.accept(self) unless error?
76
86
  end
@@ -79,10 +89,13 @@ module Prism
79
89
  # Visitor methods
80
90
  ############################################################################
81
91
 
92
+ # This method is responsible for dispatching to the correct visitor method
93
+ # based on the type of the node.
82
94
  def visit(node)
83
95
  node&.accept(self)
84
96
  end
85
97
 
98
+ # Visit a CallNode node.
86
99
  def visit_call_node(node)
87
100
  if !node.opening_loc && node.arguments.arguments.length == 1
88
101
  bounds(node.receiver.location)
@@ -97,11 +110,13 @@ module Prism
97
110
  end
98
111
  end
99
112
 
113
+ # Visit an IntegerNode node.
100
114
  def visit_integer_node(node)
101
115
  bounds(node.location)
102
116
  on_int(source[node.location.start_offset...node.location.end_offset])
103
117
  end
104
118
 
119
+ # Visit a StatementsNode node.
105
120
  def visit_statements_node(node)
106
121
  bounds(node.location)
107
122
  node.body.inject(on_stmts_new) do |stmts, stmt|
@@ -109,6 +124,7 @@ module Prism
109
124
  end
110
125
  end
111
126
 
127
+ # Visit a token found during parsing.
112
128
  def visit_token(node)
113
129
  bounds(node.location)
114
130
 
@@ -122,6 +138,7 @@ module Prism
122
138
  end
123
139
  end
124
140
 
141
+ # Visit a ProgramNode node.
125
142
  def visit_program_node(node)
126
143
  bounds(node.location)
127
144
  on_program(visit(node.statements))
@@ -155,17 +172,18 @@ module Prism
155
172
  @column = start_offset - (source.rindex("\n", start_offset) || 0)
156
173
  end
157
174
 
175
+ # Lazily initialize the parse result.
158
176
  def result
159
177
  @result ||= Prism.parse(source)
160
178
  end
161
179
 
162
- def _dispatch0; end
163
- def _dispatch1(_); end
164
- def _dispatch2(_, _); end
165
- def _dispatch3(_, _, _); end
166
- def _dispatch4(_, _, _, _); end
167
- def _dispatch5(_, _, _, _, _); end
168
- def _dispatch7(_, _, _, _, _, _, _); end
180
+ def _dispatch0; end # :nodoc:
181
+ def _dispatch1(_); end # :nodoc:
182
+ def _dispatch2(_, _); end # :nodoc:
183
+ def _dispatch3(_, _, _); end # :nodoc:
184
+ def _dispatch4(_, _, _, _); end # :nodoc:
185
+ def _dispatch5(_, _, _, _, _); end # :nodoc:
186
+ def _dispatch7(_, _, _, _, _, _, _); end # :nodoc:
169
187
 
170
188
  (Ripper::SCANNER_EVENT_TABLE.merge(Ripper::PARSER_EVENT_TABLE)).each do |event, arity|
171
189
  alias_method :"on_#{event}", :"_dispatch#{arity}"
@@ -11,7 +11,7 @@ require "stringio"
11
11
  if String.instance_method(:unpack1).parameters.none? { |_, name| name == :offset }
12
12
  String.prepend(
13
13
  Module.new {
14
- def unpack1(format, offset: 0)
14
+ def unpack1(format, offset: 0) # :nodoc:
15
15
  offset == 0 ? super(format) : self[offset..].unpack1(format)
16
16
  end
17
17
  }
@@ -19,11 +19,21 @@ if String.instance_method(:unpack1).parameters.none? { |_, name| name == :offset
19
19
  end
20
20
 
21
21
  module Prism
22
+ # A module responsible for deserializing parse results.
22
23
  module Serialize
24
+ # The major version of prism that we are expecting to find in the serialized
25
+ # strings.
23
26
  MAJOR_VERSION = 0
24
- MINOR_VERSION = 16
27
+
28
+ # The minor version of prism that we are expecting to find in the serialized
29
+ # strings.
30
+ MINOR_VERSION = 17
31
+
32
+ # The patch version of prism that we are expecting to find in the serialized
33
+ # strings.
25
34
  PATCH_VERSION = 0
26
35
 
36
+ # Deserialize the AST represented by the given string into a parse result.
27
37
  def self.load(input, serialized)
28
38
  input = input.dup
29
39
  source = Source.new(input)
@@ -34,13 +44,16 @@ module Prism
34
44
  result
35
45
  end
36
46
 
47
+ # Deserialize the tokens represented by the given string into a parse
48
+ # result.
37
49
  def self.load_tokens(source, serialized)
38
50
  Loader.new(source, serialized).load_tokens_result
39
51
  end
40
52
 
41
- class Loader
53
+ class Loader # :nodoc:
42
54
  attr_reader :encoding, :input, :serialized, :io
43
55
  attr_reader :constant_pool_offset, :constant_pool, :source
56
+ attr_reader :start_line
44
57
 
45
58
  def initialize(source, serialized)
46
59
  @encoding = Encoding::UTF_8
@@ -54,7 +67,7 @@ module Prism
54
67
  @constant_pool = nil
55
68
 
56
69
  @source = source
57
- define_load_node_lambdas unless RUBY_ENGINE == 'ruby'
70
+ define_load_node_lambdas unless RUBY_ENGINE == "ruby"
58
71
  end
59
72
 
60
73
  def load_header
@@ -75,8 +88,18 @@ module Prism
75
88
  @input = input.force_encoding(@encoding).freeze
76
89
  end
77
90
 
91
+ def load_start_line
92
+ source.start_line = load_varint
93
+ end
94
+
78
95
  def load_comments
79
- load_varint.times.map { Comment.new(Comment::TYPES.fetch(load_varint), load_location) }
96
+ load_varint.times.map do
97
+ case load_varint
98
+ when 0 then InlineComment.new(load_location)
99
+ when 1 then EmbDocComment.new(load_location)
100
+ when 2 then DATAComment.new(load_location)
101
+ end
102
+ end
80
103
  end
81
104
 
82
105
  def load_metadata
@@ -103,6 +126,7 @@ module Prism
103
126
  def load_tokens_result
104
127
  tokens = load_tokens
105
128
  encoding = load_encoding
129
+ load_start_line
106
130
  comments, magic_comments, errors, warnings = load_metadata
107
131
 
108
132
  if encoding != @encoding
@@ -116,6 +140,7 @@ module Prism
116
140
  def load_nodes
117
141
  load_header
118
142
  load_force_encoding
143
+ load_start_line
119
144
 
120
145
  comments, magic_comments, errors, warnings = load_metadata
121
146
 
@@ -389,47 +414,47 @@ module Prism
389
414
  when 84 then
390
415
  KeywordHashNode.new(Array.new(load_varint) { load_node }, location)
391
416
  when 85 then
392
- KeywordParameterNode.new(load_required_constant, load_location, load_optional_node, location)
393
- when 86 then
394
417
  KeywordRestParameterNode.new(load_optional_constant, load_optional_location, load_location, location)
395
- when 87 then
418
+ when 86 then
396
419
  LambdaNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_location, load_location, load_optional_node, load_optional_node, location)
397
- when 88 then
420
+ when 87 then
398
421
  LocalVariableAndWriteNode.new(load_location, load_location, load_node, load_required_constant, load_varint, location)
399
- when 89 then
422
+ when 88 then
400
423
  LocalVariableOperatorWriteNode.new(load_location, load_location, load_node, load_required_constant, load_required_constant, load_varint, location)
401
- when 90 then
424
+ when 89 then
402
425
  LocalVariableOrWriteNode.new(load_location, load_location, load_node, load_required_constant, load_varint, location)
403
- when 91 then
426
+ when 90 then
404
427
  LocalVariableReadNode.new(load_required_constant, load_varint, location)
405
- when 92 then
428
+ when 91 then
406
429
  LocalVariableTargetNode.new(load_required_constant, load_varint, location)
407
- when 93 then
430
+ when 92 then
408
431
  LocalVariableWriteNode.new(load_required_constant, load_varint, load_location, load_node, load_location, location)
409
- when 94 then
432
+ when 93 then
410
433
  MatchLastLineNode.new(load_location, load_location, load_location, load_string, load_varint, location)
411
- when 95 then
434
+ when 94 then
412
435
  MatchPredicateNode.new(load_node, load_node, load_location, location)
413
- when 96 then
436
+ when 95 then
414
437
  MatchRequiredNode.new(load_node, load_node, load_location, location)
415
- when 97 then
438
+ when 96 then
416
439
  MatchWriteNode.new(load_node, Array.new(load_varint) { load_required_constant }, location)
417
- when 98 then
440
+ when 97 then
418
441
  MissingNode.new(location)
419
- when 99 then
442
+ when 98 then
420
443
  ModuleNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_node, load_optional_node, load_location, load_required_constant, location)
421
- when 100 then
444
+ when 99 then
422
445
  MultiTargetNode.new(Array.new(load_varint) { load_node }, load_optional_node, Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, location)
423
- when 101 then
446
+ when 100 then
424
447
  MultiWriteNode.new(Array.new(load_varint) { load_node }, load_optional_node, Array.new(load_varint) { load_node }, load_optional_location, load_optional_location, load_location, load_node, location)
425
- when 102 then
448
+ when 101 then
426
449
  NextNode.new(load_optional_node, load_location, location)
427
- when 103 then
450
+ when 102 then
428
451
  NilNode.new(location)
429
- when 104 then
452
+ when 103 then
430
453
  NoKeywordsParameterNode.new(load_location, load_location, location)
431
- when 105 then
454
+ when 104 then
432
455
  NumberedReferenceReadNode.new(load_varint, location)
456
+ when 105 then
457
+ OptionalKeywordParameterNode.new(load_required_constant, load_location, load_node, location)
433
458
  when 106 then
434
459
  OptionalParameterNode.new(load_required_constant, load_location, load_location, load_node, location)
435
460
  when 107 then
@@ -457,54 +482,56 @@ module Prism
457
482
  when 118 then
458
483
  RegularExpressionNode.new(load_location, load_location, load_location, load_string, load_varint, location)
459
484
  when 119 then
460
- RequiredParameterNode.new(load_required_constant, location)
485
+ RequiredKeywordParameterNode.new(load_required_constant, load_location, location)
461
486
  when 120 then
462
- RescueModifierNode.new(load_node, load_location, load_node, location)
487
+ RequiredParameterNode.new(load_required_constant, location)
463
488
  when 121 then
464
- RescueNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_location, load_optional_node, load_optional_node, load_optional_node, location)
489
+ RescueModifierNode.new(load_node, load_location, load_node, location)
465
490
  when 122 then
466
- RestParameterNode.new(load_optional_constant, load_optional_location, load_location, location)
491
+ RescueNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_location, load_optional_node, load_optional_node, load_optional_node, location)
467
492
  when 123 then
468
- RetryNode.new(location)
493
+ RestParameterNode.new(load_optional_constant, load_optional_location, load_location, location)
469
494
  when 124 then
470
- ReturnNode.new(load_location, load_optional_node, location)
495
+ RetryNode.new(location)
471
496
  when 125 then
472
- SelfNode.new(location)
497
+ ReturnNode.new(load_location, load_optional_node, location)
473
498
  when 126 then
474
- SingletonClassNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_location, load_node, load_optional_node, load_location, location)
499
+ SelfNode.new(location)
475
500
  when 127 then
476
- SourceEncodingNode.new(location)
501
+ SingletonClassNode.new(Array.new(load_varint) { load_required_constant }, load_location, load_location, load_node, load_optional_node, load_location, location)
477
502
  when 128 then
478
- SourceFileNode.new(load_string, location)
503
+ SourceEncodingNode.new(location)
479
504
  when 129 then
480
- SourceLineNode.new(location)
505
+ SourceFileNode.new(load_string, location)
481
506
  when 130 then
482
- SplatNode.new(load_location, load_optional_node, location)
507
+ SourceLineNode.new(location)
483
508
  when 131 then
484
- StatementsNode.new(Array.new(load_varint) { load_node }, location)
509
+ SplatNode.new(load_location, load_optional_node, location)
485
510
  when 132 then
486
- StringConcatNode.new(load_node, load_node, location)
511
+ StatementsNode.new(Array.new(load_varint) { load_node }, location)
487
512
  when 133 then
488
- StringNode.new(load_varint, load_optional_location, load_location, load_optional_location, load_string, location)
513
+ StringConcatNode.new(load_node, load_node, location)
489
514
  when 134 then
490
- SuperNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, load_optional_node, location)
515
+ StringNode.new(load_varint, load_optional_location, load_location, load_optional_location, load_string, location)
491
516
  when 135 then
492
- SymbolNode.new(load_optional_location, load_optional_location, load_optional_location, load_string, location)
517
+ SuperNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, load_optional_node, location)
493
518
  when 136 then
494
- TrueNode.new(location)
519
+ SymbolNode.new(load_optional_location, load_optional_location, load_optional_location, load_string, location)
495
520
  when 137 then
496
- UndefNode.new(Array.new(load_varint) { load_node }, load_location, location)
521
+ TrueNode.new(location)
497
522
  when 138 then
498
- UnlessNode.new(load_location, load_node, load_optional_node, load_optional_node, load_optional_location, location)
523
+ UndefNode.new(Array.new(load_varint) { load_node }, load_location, location)
499
524
  when 139 then
500
- UntilNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
525
+ UnlessNode.new(load_location, load_node, load_optional_node, load_optional_node, load_optional_location, location)
501
526
  when 140 then
502
- WhenNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_node, location)
527
+ UntilNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
503
528
  when 141 then
504
- WhileNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
529
+ WhenNode.new(load_location, Array.new(load_varint) { load_node }, load_optional_node, location)
505
530
  when 142 then
506
- XStringNode.new(load_location, load_location, load_location, load_string, location)
531
+ WhileNode.new(load_location, load_optional_location, load_node, load_optional_node, load_varint, location)
507
532
  when 143 then
533
+ XStringNode.new(load_location, load_location, load_location, load_string, location)
534
+ when 144 then
508
535
  YieldNode.new(load_location, load_optional_location, load_optional_node, load_optional_location, location)
509
536
  end
510
537
  end
@@ -854,10 +881,6 @@ module Prism
854
881
  location = load_location
855
882
  KeywordHashNode.new(Array.new(load_varint) { load_node }, location)
856
883
  },
857
- -> {
858
- location = load_location
859
- KeywordParameterNode.new(load_required_constant, load_location, load_optional_node, location)
860
- },
861
884
  -> {
862
885
  location = load_location
863
886
  KeywordRestParameterNode.new(load_optional_constant, load_optional_location, load_location, location)
@@ -938,6 +961,10 @@ module Prism
938
961
  location = load_location
939
962
  NumberedReferenceReadNode.new(load_varint, location)
940
963
  },
964
+ -> {
965
+ location = load_location
966
+ OptionalKeywordParameterNode.new(load_required_constant, load_location, load_node, location)
967
+ },
941
968
  -> {
942
969
  location = load_location
943
970
  OptionalParameterNode.new(load_required_constant, load_location, load_location, load_node, location)
@@ -990,6 +1017,10 @@ module Prism
990
1017
  location = load_location
991
1018
  RegularExpressionNode.new(load_location, load_location, load_location, load_string, load_varint, location)
992
1019
  },
1020
+ -> {
1021
+ location = load_location
1022
+ RequiredKeywordParameterNode.new(load_required_constant, load_location, location)
1023
+ },
993
1024
  -> {
994
1025
  location = load_location
995
1026
  RequiredParameterNode.new(load_required_constant, location)
@@ -1095,6 +1126,7 @@ module Prism
1095
1126
  end
1096
1127
  end
1097
1128
 
1129
+ # The token types that can be indexed by their enum values.
1098
1130
  TOKEN_TYPES = [
1099
1131
  nil,
1100
1132
  :EOF,
data/lib/prism/visitor.rb CHANGED
@@ -11,14 +11,18 @@ module Prism
11
11
  # implement each one that they need. For a default implementation that
12
12
  # continues walking the tree, see the Visitor class.
13
13
  class BasicVisitor
14
+ # Calls `accept` on the given node if it is not `nil`, which in turn should
15
+ # call back into this visitor by calling the appropriate `visit_*` method.
14
16
  def visit(node)
15
17
  node&.accept(self)
16
18
  end
17
19
 
20
+ # Visits each node in `nodes` by calling `accept` on each one.
18
21
  def visit_all(nodes)
19
22
  nodes.each { |node| node&.accept(self) }
20
23
  end
21
24
 
25
+ # Visits the child nodes of `node` by calling `accept` on each one.
22
26
  def visit_child_nodes(node)
23
27
  node.compact_child_nodes.each { |node| node.accept(self) }
24
28
  end
@@ -296,9 +300,6 @@ module Prism
296
300
  # Visit a KeywordHashNode node
297
301
  alias visit_keyword_hash_node visit_child_nodes
298
302
 
299
- # Visit a KeywordParameterNode node
300
- alias visit_keyword_parameter_node visit_child_nodes
301
-
302
303
  # Visit a KeywordRestParameterNode node
303
304
  alias visit_keyword_rest_parameter_node visit_child_nodes
304
305
 
@@ -359,6 +360,9 @@ module Prism
359
360
  # Visit a NumberedReferenceReadNode node
360
361
  alias visit_numbered_reference_read_node visit_child_nodes
361
362
 
363
+ # Visit a OptionalKeywordParameterNode node
364
+ alias visit_optional_keyword_parameter_node visit_child_nodes
365
+
362
366
  # Visit a OptionalParameterNode node
363
367
  alias visit_optional_parameter_node visit_child_nodes
364
368
 
@@ -398,6 +402,9 @@ module Prism
398
402
  # Visit a RegularExpressionNode node
399
403
  alias visit_regular_expression_node visit_child_nodes
400
404
 
405
+ # Visit a RequiredKeywordParameterNode node
406
+ alias visit_required_keyword_parameter_node visit_child_nodes
407
+
401
408
  # Visit a RequiredParameterNode node
402
409
  alias visit_required_parameter_node visit_child_nodes
403
410
 
data/lib/prism.rb CHANGED
@@ -1,10 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # The Prism Ruby parser.
4
+ #
5
+ # "Parsing Ruby is suddenly manageable!"
6
+ # - You, hopefully
7
+ #
3
8
  module Prism
4
9
  # There are many files in prism that are templated to handle every node type,
5
10
  # which means the files can end up being quite large. We autoload them to make
6
11
  # our require speed faster since consuming libraries are unlikely to use all
7
12
  # of these features.
13
+
8
14
  autoload :BasicVisitor, "prism/visitor"
9
15
  autoload :Compiler, "prism/compiler"
10
16
  autoload :Debug, "prism/debug"
@@ -23,17 +29,26 @@ module Prism
23
29
 
24
30
  # Some of these constants are not meant to be exposed, so marking them as
25
31
  # private here.
32
+
26
33
  private_constant :Debug
27
34
  private_constant :LexCompat
28
35
  private_constant :LexRipper
29
36
 
37
+ # :call-seq:
38
+ # Prism::lex_compat(source, **options) -> Array
39
+ #
30
40
  # Returns an array of tokens that closely resembles that of the Ripper lexer.
31
41
  # The only difference is that since we don't keep track of lexer state in the
32
42
  # same way, it's going to always return the NONE state.
33
- def self.lex_compat(source, filepath = "")
34
- LexCompat.new(source, filepath).result
43
+ #
44
+ # For supported options, see Prism::parse.
45
+ def self.lex_compat(source, **options)
46
+ LexCompat.new(source, **options).result
35
47
  end
36
48
 
49
+ # :call-seq:
50
+ # Prism::lex_ripper(source) -> Array
51
+ #
37
52
  # This lexes with the Ripper lex. It drops any space events but otherwise
38
53
  # returns the same tokens. Raises SyntaxError if the syntax in source is
39
54
  # invalid.
@@ -41,6 +56,9 @@ module Prism
41
56
  LexRipper.new(source).result
42
57
  end
43
58
 
59
+ # :call-seq:
60
+ # Prism::load(source, serialized) -> ParseResult
61
+ #
44
62
  # Load the serialized AST using the source as a reference into a tree.
45
63
  def self.load(source, serialized)
46
64
  Serialize.load(source, serialized)
data/prism.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prism"
5
- spec.version = "0.16.0"
5
+ spec.version = "0.17.0"
6
6
  spec.authors = ["Shopify"]
7
7
  spec.email = ["ruby@shopify.com"]
8
8
 
@@ -30,7 +30,6 @@ Gem::Specification.new do |spec|
30
30
  "docs/heredocs.md",
31
31
  "docs/javascript.md",
32
32
  "docs/mapping.md",
33
- "docs/prism.png",
34
33
  "docs/releasing.md",
35
34
  "docs/ripper.md",
36
35
  "docs/ruby_api.md",
@@ -46,6 +45,7 @@ Gem::Specification.new do |spec|
46
45
  "include/prism/diagnostic.h",
47
46
  "include/prism/enc/pm_encoding.h",
48
47
  "include/prism/node.h",
48
+ "include/prism/options.h",
49
49
  "include/prism/pack.h",
50
50
  "include/prism/parser.h",
51
51
  "include/prism/prettyprint.h",
@@ -57,6 +57,7 @@ Gem::Specification.new do |spec|
57
57
  "include/prism/util/pm_memchr.h",
58
58
  "include/prism/util/pm_newline_list.h",
59
59
  "include/prism/util/pm_state_stack.h",
60
+ "include/prism/util/pm_strncasecmp.h",
60
61
  "include/prism/util/pm_string.h",
61
62
  "include/prism/util/pm_string_list.h",
62
63
  "include/prism/util/pm_strpbrk.h",
@@ -106,6 +107,7 @@ Gem::Specification.new do |spec|
106
107
  "src/util/pm_string_list.c",
107
108
  "src/util/pm_strncasecmp.c",
108
109
  "src/util/pm_strpbrk.c",
110
+ "src/options.c",
109
111
  "src/prism.c",
110
112
  "prism.gemspec",
111
113
  "sig/prism.rbs",