ARTS 2.5.11 (git: 6827797f)
sourcetext.h
Go to the documentation of this file.
1#ifndef sourcetext_h
2#define sourcetext_h
3
4#include "array.h"
5#include "exceptions.h"
6#include "mystring.h"
7
20 public:
23 : mLine(0), mColumn(0), mLineBreak(false) { /* Nothing to be done here. */
24 }
25
28 void AppendFile(const String& name);
29
31 char Current() {
32 if (reachedEot()) throw Eot("", this->File(), this->Line(), this->Column());
33
34 return mText[mLine][mColumn];
35 }
36
38 bool reachedEot() {
39 return (mLine >= mText.nelem() ||
40 (mLine == mText.nelem() - 1 && mColumn >= mText[mLine].nelem()));
41 }
42
47 void AdvanceChar();
48
52 void AdvanceLine();
53
55 const String& File();
56
59 Index Line() { return GetSourceLine(mLine); };
60
63 Index MarkedLine() { return GetSourceLine(mMarkedLine); };
64
66 Index LineRaw() { return mLine; }
67
69 Index ColumnRaw() { return mColumn; }
70
72 Index Column() { return mColumn + 1; }
73
75 Index MarkedColumn() { return mMarkedColumn + 1; }
76
78 void SetPosition(Index line, Index column) {
79 mLine = line;
80 mColumn = column;
81 }
82
84 void SetMark() {
87 }
88
91 void Init();
92
95 bool& LineBreak() { return mLineBreak; }
96
99 bool LineBreak() const { return mLineBreak; }
100
102 friend std::ostream& operator<<(std::ostream& os, const SourceText& text);
103
104 private:
107 Index GetSourceLine(const Index line);
108
111
113 Index mLine;
114
116 Index mColumn;
117
120
123
126
129
133};
134
135#endif /* sourcetext_h */
This file contains the definition of Array.
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:75
Definition: exceptions.h:46
A smart class to hold the text for parsing.
Definition: sourcetext.h:19
bool LineBreak() const
Const version of LineBreak.
Definition: sourcetext.h:99
ArrayOfIndex mSfLine
Remember where which source file starts.
Definition: sourcetext.h:125
Index MarkedLine()
Return the marked line number, but for the file that is associated with the current position.
Definition: sourcetext.h:63
friend std::ostream & operator<<(std::ostream &os, const SourceText &text)
Output operator for SourceText.
Definition: sourcetext.cc:90
void AdvanceChar()
Advance position pointer by one character.
Definition: sourcetext.cc:12
void AdvanceLine()
Advances position pointer by one line.
Definition: sourcetext.cc:31
Index Line()
Return the line number, but for the file that is associated with the current position.
Definition: sourcetext.h:59
SourceText()
Default constructor.
Definition: sourcetext.h:22
Index mColumn
Column position in the text.
Definition: sourcetext.h:116
const String & File()
Return the filename associated with the current position.
Definition: sourcetext.cc:43
void SetMark()
Mark current position.
Definition: sourcetext.h:84
void AppendFile(const String &name)
Appends contents of file to the source text.
Definition: sourcetext.cc:5
Index mLine
Line position in the text.
Definition: sourcetext.h:113
char Current()
Return the current character.
Definition: sourcetext.h:31
bool & LineBreak()
Read the line break flag.
Definition: sourcetext.h:95
ArrayOfString mText
The text.
Definition: sourcetext.h:110
Index MarkedColumn()
Return the current marked column.
Definition: sourcetext.h:75
bool reachedEot()
Check if the current position reached the end.
Definition: sourcetext.h:38
Index mMarkedColumn
Marked column position in the text.
Definition: sourcetext.h:122
Index Column()
Return the current column.
Definition: sourcetext.h:72
Index GetSourceLine(const Index line)
Return the line number, but for the file that is associated with the given position.
Definition: sourcetext.cc:76
Index mMarkedLine
Marked line position in the text.
Definition: sourcetext.h:119
ArrayOfString mSfName
Names associated with.
Definition: sourcetext.h:128
void Init()
This sets the pointer to the first existing character in the text.
Definition: sourcetext.cc:57
Index LineRaw()
Return the line index.
Definition: sourcetext.h:66
Index ColumnRaw()
Return the column index.
Definition: sourcetext.h:69
bool mLineBreak
Is set to true if the last operation caused a line break.
Definition: sourcetext.h:132
void SetPosition(Index line, Index column)
Set current position.
Definition: sourcetext.h:78
The declarations of all the exception classes.
This file contains the definition of String, the ARTS string class.