Sha256: 472ba33e0fd83b8478bf8cf1700508039bd361d9b57fb58062e9ed16f6fc68d0

Contents?: true

Size: 1.24 KB

Versions: 14

Compression:

Stored size: 1.24 KB

Contents

# -*- coding: utf-8 -*- #

module Rouge
  module Lexers
    load_lexer 'console.rb'

    class IRBLexer < ConsoleLexer
      tag 'irb'
      aliases 'pry'

      desc 'Shell sessions in IRB or Pry'

      # unlike the superclass, we do not accept any options
      @option_docs = {}

      def output_lexer
        @output_lexer ||= IRBOutputLexer.new(@options)
      end

      def lang_lexer
        @lang_lexer ||= Ruby.new(@options)
      end

      def prompt_regex
        /^.*?(irb|pry).*?[>"*]/
      end

      def allow_comments?
        true
      end
    end

    load_lexer 'ruby.rb'
    class IRBOutputLexer < Ruby
      tag 'irb_output'

      start do
        push :stdout
      end

      state :has_irb_output do
        rule %r(=>), Punctuation, :pop!
        rule /.+?(\n|$)/, Generic::Output
      end

      state :irb_error do
        rule /.+?(\n|$)/, Generic::Error
        mixin :has_irb_output
      end

      state :stdout do
        rule /\w+?(Error|Exception):.+?(\n|$)/, Generic::Error, :irb_error
        mixin :has_irb_output
      end

      prepend :root do
        rule /#</, Keyword::Type, :irb_object
      end

      state :irb_object do
        rule />/, Keyword::Type, :pop!
        mixin :root
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/rouge-2.2.1/lib/rouge/lexers/irb.rb
rouge-3.2.1 lib/rouge/lexers/irb.rb
rouge-3.2.0 lib/rouge/lexers/irb.rb
rouge_ecl-1.0.0 lib/rouge/lexers/irb.rb
rouge_ecl-0.0.1 lib/rouge/lexers/irb.rb
rouge-3.1.1 lib/rouge/lexers/irb.rb
rouge-3.1.0 lib/rouge/lexers/irb.rb
rouge-3.0.0 lib/rouge/lexers/irb.rb
rouge-2.2.1 lib/rouge/lexers/irb.rb
rouge-2.2.0 lib/rouge/lexers/irb.rb
rougegal-2.1.2 lib/rouge/lexers/irb.rb
tdiary-5.0.5 vendor/bundle/gems/rouge-2.1.1/lib/rouge/lexers/irb.rb
rouge-2.1.1 lib/rouge/lexers/irb.rb
rouge-2.1.0 lib/rouge/lexers/irb.rb