ARTS  2.4.0(git:4fb77825)
sourcetext.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Oliver Lemke <olemke@core-dump.info>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
18 #ifndef sourcetext_h
19 #define sourcetext_h
20 
21 #include "array.h"
22 #include "exceptions.h"
23 #include "mystring.h"
24 
36 class SourceText {
37  public:
40  : mLine(0), mColumn(0), mLineBreak(false) { /* Nothing to be done here. */
41  }
42 
45  void AppendFile(const String& name);
46 
48  char Current() {
49  if (reachedEot()) throw Eot("", this->File(), this->Line(), this->Column());
50 
51  return mText[mLine][mColumn];
52  }
53 
55  bool reachedEot() {
56  return (mLine >= mText.nelem() ||
57  (mLine == mText.nelem() - 1 && mColumn >= mText[mLine].nelem()));
58  }
59 
64  void AdvanceChar();
65 
69  void AdvanceLine();
70 
72  const String& File();
73 
76  Index Line() { return GetSourceLine(mLine); };
77 
81 
83  Index LineRaw() { return mLine; }
84 
86  Index ColumnRaw() { return mColumn; }
87 
89  Index Column() { return mColumn + 1; }
90 
92  Index MarkedColumn() { return mMarkedColumn + 1; }
93 
95  void SetPosition(Index line, Index column) {
96  mLine = line;
97  mColumn = column;
98  }
99 
101  void SetMark() {
102  mMarkedLine = mLine;
104  }
105 
108  void Init();
109 
112  bool& LineBreak() { return mLineBreak; }
113 
116  bool LineBreak() const { return mLineBreak; }
117 
119  friend std::ostream& operator<<(std::ostream& os, const SourceText& text);
120 
121  private:
124  Index GetSourceLine(const Index line);
125 
128 
131 
134 
137 
140 
143 
146 
150 };
151 
152 #endif /* sourcetext_h */
SourceText::mMarkedColumn
Index mMarkedColumn
Marked column position in the text.
Definition: sourcetext.h:139
SourceText::AppendFile
void AppendFile(const String &name)
Appends contents of file to the source text.
Definition: sourcetext.cc:22
exceptions.h
The declarations of all the exception classes.
SourceText::GetSourceLine
Index GetSourceLine(const Index line)
Return the line number, but for the file that is associated with the given position.
Definition: sourcetext.cc:93
SourceText::mColumn
Index mColumn
Column position in the text.
Definition: sourcetext.h:133
SourceText::Init
void Init()
This sets the pointer to the first existing character in the text.
Definition: sourcetext.cc:74
SourceText::SetPosition
void SetPosition(Index line, Index column)
Set current position.
Definition: sourcetext.h:95
SourceText::mSfName
ArrayOfString mSfName
Names associated with.
Definition: sourcetext.h:145
SourceText::mText
ArrayOfString mText
The text.
Definition: sourcetext.h:127
SourceText::ColumnRaw
Index ColumnRaw()
Return the column index.
Definition: sourcetext.h:86
SourceText::operator<<
friend std::ostream & operator<<(std::ostream &os, const SourceText &text)
Output operator for SourceText.
Definition: sourcetext.cc:107
SourceText::LineBreak
bool & LineBreak()
Read the line break flag.
Definition: sourcetext.h:112
SourceText::MarkedColumn
Index MarkedColumn()
Return the current marked column.
Definition: sourcetext.h:92
SourceText::mLine
Index mLine
Line position in the text.
Definition: sourcetext.h:130
SourceText::mLineBreak
bool mLineBreak
Is set to true if the last operation caused a line break.
Definition: sourcetext.h:149
SourceText::reachedEot
bool reachedEot()
Check if the current position reached the end.
Definition: sourcetext.h:55
array.h
This file contains the definition of Array.
SourceText::LineRaw
Index LineRaw()
Return the line index.
Definition: sourcetext.h:83
SourceText::SourceText
SourceText()
Default constructor.
Definition: sourcetext.h:39
Array< String >
SourceText::Line
Index Line()
Return the line number, but for the file that is associated with the current position.
Definition: sourcetext.h:76
SourceText::mSfLine
ArrayOfIndex mSfLine
Remember where which source file starts.
Definition: sourcetext.h:142
SourceText::AdvanceLine
void AdvanceLine()
Advances position pointer by one line.
Definition: sourcetext.cc:48
SourceText::Column
Index Column()
Return the current column.
Definition: sourcetext.h:89
my_basic_string< char >
Eot
Definition: exceptions.h:67
SourceText::File
const String & File()
Return the filename associated with the current position.
Definition: sourcetext.cc:60
SourceText::LineBreak
bool LineBreak() const
Const version of LineBreak.
Definition: sourcetext.h:116
SourceText
A smart class to hold the text for parsing.
Definition: sourcetext.h:36
SourceText::SetMark
void SetMark()
Mark current position.
Definition: sourcetext.h:101
SourceText::Current
char Current()
Return the current character.
Definition: sourcetext.h:48
SourceText::MarkedLine
Index MarkedLine()
Return the marked line number, but for the file that is associated with the current position.
Definition: sourcetext.h:80
SourceText::AdvanceChar
void AdvanceChar()
Advance position pointer by one character.
Definition: sourcetext.cc:29
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
SourceText::mMarkedLine
Index mMarkedLine
Marked line position in the text.
Definition: sourcetext.h:136
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:195
mystring.h
This file contains the definition of String, the ARTS string class.