Class: Carbon::Compiler::Project::File

Inherits:
Object
  • Object
show all
Defined in:
lib/carbon/compiler/project/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, root, project) ⇒ File

Returns a new instance of File.



14
15
16
17
18
19
20
21
# File 'lib/carbon/compiler/project/file.rb', line 14

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

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



12
13
14
# File 'lib/carbon/compiler/project/file.rb', line 12

def aliases
  @aliases
end

#moduleObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/carbon/compiler/project/file.rb', line 23

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

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/carbon/compiler/project/file.rb', line 8

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/carbon/compiler/project/file.rb', line 10

def path
  @path
end

#rootObject (readonly)

Returns the value of attribute root.



9
10
11
# File 'lib/carbon/compiler/project/file.rb', line 9

def root
  @root
end

#shortObject (readonly)

Returns the value of attribute short.



11
12
13
# File 'lib/carbon/compiler/project/file.rb', line 11

def short
  @short
end

Instance Method Details

#call(index, diagnostics) ⇒ Object



40
41
42
43
44
# File 'lib/carbon/compiler/project/file.rb', line 40

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

#emit(*p) ⇒ Object



36
37
38
# File 'lib/carbon/compiler/project/file.rb', line 36

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

#linesObject



58
59
60
# File 'lib/carbon/compiler/project/file.rb', line 58

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

#parserObject



46
47
48
# File 'lib/carbon/compiler/project/file.rb', line 46

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

#readObject



54
55
56
# File 'lib/carbon/compiler/project/file.rb', line 54

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

#scannerObject



50
51
52
# File 'lib/carbon/compiler/project/file.rb', line 50

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