Skip to content

Commit 4ef6e9f

Browse files
authored
Merge pull request #3580 from Shopify/amomchilov/repl
Add `repl` sub-command
2 parents 615e726 + 84075dc commit 4ef6e9f

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

bin/prism

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Prism
2020
when "parser" then parser(argv)
2121
when "ripper" then ripper(argv)
2222
when "rubyparser" then rubyparser(argv)
23+
when "repl" then repl
2324
else
2425
puts <<~TXT
2526
Usage:
@@ -35,6 +36,7 @@ module Prism
3536
bin/prism parser [source]
3637
bin/prism ripper [source]
3738
bin/prism rubyparser [source]
39+
bin/prism repl
3840
TXT
3941
end
4042
end
@@ -324,6 +326,25 @@ module Prism
324326
pp prism
325327
end
326328

329+
# bin/prism repl
330+
def repl
331+
loop do
332+
print "Prism> "
333+
334+
input = gets
335+
break if input.nil?
336+
337+
result = Prism.parse(input.chomp)
338+
339+
statements_node = result.value.statements
340+
statements = statements_node.body
341+
342+
result.errors.each { |e| p(e) }
343+
344+
p(statements.one? ? statements.first : statements)
345+
end
346+
end
347+
327348
############################################################################
328349
# Helpers
329350
############################################################################

0 commit comments

Comments
 (0)