Class: Carbon::Compiler::Project::File
- Inherits:
-
Object
- Object
- Carbon::Compiler::Project::File
- Defined in:
- lib/carbon/compiler/project/file.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
- #module ⇒ Object
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
Instance Method Summary collapse
- #call(index, diagnostics) ⇒ Object
- #emit(*p) ⇒ Object
-
#initialize(path, root, project) ⇒ File
constructor
A new instance of File.
- #lines ⇒ Object
- #parser ⇒ Object
- #read ⇒ Object
- #scanner ⇒ Object
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).(@root) @short = @path.relative_path_from(@root) @name = @short.sub_ext("").to_s @project = project @aliases = {} end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
12 13 14 |
# File 'lib/carbon/compiler/project/file.rb', line 12 def aliases @aliases end |
#module ⇒ Object
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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/carbon/compiler/project/file.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/carbon/compiler/project/file.rb', line 10 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
9 10 11 |
# File 'lib/carbon/compiler/project/file.rb', line 9 def root @root end |
#short ⇒ Object (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 |
#lines ⇒ Object
58 59 60 |
# File 'lib/carbon/compiler/project/file.rb', line 58 def lines @_lines ||= @path.each_line end |
#parser ⇒ Object
46 47 48 |
# File 'lib/carbon/compiler/project/file.rb', line 46 def parser @parser ||= Compiler::Parser.new(scanner) end |
#read ⇒ Object
54 55 56 |
# File 'lib/carbon/compiler/project/file.rb', line 54 def read @_read ||= @path.read end |