Sha256: f5134937e2d2f3797e353441d10d99a1946f2ad6bcd8cf4dd84cceb2af50ddca

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module Carbon
  module Compiler
    class Project
      class File
        attr_reader :name
        attr_reader :root
        attr_reader :path
        attr_reader :short
        attr_reader :aliases

        def initialize(path, root, project)
          @root = Pathname.new(root)
          @path = Pathname.new(path).expand_path(@root)
          @short = @path.relative_path_from(@root)
          @name = @short.sub_ext("").to_s
          @project = project
          @aliases = {}
        end

        def module
          @module ||= begin
            mname = @name
              .gsub(/\A([a-z])/, &:upcase)
              .gsub(/(\/|\\)([a-z])/) { |m| "::#{m[1].upcase}" }
              .gsub(/_([a-z])/) { |m| m[1].upcase }
              .gsub(/\/|\\/, "::")
            Carbon::Type(mname)
          end
        end

        attr_writer :module

        def emit(*p)
          @diagnostics.emit(*p)
        end

        def call(index, diagnostics)
          @diagnostics = diagnostics
          root = Visitor::Preparation.new(self, index).call(parser.root)
          Visitor::Generation.new(self, index).call(root)
        end

        def parser
          @parser ||= Compiler::Parser.new(scanner)
        end

        def scanner
          @scanner ||= Compiler::Scanner.new(self)
        end

        def read
          @_read ||= @path.read
        end

        def lines
          @_lines ||= @path.each_line
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carbon-compiler-0.2.0 lib/carbon/compiler/project/file.rb