tan  0.0.1
tanlang::SourceFile Class Referencefinal

Public Member Functions

void open (const str &filename)
 
void from_string (const str &code)
 
size_t size () const
 Return the number of lines of code of the current file. More...
 
str get_line (size_t index) const
 Return source at a specific line. More...
 
char at (const SrcLoc &ptr) const
 
str substr (const SrcLoc &start) const
 Get a substring from start to the end of the current line. More...
 
str substr (const SrcLoc &start, const SrcLoc &end) const
 Get a substring from the source code. More...
 
bool is_cursor_valid (const SrcLoc &c) const
 Check if a cursor is in bound. More...
 
SrcLoc begin () const
 The start of source file (inclusive). More...
 
SrcLoc end () const
 The end of source file (exclusive). More...
 
SrcLoc forward (SrcLoc c)
 Return a copy of code_ptr that points to the next character. More...
 
str get_filename () const
 

Detailed Description

Definition at line 10 of file source_file.h.

Member Function Documentation

◆ begin()

SrcLoc tanlang::SourceFile::begin ( ) const

The start of source file (inclusive).

Definition at line 128 of file source_file.cpp.

◆ end()

SrcLoc tanlang::SourceFile::end ( ) const

The end of source file (exclusive).

Definition at line 110 of file source_file.cpp.

Referenced by substr().

◆ forward()

SrcLoc tanlang::SourceFile::forward ( SrcLoc  c)

Return a copy of code_ptr that points to the next character.

Definition at line 92 of file source_file.cpp.

◆ get_line()

str tanlang::SourceFile::get_line ( size_t  index) const

Return source at a specific line.

Parameters
indexline of code starting from 0

Definition at line 130 of file source_file.cpp.

Referenced by substr().

◆ is_cursor_valid()

bool tanlang::SourceFile::is_cursor_valid ( const SrcLoc c) const

Check if a cursor is in bound.

Definition at line 47 of file source_file.cpp.

Referenced by substr().

◆ size()

size_t tanlang::SourceFile::size ( ) const
inline

Return the number of lines of code of the current file.

Definition at line 17 of file source_file.h.

◆ substr() [1/2]

str tanlang::SourceFile::substr ( const SrcLoc start) const

Get a substring from start to the end of the current line.

Parameters
startstart of the string, inclusive

Definition at line 87 of file source_file.cpp.

References end(), and get_line().

◆ substr() [2/2]

str tanlang::SourceFile::substr ( const SrcLoc start,
const SrcLoc end 
) const

Get a substring from the source code.

Parameters
startstart of the string, inclusive
endend of the string, exclusive

Definition at line 60 of file source_file.cpp.

References end(), and is_cursor_valid().


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