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.
Signature
-
parameter
nameString The name of the language.
-
parameter
extensionsArray(String) File extensions for this language.
-
parameter
tagsComment::Tags The comment tags to recognize.
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.
Signature
-
attribute
String The language name.
def names
Get all names for this language.
Signature
-
returns
Array(String) An array containing the language name.
Implementation
def names
[@name]
end
attr :extensions
The file extensions this language supports.
Signature
-
attribute
Array(String) The supported file extensions.
def reference_for(identifier)
Generate a language-specific reference.
Signature
-
parameter
identifierString 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.
Signature
-
returns
untyped The parser instance, or nil if not available.
Implementation
def parser
nil
end
def definitions_for(source, &block)
Parse the input yielding definitions.
Signature
-
parameter
sourceSource The input source file which contains the source code.
-
yields
{|definition| ...} Receives the definitions extracted from the source code.
-
parameter
definitionDefinition The source code definition including methods, classes, etc.
-
parameter
-
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.
Signature
-
parameter
sourceSource The input source file which contains the source code.
-
yields
{|segment| ...} -
parameter
segmentSegment
-
parameter
-
returns
Enumerator(Segment) If no block given.
Implementation
def segments_for(source, &block)
if parser = self.parser
parser.segments_for(source, &block)
end
end
def code_for(text, index, relative_to: nil)
Generate a code representation with syntax highlighting and link resolution.
Signature
-
parameter
textString The source code text to format.
-
parameter
indexIndex The index for resolving references.
-
parameter
relative_toDefinition The definition to resolve relative references from.
-
returns
untyped A formatted code object with syntax highlighting.
Implementation
def code_for(text, index, relative_to: nil)
raise NotImplementedError, "Code generation is not implemented for #{self.class}!"
end