ARTS 2.5.11 (git: 6827797f)
sourcetext.cc
Go to the documentation of this file.
1#include "sourcetext.h"
2#include <iostream>
3#include "file.h"
4
5void SourceText::AppendFile(const String& name) {
6 mSfLine.push_back(mText.nelem());
7 mSfName.push_back(name);
8
10}
11
13 if (mColumn < mText[mLine].nelem() - 1) {
14 ++mColumn;
15 } else {
16 mLineBreak = true;
17 do {
18 if (mLine >= mText.nelem()) {
19 throw Eot("", this->File(), this->Line(), this->Column());
20 } else if (mLine == mText.nelem() - 1) {
21 mColumn++;
22 break;
23 } else {
24 ++mLine;
25 mColumn = 0;
26 }
27 } while (1 > mText[mLine].nelem()); // Skip empty lines.
28 }
29}
30
32 mLineBreak = true;
33 mColumn = 0;
34 do {
35 if (mLine >= mText.nelem() - 1) {
36 throw Eot("", this->File(), this->Line(), this->Column());
37 } else {
38 ++mLine;
39 }
40 } while (1 > mText[mLine].nelem()); // Skip empty lines.
41}
42
44 Index i = 0;
45 bool stop = false;
46
47 while (i < mSfLine.nelem() - 1 && !stop) {
48 if (mLine >= mSfLine[i + 1])
49 ++i;
50 else
51 stop = true;
52 }
53
54 return mSfName[i];
55}
56
58 mLine = 0;
59 mColumn = 0;
60
61 if (1 > mText.nelem()) {
62 throw Eot("Empty text!", this->File(), this->Line(), this->Column());
63 } else {
64 // Skip empty lines:
65 while (1 > mText[mLine].nelem()) {
66 if (mLine >= mText.nelem() - 1) {
67 throw Eot("", this->File(), this->Line(), this->Column());
68 } else {
69 mLineBreak = true;
70 ++mLine;
71 }
72 }
73 }
74}
75
76Index SourceText::GetSourceLine(const Index line) {
77 Index i = 0;
78 bool stop = false;
79
80 while (i < mSfLine.nelem() - 1 && !stop) {
81 if (line >= mSfLine[i + 1])
82 ++i;
83 else
84 stop = true;
85 }
86
87 return line - mSfLine[i] + 1;
88}
89
90std::ostream& operator<<(std::ostream& os, const SourceText& text) {
91 for (Index i = 0; i < text.mText.nelem(); ++i)
92 os << i << "(" << text.mText[i].nelem() << ")"
93 << ": " << text.mText[i] << '\n';
94 return (os);
95}
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
ArrayOfIndex mSfLine
Remember where which source file starts.
Definition: sourcetext.h:125
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
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 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
ArrayOfString mText
The text.
Definition: sourcetext.h:110
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
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
bool mLineBreak
Is set to true if the last operation caused a line break.
Definition: sourcetext.h:132
ArrayOfString read_text_from_file(const std::string_view name)
Reads an ASCII file and appends the contents to the String vector text.
Definition: file.cc:186
This file contains basic functions to handle ASCII files.
std::ostream & operator<<(std::ostream &os, const SourceText &text)
Definition: sourcetext.cc:90