Sha256: 02fe0c3ffd8a3a39a72f13d23aeae8a164984ccbba957ba7ad9f6a16967db16d

Contents?: true

Size: 1.09 KB

Versions: 62

Compression:

Stored size: 1.09 KB

Contents

require 'parslet'

# For parsing commandline slide content.
class CommandlineParser < Parslet::Parser

  rule(:prompt) do
    str('$') | 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

Version data entries

62 entries across 62 versions & 2 rubygems

Version Path
showoff-0.20.4 lib/commandline_parser.rb
showoff-0.20.3 lib/commandline_parser.rb
showoff-0.20.2 lib/commandline_parser.rb
showoff-0.20.1 lib/commandline_parser.rb
showoff-0.20.0 lib/commandline_parser.rb
showoff-0.19.6 lib/commandline_parser.rb
showoff-0.19.4 lib/commandline_parser.rb
showoff-0.19.3 lib/commandline_parser.rb
showoff-0.19.2 lib/commandline_parser.rb
showoff-0.19.1 lib/commandline_parser.rb
showoff-0.19.0 lib/commandline_parser.rb
showoff-0.18.2 lib/commandline_parser.rb
showoff-0.18.1 lib/commandline_parser.rb
showoff-0.18.0 lib/commandline_parser.rb
showoff-0.17.2 lib/commandline_parser.rb
showoff-0.17.1 lib/commandline_parser.rb
showoff-0.17.0 lib/commandline_parser.rb
showoff-0.16.2 lib/commandline_parser.rb
showoff-0.16.1 lib/commandline_parser.rb
showoff-0.16.0 lib/commandline_parser.rb