Sha256: 4cbe2d70de64234b63f0026befc9db790a0d651320a77046f1aca36a57d65b05

Contents?: true

Size: 810 Bytes

Versions: 6

Compression:

Stored size: 810 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module RBS
    class ProcessedRBSSource
      attr_reader :raw_source
      attr_reader :source
      attr_reader :buffer
      attr_reader :directives
      attr_reader :decls
      attr_reader :error

      def initialize(source)
        @raw_source = source.content
        @buffer, @directives, @decls = ::RBS::Parser.parse_signature(source)
        @error = nil
        @tokens = nil
      rescue ::RBS::ParsingError => e
        @error = e
      end

      def valid_syntax?
        @error.nil?
      end

      def tokens(with_trivia: false)
        @tokens ||= begin
          tokens = ::RBS::Parser.lex(buffer).value
          tokens.reject! { |token| token.type == :tTRIVIA } unless with_trivia
          tokens
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-on-rbs-1.2.0 lib/rubocop/rbs/processed_rbs_source.rb
rubocop-on-rbs-1.1.0 lib/rubocop/rbs/processed_rbs_source.rb
rubocop-on-rbs-1.0.0 lib/rubocop/rbs/processed_rbs_source.rb
rubocop-on-rbs-0.9.0 lib/rubocop/rbs/processed_rbs_source.rb
rubocop-on-rbs-0.8.0 lib/rubocop/rbs/processed_rbs_source.rb
rubocop-on-rbs-0.7.0 lib/rubocop/rbs/processed_rbs_source.rb