ARTS  2.3.1285(git:92a29ea9-dirty)
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 */
const String & File()
Return the filename associated with the current position.
Definition: sourcetext.cc:60
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
bool LineBreak() const
Const version of LineBreak.
Definition: sourcetext.h:116
Index nelem() const
Number of elements.
Definition: array.h:195
void SetMark()
Mark current position.
Definition: sourcetext.h:101
Index MarkedLine()
Return the marked line number, but for the file that is associated with the current position...
Definition: sourcetext.h:80
void AdvanceChar()
Advance position pointer by one character.
Definition: sourcetext.cc:29
char Current()
Return the current character.
Definition: sourcetext.h:48
This file contains the definition of Array.
Index mMarkedColumn
Marked column position in the text.
Definition: sourcetext.h:139
Index mMarkedLine
Marked line position in the text.
Definition: sourcetext.h:136
void AppendFile(const String &name)
Appends contents of file to the source text.
Definition: sourcetext.cc:22
Index GetSourceLine(const Index line)
Return the line number, but for the file that is associated with the given position.
Definition: sourcetext.cc:93
The declarations of all the exception classes.
Index mColumn
Column position in the text.
Definition: sourcetext.h:133
Definition: exceptions.h:67
ArrayOfString mSfName
Names associated with.
Definition: sourcetext.h:145
A smart class to hold the text for parsing.
Definition: sourcetext.h:36
void Init()
This sets the pointer to the first existing character in the text.
Definition: sourcetext.cc:74
void SetPosition(Index line, Index column)
Set current position.
Definition: sourcetext.h:95
friend std::ostream & operator<<(std::ostream &os, const SourceText &text)
Output operator for SourceText.
Definition: sourcetext.cc:107
bool & LineBreak()
Read the line break flag.
Definition: sourcetext.h:112
ArrayOfString mText
The text.
Definition: sourcetext.h:127
Index MarkedColumn()
Return the current marked column.
Definition: sourcetext.h:92
Index mLine
Line position in the text.
Definition: sourcetext.h:130
Index ColumnRaw()
Return the column index.
Definition: sourcetext.h:86
bool mLineBreak
Is set to true if the last operation caused a line break.
Definition: sourcetext.h:149
bool reachedEot()
Check if the current position reached the end.
Definition: sourcetext.h:55
Index LineRaw()
Return the line index.
Definition: sourcetext.h:83
ArrayOfIndex mSfLine
Remember where which source file starts.
Definition: sourcetext.h:142
SourceText()
Default constructor.
Definition: sourcetext.h:39
void AdvanceLine()
Advances position pointer by one line.
Definition: sourcetext.cc:48
Index Column()
Return the current column.
Definition: sourcetext.h:89
Index Line()
Return the line number, but for the file that is associated with the current position.
Definition: sourcetext.h:76
This file contains the definition of String, the ARTS string class.