prism 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/README.md +1 -1
- data/config.yml +86 -21
- data/ext/prism/api_node.c +213 -67
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +133 -83
- data/include/prism/diagnostic.h +1 -0
- data/include/prism/node.h +7 -0
- data/include/prism/util/pm_constant_pool.h +20 -6
- data/include/prism/version.h +2 -2
- data/include/prism.h +1 -1
- data/lib/prism/compiler.rb +9 -0
- data/lib/prism/debug.rb +30 -26
- data/lib/prism/dispatcher.rb +42 -0
- data/lib/prism/dsl.rb +23 -8
- data/lib/prism/ffi.rb +2 -2
- data/lib/prism/lex_compat.rb +9 -9
- data/lib/prism/mutation_compiler.rb +18 -3
- data/lib/prism/node.rb +580 -120
- data/lib/prism/serialize.rb +83 -77
- data/lib/prism/visitor.rb +9 -0
- data/prism.gemspec +1 -1
- data/src/diagnostic.c +1 -0
- data/src/node.c +99 -18
- data/src/prettyprint.c +102 -45
- data/src/prism.c +288 -88
- data/src/serialize.c +95 -57
- data/src/util/pm_constant_pool.c +25 -11
- metadata +2 -2
data/lib/prism/lex_compat.rb
CHANGED
@@ -357,6 +357,7 @@ module Prism
|
|
357
357
|
@dedent_next = true
|
358
358
|
@dedent = nil
|
359
359
|
@embexpr_balance = 0
|
360
|
+
@ended_on_newline = false
|
360
361
|
end
|
361
362
|
|
362
363
|
# As tokens are coming in, we track the minimum amount of common leading
|
@@ -366,13 +367,14 @@ module Prism
|
|
366
367
|
case token.event
|
367
368
|
when :on_embexpr_beg, :on_heredoc_beg
|
368
369
|
@embexpr_balance += 1
|
370
|
+
@dedent = 0 if @dedent_next && @ended_on_newline
|
369
371
|
when :on_embexpr_end, :on_heredoc_end
|
370
372
|
@embexpr_balance -= 1
|
371
373
|
when :on_tstring_content
|
372
374
|
if embexpr_balance == 0
|
373
375
|
line = token.value
|
374
376
|
|
375
|
-
if !(line.strip.empty? && line.end_with?("\n"))
|
377
|
+
if dedent_next && !(line.strip.empty? && line.end_with?("\n"))
|
376
378
|
leading = line[/\A(\s*)\n?/, 1]
|
377
379
|
next_dedent = 0
|
378
380
|
|
@@ -385,11 +387,16 @@ module Prism
|
|
385
387
|
end
|
386
388
|
|
387
389
|
@dedent = [dedent, next_dedent].compact.min
|
390
|
+
@dedent_next = true
|
391
|
+
@ended_on_newline = line.end_with?("\n")
|
392
|
+
tokens << token
|
393
|
+
return
|
388
394
|
end
|
389
395
|
end
|
390
396
|
end
|
391
397
|
|
392
398
|
@dedent_next = token.event == :on_tstring_content && embexpr_balance == 0
|
399
|
+
@ended_on_newline = false
|
393
400
|
tokens << token
|
394
401
|
end
|
395
402
|
|
@@ -440,28 +447,21 @@ module Prism
|
|
440
447
|
|
441
448
|
while index < max_index
|
442
449
|
token = tokens[index]
|
450
|
+
results << token
|
443
451
|
index += 1
|
444
452
|
|
445
453
|
case token.event
|
446
454
|
when :on_embexpr_beg, :on_heredoc_beg
|
447
455
|
embexpr_balance += 1
|
448
|
-
results << token
|
449
456
|
when :on_embexpr_end, :on_heredoc_end
|
450
457
|
embexpr_balance -= 1
|
451
|
-
results << token
|
452
458
|
when :on_tstring_content
|
453
459
|
if embexpr_balance == 0
|
454
|
-
results << token
|
455
|
-
|
456
460
|
while index < max_index && tokens[index].event == :on_tstring_content
|
457
461
|
token.value << tokens[index].value
|
458
462
|
index += 1
|
459
463
|
end
|
460
|
-
else
|
461
|
-
results << token
|
462
464
|
end
|
463
|
-
else
|
464
|
-
results << token
|
465
465
|
end
|
466
466
|
end
|
467
467
|
|
@@ -97,7 +97,7 @@ module Prism
|
|
97
97
|
|
98
98
|
# Copy a CallAndWriteNode node
|
99
99
|
def visit_call_and_write_node(node)
|
100
|
-
node.copy(receiver: visit(node.receiver),
|
100
|
+
node.copy(receiver: visit(node.receiver), value: visit(node.value))
|
101
101
|
end
|
102
102
|
|
103
103
|
# Copy a CallNode node
|
@@ -107,12 +107,12 @@ module Prism
|
|
107
107
|
|
108
108
|
# Copy a CallOperatorWriteNode node
|
109
109
|
def visit_call_operator_write_node(node)
|
110
|
-
node.copy(receiver: visit(node.receiver),
|
110
|
+
node.copy(receiver: visit(node.receiver), value: visit(node.value))
|
111
111
|
end
|
112
112
|
|
113
113
|
# Copy a CallOrWriteNode node
|
114
114
|
def visit_call_or_write_node(node)
|
115
|
-
node.copy(receiver: visit(node.receiver),
|
115
|
+
node.copy(receiver: visit(node.receiver), value: visit(node.value))
|
116
116
|
end
|
117
117
|
|
118
118
|
# Copy a CapturePatternNode node
|
@@ -350,6 +350,21 @@ module Prism
|
|
350
350
|
node.copy(pattern: visit(node.pattern), statements: visit(node.statements))
|
351
351
|
end
|
352
352
|
|
353
|
+
# Copy a IndexAndWriteNode node
|
354
|
+
def visit_index_and_write_node(node)
|
355
|
+
node.copy(receiver: visit(node.receiver), arguments: visit(node.arguments), block: visit(node.block), value: visit(node.value))
|
356
|
+
end
|
357
|
+
|
358
|
+
# Copy a IndexOperatorWriteNode node
|
359
|
+
def visit_index_operator_write_node(node)
|
360
|
+
node.copy(receiver: visit(node.receiver), arguments: visit(node.arguments), block: visit(node.block), value: visit(node.value))
|
361
|
+
end
|
362
|
+
|
363
|
+
# Copy a IndexOrWriteNode node
|
364
|
+
def visit_index_or_write_node(node)
|
365
|
+
node.copy(receiver: visit(node.receiver), arguments: visit(node.arguments), block: visit(node.block), value: visit(node.value))
|
366
|
+
end
|
367
|
+
|
353
368
|
# Copy a InstanceVariableAndWriteNode node
|
354
369
|
def visit_instance_variable_and_write_node(node)
|
355
370
|
node.copy(value: visit(node.value))
|