Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

68 lines (50 sloc) 1.108 kb
require 'parslet'
# For parsing commandline slide content.
class CommandlineParser < Parslet::Parser
rule(:prompt) do
str('$') | str('#')
end
rule(:text) do
match['[:print:]'].repeat
end
rule(:singleline_input) do
(str("\\\n").absent? >> match['[:print:]']).repeat
end
rule(:input) do
multiline_input | singleline_input
end
rule(:multiline_input) do
# some command \
# continued \
# \
# and stop
( singleline_input >> str('\\') >> newline ).repeat(1) >> singleline_input
end
rule(:command) do
# $ some command
# some output
( prompt.as(:prompt) >> space? >> input.as(:input) >> output? ).as(:command)
end
rule(:output) do
# output
prompt.absent? >> text
end
rule(:output?) do
#
# some text
# some text
#
# some text
( newline >> ( ( output >> newline ).repeat >> output.maybe ).as(:output) ).maybe
end
rule(:commands) do
command.repeat
end
rule(:newline) do
str("\n") | str("\r\n")
end
rule(:space?) do
match['[:space:]'].repeat
end
root(:commands)
end
Jump to Line
Something went wrong with that request. Please try again.