class DataMetaDom::SourceFile
A Model
coupled with the DataMeta DOM source file info
For command line details either check the new method's source or the README.rdoc file, the usage section.
Attributes
Unique key of this source file to use in hash maps, the absolute path to avoid duplicates by different ways to point to the file, turned into a symbol.
Current source line.
Current source line number
The name of this source file in the directory indicated by the path property.
The namespace associated with the source file.
The directory to this source file.
Public Class Methods
Create an instance with the given parameters.
-
Parameters:
-
path
- directory where the source file is located -
name
- the base name of this source file -
line
- source line if any, useful when creating the source reference from the code when source is not trivial. -
lineNum
- line number, useful when creating the source reference from the code -
namespace
- namespace associated with this source file, useful when creating the source reference from the code
-
# File lib/dataMetaDom/sourceFile.rb, line 52 def initialize(path, name, line = nil, lineNum = 0, namespace = nil) #noinspection RubyArgCount super() @path = path @name = name @namespace = namespace # use the Absolute Path to avoid double-dipping via different subdir references @key = File.absolute_path("#{@path}#{File::SEPARATOR}#{@name}").to_sym @lineNum = lineNum @line = line # nil interpolates to an empty string end
Public Instance Methods
Full name of this source file, absolute path. Derived from the key property turned into a string.
# File lib/dataMetaDom/sourceFile.rb, line 142 def fullName; @key.to_s end
Advances a line, skipping empty lines and comments. Parameter:
-
verbatim
- pass true to maintain formatting and keep empty lines
# File lib/dataMetaDom/sourceFile.rb, line 119 def nextLine(verbatim = false) @file = File.open("#{@path}#{File::SEPARATOR}#{@name}") unless defined?(@file) && @file while (line = @file.gets) unless line @file.close nil end @lineNum += 1 return (@line = line) if verbatim @line = line.chomp.strip case @line when '', /^\s*#.*$/ # skip comments and empty lines next else return @line end end end
Parses this DataMeta DOM source into the given Model
.
# File lib/dataMetaDom/sourceFile.rb, line 77 def parse model while nextLine puts "Source: #{@line}" if $DEBUG next if docConsumed?(self) if (newVer = VerDoccable.verConsumed?(self)) raise RuntimeError, "Only one version definition allowed, second one found in line #{@lineNum}" if self.ver self.ver = newVer model.ver = newVer # plant it straight into the model per the latest design raise ArgumentError, %<Model version already defined as #{model.ver} but the file #{@path} tries to redefine it to #{newVer}. This is not allowed: all included files should define same version> unless model.ver && newVer == model.ver next end case @line # treat the namespace operator as a special case when /^\s*#{NAMESPACE}\s+([\w\.]+)$/ @namespace = $1 next when /^\s*#{INCLUDE}\s+(\S+)$/ model.sources.queue "#{$1}.dmDom" next else isTokenOk = false MODEL_LEVEL_TOKENS.each { |c| isTokenOk = c.consumed?(model, self) if isTokenOk resetEntity break end } raise "Syntax error; #{model.diagn}" unless isTokenOk end end # while end
Create a shapshot of the source file information, useful for saving a status about an element currently parsed. Can not use this instance - as the parsing progresses, the stateful information will change.
# File lib/dataMetaDom/sourceFile.rb, line 68 def snapshot # for the history snap = SourceFile.new(@path, @name, @line, @lineNum, @namespace) snap.ver = Ver.new(self.ver.full) snap end
Textual representation of this source file reference, includes line number and the current source line.
# File lib/dataMetaDom/sourceFile.rb, line 147 def to_s; "#{fullName}##{@lineNum}{{#{@line}}}" end