Static code utility class.
More...
#include <Code.hpp>
|
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...
|
|
|
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 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< Character > | peek (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.
|
|
Static code utility class.
◆ 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
-
source | The destination source. |
new_source | The source to be appended. |
◆ consume()
Compute the immediate next character past the given indices of a source structure, then increment them accordingly.
- Parameters
-
source | The source code to use. |
character_index | The current character index for the current line. |
line_index | The current line index. |
- Returns
- The structure corresponding to the consumed, now previous character.
◆ peek()
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
-
source | The source code to test for. |
character_index | The current character index for the current line. |
line_index | The current line index. |
offset | The 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_source | The original, raw source code. |
filepath | The 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: