ARTS 2.5.11 (git: 6827797f)
SourceText Class Reference

A smart class to hold the text for parsing. More...

#include <sourcetext.h>

Public Member Functions

 SourceText ()
 Default constructor.
 
void AppendFile (const String &name)
 Appends contents of file to the source text.
 
char Current ()
 Return the current character.
 
bool reachedEot ()
 Check if the current position reached the end.
 
void AdvanceChar ()
 Advance position pointer by one character.
 
void AdvanceLine ()
 Advances position pointer by one line.
 
const StringFile ()
 Return the filename associated with the current position.
 
Index Line ()
 Return the line number, but for the file that is associated with the current position.
 
Index MarkedLine ()
 Return the marked line number, but for the file that is associated with the current position.
 
Index LineRaw ()
 Return the line index.
 
Index ColumnRaw ()
 Return the column index.
 
Index Column ()
 Return the current column.
 
Index MarkedColumn ()
 Return the current marked column.
 
void SetPosition (Index line, Index column)
 Set current position.
 
void SetMark ()
 Mark current position.
 
void Init ()
 This sets the pointer to the first existing character in the text.
 
bool & LineBreak ()
 Read the line break flag.
 
bool LineBreak () const
 Const version of LineBreak.
 

Private Member Functions

Index GetSourceLine (const Index line)
 Return the line number, but for the file that is associated with the given position.
 

Private Attributes

ArrayOfString mText
 The text.
 
Index mLine
 Line position in the text.
 
Index mColumn
 Column position in the text.
 
Index mMarkedLine
 Marked line position in the text.
 
Index mMarkedColumn
 Marked column position in the text.
 
ArrayOfIndex mSfLine
 Remember where which source file starts.
 
ArrayOfString mSfName
 Names associated with.
 
bool mLineBreak
 Is set to true if the last operation caused a line break.
 

Friends

std::ostream & operator<< (std::ostream &os, const SourceText &text)
 Output operator for SourceText.
 

Detailed Description

A smart class to hold the text for parsing.

A variable of this class can hold not only the text of the ARTS Control file, but also a position in the text. This is handy for parsing. There is also a function to return the current character and functions to advance the position. (AdvanceChar advances the position to the next character, doing a line break if necessary; AdvanceLine goes to the next line.)

mLine and mColumn are 0 based, but Line and Column are 1 based.

Author
Stefan Buehler

Definition at line 19 of file sourcetext.h.

Constructor & Destructor Documentation

◆ SourceText()

SourceText::SourceText ( )
inline

Default constructor.

Definition at line 22 of file sourcetext.h.

Member Function Documentation

◆ AdvanceChar()

◆ AdvanceLine()

void SourceText::AdvanceLine ( )

Advances position pointer by one line.

Exceptions
EotThe end of the text is reached.

Definition at line 31 of file sourcetext.cc.

References Column(), File(), Line(), mColumn, mLine, mLineBreak, mText, and Array< base >::nelem().

Referenced by ArtsParser::eat_whitespace(), and ArtsParser::skip_to_next_argument().

◆ AppendFile()

void SourceText::AppendFile ( const String name)

Appends contents of file to the source text.

See also
read_text_from_file

Definition at line 5 of file sourcetext.cc.

References mSfLine, mSfName, mText, Array< base >::nelem(), and read_text_from_file().

Referenced by ArtsParser::ArtsParser().

◆ Column()

◆ ColumnRaw()

Index SourceText::ColumnRaw ( )
inline

Return the column index.

Definition at line 69 of file sourcetext.h.

References mColumn.

Referenced by ArtsParser::find_named_arguments(), ArtsParser::parse_method_args(), and ArtsParser::skip_to_next_argument().

◆ Current()

◆ File()

◆ GetSourceLine()

Index SourceText::GetSourceLine ( const Index  line)
private

Return the line number, but for the file that is associated with the given position.

Definition at line 76 of file sourcetext.cc.

References mSfLine, and Array< base >::nelem().

Referenced by Line(), and MarkedLine().

◆ Init()

void SourceText::Init ( )

This sets the pointer to the first existing character in the text.

(First few lines could be empty).

Definition at line 57 of file sourcetext.cc.

References Column(), File(), Line(), mColumn, mLine, mLineBreak, mText, and Array< base >::nelem().

