linc 0.7
Linc is a general-purpose programming language inspired by C
Loading...
Searching...
No Matches
linc::Code Class Referencefinal

Static code utility class. More...

#include <Code.hpp>

Classes

struct  Character
 Structure representation of a character, along with the corresponding line and file it belongs to. Note: not all characters are represented using this format, as that would be too memory intensive. More...
 
struct  Line
 Structure representation of a single line of code, along with the corresponding file and line it belongs to. More...
 

Public Types

using Source = std::vector<Line>
 Representation of source code, as a dynamic array of lines.
 
using SourceSize = Source::size_type
 The appropriate size type for the source code array type.
 
using StringSize = std::string::size_type
 The appropriate size type for a standard string.
 

Static Public Member Functions

static std::string trim (const std::string &text)
 
static void append (Source &source, const Source &new_source)
 Append a source to its destination, similar to how it's done with strings.
 
static Source toSource (std::string raw_source, const std::string &filepath="")
 Convert raw source code to the 'source' structure in use. Use the given filenames and compute the line numbers for each line.
 
static std::optional< Characterpeek (const Source &source, StringSize character_index, StringSize line_index, StringSize offset)
 Compute the character at a specified offset past the given indices of a source structure, which may also be out of bounds for the current line. If so, the following line is checked for accordingly.
 
static Character consume (const Source &source, StringSize &character_index, StringSize &line_index)
 Compute the immediate next character past the given indices of a source structure, then increment them accordingly.
 

Detailed Description

Static code utility class.

Member Function Documentation

◆ append()

static void linc::Code::append ( Source & source,
const Source & new_source )
inlinestatic

Append a source to its destination, similar to how it's done with strings.

Parameters
sourceThe destination source.
new_sourceThe source to be appended.

◆ consume()

static Character linc::Code::consume ( const Source & source,
StringSize & character_index,
StringSize & line_index )
inlinestaticnodiscard

Compute the immediate next character past the given indices of a source structure, then increment them accordingly.

Parameters
sourceThe source code to use.
character_indexThe current character index for the current line.
line_indexThe current line index.
Returns
The structure corresponding to the consumed, now previous character.

◆ peek()

static std::optional< Character > linc::Code::peek ( const Source & source,
StringSize character_index,
StringSize line_index,
StringSize offset )
inlinestaticnodiscard

Compute the character at a specified offset past the given indices of a source structure, which may also be out of bounds for the current line. If so, the following line is checked for accordingly.

Parameters
sourceThe source code to test for.
character_indexThe current character index for the current line.
line_indexThe current line index.
offsetThe offset (in characters) past the current indices.
Returns
The structure corresponding to the resulting character.

◆ toSource()

static Source linc::Code::toSource ( std::string raw_source,
const std::string & filepath = "" )
inlinestaticnodiscard

Convert raw source code to the 'source' structure in use. Use the given filenames and compute the line numbers for each line.

Parameters
raw_sourceThe original, raw source code.
filepathThe filepath of the source file (can be arbitrary if from a buffer, e.g. from stdin).
Returns
The resulting source code.

The documentation for this class was generated from the following file: