ARTS  2.2.66
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 "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 LineRaw() { return mLine; }
82 
84  Index ColumnRaw() { return mColumn; }
85 
87  Index Column() { return mColumn+1; }
88 
90  void SetPosition(Index line, Index column)
91  {
92  mLine = line;
93  mColumn = column;
94  }
95 
98  void Init();
99 
102  bool& LineBreak() { return mLineBreak; }
103 
106  bool LineBreak() const { return mLineBreak; }
107 
109  friend std::ostream& operator << (std::ostream& os, const SourceText& text);
110 
111 private:
112 
115 
118 
121 
124 
127 
131 };
132 
133 #endif /* sourcetext_h */
134 
const String & File()
Return the filename associated with the current position.
Definition: sourcetext.cc:88
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
bool LineBreak() const
Const version of LineBreak.
Definition: sourcetext.h:106
Index nelem() const
Number of elements.
Definition: array.h:176
void AdvanceChar()
Advance position pointer by one character.
Definition: sourcetext.cc:32
char Current()
Return the current character.
Definition: sourcetext.h:49
This file contains the definition of Array.
void AppendFile(const String &name)
Appends contents of file to the source text.
Definition: sourcetext.cc:23
The declarations of all the exception classes.
Index mColumn
Column position in the text.
Definition: sourcetext.h:120
Definition: exceptions.h:67
ArrayOfString mSfName
Names associated with.
Definition: sourcetext.h:126
A smart class to hold the text for parsing.
Definition: sourcetext.h:37
void Init()
This sets the pointer to the first existing character in the text.
Definition: sourcetext.cc:118
void SetPosition(Index line, Index column)
Set current position.
Definition: sourcetext.h:90
friend std::ostream & operator<<(std::ostream &os, const SourceText &text)
Output operator for SourceText.
Definition: sourcetext.cc:152
bool & LineBreak()
Read the line break flag.
Definition: sourcetext.h:102
ArrayOfString mText
The text.
Definition: sourcetext.h:114
Index mLine
Line position in the text.
Definition: sourcetext.h:117
Index ColumnRaw()
Return the column index.
Definition: sourcetext.h:84
bool mLineBreak
Is set to true if the last operation caused a line break.
Definition: sourcetext.h:130
bool reachedEot()
Check if the current position reached the end.
Definition: sourcetext.h:57
Index LineRaw()
Return the line index.
Definition: sourcetext.h:81
ArrayOfIndex mSfLine
Remember where which source file starts.
Definition: sourcetext.h:123
SourceText()
Default constructor.
Definition: sourcetext.h:41
void AdvanceLine()
Advances position pointer by one line.
Definition: sourcetext.cc:66
Index Column()
Return the current column.
Definition: sourcetext.h:87
Index Line()
Return the line number, but for the file that is associated with the current position.
Definition: sourcetext.cc:103
This file contains the definition of String, the ARTS string class.