Referenced by ArtsParser::parse_main().

◆ Line()

◆ LineBreak() [1/2]

bool & SourceText::LineBreak ( )
inline

Read the line break flag.

Set this to false before an operation that you want to monitor and check it afterwards.

Definition at line 95 of file sourcetext.h.

References mLineBreak.

Referenced by ArtsParser::parse_String(), ArtsParser::read_integer(), ArtsParser::read_name(), and ArtsParser::read_numeric().

◆ LineBreak() [2/2]

bool SourceText::LineBreak ( ) const
inline

Const version of LineBreak.

See also
LineBreak

Definition at line 99 of file sourcetext.h.

References mLineBreak.

◆ LineRaw()

Index SourceText::LineRaw ( )
inline

Return the line index.

Definition at line 66 of file sourcetext.h.

References mLine.

Referenced by ArtsParser::find_named_arguments(), ArtsParser::parse_method_args(), and ArtsParser::skip_to_next_argument().

◆ MarkedColumn()

Index SourceText::MarkedColumn ( )
inline

Return the current marked column.

Definition at line 75 of file sourcetext.h.

References mMarkedColumn.

Referenced by ArtsParser::parse_method_args(), and ArtsParser::use_default_method_args().

◆ MarkedLine()

Index SourceText::MarkedLine ( )
inline

Return the marked line number, but for the file that is associated with the current position.

Definition at line 63 of file sourcetext.h.

References GetSourceLine(), and mMarkedLine.

Referenced by ArtsParser::parse_method_args(), and ArtsParser::use_default_method_args().

◆ reachedEot()

bool SourceText::reachedEot ( )
inline

Check if the current position reached the end.

Definition at line 38 of file sourcetext.h.

References mColumn, mLine, mText, and Array< base >::nelem().

Referenced by Current(), and ArtsParser::parse_main().

◆ SetMark()

void SourceText::SetMark ( )
inline

Mark current position.

Definition at line 84 of file sourcetext.h.

References mColumn, mLine, mMarkedColumn, and mMarkedLine.

Referenced by ArtsParser::parse_method().

◆ SetPosition()

void SourceText::SetPosition ( Index  line,
Index  column 
)
inline

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const SourceText text 
)
friend

Output operator for SourceText.

(Only used for debugging)

Definition at line 90 of file sourcetext.cc.

Member Data Documentation

◆ mColumn

Index SourceText::mColumn
private

Column position in the text.

(0 based!)

Definition at line 116 of file sourcetext.h.

Referenced by AdvanceChar(), AdvanceLine(), Column(), ColumnRaw(), Current(), Init(), reachedEot(), SetMark(), and SetPosition().

◆ mLine

Index SourceText::mLine
private

Line position in the text.

(0 based!)

Definition at line 113 of file sourcetext.h.

Referenced by AdvanceChar(), AdvanceLine(), Current(), File(), Init(), Line(), LineRaw(), reachedEot(), SetMark(), and SetPosition().

◆ mLineBreak

bool SourceText::mLineBreak
private

Is set to true if the last operation caused a line break.

Has to be cleared explicitly!

Definition at line 132 of file sourcetext.h.

Referenced by AdvanceChar(), AdvanceLine(), Init(), and LineBreak().

◆ mMarkedColumn

Index SourceText::mMarkedColumn
private

Marked column position in the text.

(0 based!)

Definition at line 122 of file sourcetext.h.

Referenced by MarkedColumn(), and SetMark().

◆ mMarkedLine

Index SourceText::mMarkedLine
private

Marked line position in the text.

(0 based!)

Definition at line 119 of file sourcetext.h.

Referenced by MarkedLine(), and SetMark().

◆ mSfLine

ArrayOfIndex SourceText::mSfLine
private

Remember where which source file starts.

Definition at line 125 of file sourcetext.h.

Referenced by AppendFile(), File(), and GetSourceLine().

◆ mSfName

ArrayOfString SourceText::mSfName
private

Names associated with.

See also
mSfLine.

Definition at line 128 of file sourcetext.h.

Referenced by AppendFile(), and File().

◆ mText

ArrayOfString SourceText::mText
private

The text.

Definition at line 110 of file sourcetext.h.

Referenced by AdvanceChar(), AdvanceLine(), AppendFile(), Current(), Init(), and reachedEot().


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