Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions bin/prism
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Prism
when "parser" then parser(argv)
when "ripper" then ripper(argv)
when "rubyparser" then rubyparser(argv)
when "repl" then repl
else
puts <<~TXT
Usage:
Expand All @@ -35,6 +36,7 @@ module Prism
bin/prism parser [source]
bin/prism ripper [source]
bin/prism rubyparser [source]
bin/prism repl
TXT
end
end
Expand Down Expand Up @@ -324,6 +326,25 @@ module Prism
pp prism
end

# bin/prism repl
def repl
loop do
print "Prism> "

input = gets
break if input.nil?

result = Prism.parse(input.chomp)

statements_node = result.value.statements
statements = statements_node.body

result.errors.each { |e| p(e) }

p(statements.one? ? statements.first : statements)
end
end

############################################################################
# Helpers
############################################################################
Expand Down