class Generic
Represents a generic language implementation that can be extended for specific languages.
Definitions
def initialize(name, extensions: self.class::EXTENSIONS, tags: self.class::TAGS)
Initialize a new generic language.
@parameter name [String] The name of the language.
@parameter extensions [Array(String)] File extensions for this language.
Implementation
def initialize(name, extensions: self.class::EXTENSIONS, tags: self.class::TAGS)
@name = name
@extensions = extensions
@tags = tags
end
attr :name
The name of this language.
@attribute [String] The language name.
def names
Get all names for this language.
@returns [Array(String)] An array containing the language name.
Implementation
def names
[@name]
end
attr :extensions
The file extensions this language supports.
@attribute [Array(String)] The supported file extensions.
def reference_for(identifier)
Generate a language-specific reference.
@parameter identifier [String] A valid identifier for this language.
@returns [Reference] A reference object for the given identifier.
Implementation
def reference_for(identifier)
Reference.new(identifier, self)
end
def parser
Get the parser for this language.
@returns [Parser | Nil] The parser instance, or nil if not available.
Implementation
def parser
nil
end
def definitions_for(source, &block)
Parse the input yielding definitions.
@parameter source [Source] The input source file which contains the source code.
@yields |definition| ...
Receives the definitions extracted from the source code.
@parameter definition [Definition] The source code definition including methods, classes, etc.
@returns [Enumerator(Segment)] If no block given.
Implementation
def definitions_for(source, &block)
if parser = self.parser
parser.definitions_for(source, &block)
end
end
def segments_for(source, &block)
Parse the input yielding segments.
Segments are constructed from a block of top level comments followed by a block of code.
@parameter source [Source] The input source file which contains the source code.
@yields |segment| ...
@parameter segment [Segment]
@returns [Enumerator(Segment)] If no block given.
Implementation
def segments_for(source, &block)
if parser = self.parser
parser.segments_for(source, &block)
end
end