ARTS  2.0.49
sourcetext.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 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 "mystring.h"
23 #include "exceptions.h"
24 
25 
37 class SourceText {
38 public:
39 
41  SourceText() : mLine(0), mColumn(0), mLineBreak(false)
42  { /* Nothing to be done here. */ }
43 
46  void AppendFile(const String& name);
47 
49  char Current() {
50  if (reachedEot())
51  throw Eot( "", this->File(), this->Line(), this->Column() );
52 
53  return mText[mLine][mColumn];
54  }
55 
57  bool reachedEot() {
58  return (mLine >= mText.nelem()
59  || (mLine == mText.nelem()-1 && mColumn >= mText[mLine].nelem()));
60  }
61 
66  void AdvanceChar();
67 
71  void AdvanceLine();
72 
74  const String& File();
75 
78  Index Line();
79 
81  Index Column() { return mColumn+1; }
82 
85  void Init();
86 
89  bool& LineBreak() { return mLineBreak; }
90 
93  bool LineBreak() const { return mLineBreak; }
94 
96  friend ostream& operator << (ostream& os, const SourceText& text);
97 
98 private:
99 
102 
105 
108 
111 
114 
118 };
119 
120 #endif /* sourcetext_h */
121 
SourceText::AppendFile
void AppendFile(const String &name)
Appends contents of file to the source text.
Definition: sourcetext.cc:23
exceptions.h
The declarations of all the exception classes.
SourceText::mColumn
Index mColumn
Column position in the text.
Definition: sourcetext.h:107
SourceText::Init
void Init()
This sets the pointer to the first existing character in the text.
Definition: sourcetext.cc:118
SourceText::mSfName
ArrayOfString mSfName
Names associated with.
Definition: sourcetext.h:113
SourceText::mText
ArrayOfString mText
The text.
Definition: sourcetext.h:101
SourceText::LineBreak
bool & LineBreak()
Read the line break flag.
Definition: sourcetext.h:89
SourceText::mLine
Index mLine
Line position in the text.
Definition: sourcetext.h:104
SourceText::operator<<
friend ostream & operator<<(ostream &os, const SourceText &text)
Output operator for SourceText.
Definition: sourcetext.cc:152
SourceText::mLineBreak
bool mLineBreak
Is set to true if the last operation caused a line break.
Definition: sourcetext.h:117
SourceText::reachedEot
bool reachedEot()
Check if the current position reached the end.
Definition: sourcetext.h:57
array.h
This file contains the definition of Array.
SourceText::SourceText
SourceText()
Default constructor.
Definition: sourcetext.h:41
Array< String >
SourceText::Line
Index Line()
Return the line number, but for the file that is associated with the current position.
Definition: sourcetext.cc:103
SourceText::mSfLine
ArrayOfIndex mSfLine
Remember where which source file starts.
Definition: sourcetext.h:110
SourceText::AdvanceLine
void AdvanceLine()
Advances position pointer by one line.
Definition: sourcetext.cc:66
SourceText::Column
Index Column()
Return the current column.
Definition: sourcetext.h:81
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:62
Eot
Definition: exceptions.h:67
SourceText::File
const String & File()
Return the filename associated with the current position.
Definition: sourcetext.cc:88
SourceText::LineBreak
bool LineBreak() const
Const version of LineBreak.
Definition: sourcetext.h:93
SourceText
A smart class to hold the text for parsing.
Definition: sourcetext.h:37
SourceText::Current
char Current()
Return the current character.
Definition: sourcetext.h:49
SourceText::AdvanceChar
void AdvanceChar()
Advance position pointer by one character.
Definition: sourcetext.cc:32
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:172
mystring.h
This file contains the definition of String, the ARTS string class.