ARTS  2.2.66
parser.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 parser_h
19 #define parser_h
20 
21 #include <map>
22 #include "agenda_class.h"
23 #include "sourcetext.h"
24 #include "methods.h"
25 
26 
27 class ArtsParser {
28 public:
29  ArtsParser(Agenda& tasklist, String controlfile, const Verbosity& verbosity);
30 
31  void parse_tasklist ();
32 
33 private:
34  typedef struct {
38  } NamedArgument;
39 
40  typedef vector<NamedArgument> NamedArguments;
41 
42  void find_named_arguments(vector<NamedArgument>& named_args);
43 
44  void skip_to_next_argument();
45 
46  void at_end_of_argument(const String& argname);
47 
48  void get_argument_index_by_name(Index& arg_index,
49  NamedArguments& named_args,
50  String name);
51 
52  void parse_main();
53 
54  void parse_agenda(Agenda& tasklist);
55 
56  void parse_method(Index& id,
57  ArrayOfIndex& output,
58  ArrayOfIndex& input,
59  Agenda& tasks,
60  ArrayOfIndex& auto_vars,
61  Array<TokVal>& auto_vars_values,
62  String& include_file,
63  bool no_eot=false);
64 
65  void parse_generic_input(const MdRecord*& mdd,
66  Index& id,
67  String& methodname,
68  ArrayOfIndex& input,
69  ArrayOfIndex& auto_vars,
70  Array<TokVal>& auto_vars_values,
71  bool& first,
72  bool& still_supergeneric,
73  String& supergeneric_args,
74  Index& supergeneric_index,
75  NamedArguments& named_args,
76  bool call_by_name
77  );
78 
79  void parse_generic_output(const MdRecord*& mdd,
80  Index& id,
81  String& methodname,
82  ArrayOfIndex& output,
83  bool& first,
84  bool& still_supergeneric,
85  String& supergeneric_args,
86  Index& supergeneric_index,
87  NamedArguments& named_args,
88  bool call_by_name
89  );
90 
91  void parse_specific_input(const MdRecord* mdd,
92  ArrayOfIndex& input,
93  ArrayOfIndex& auto_vars,
94  Array<TokVal>& auto_vars_values,
95  bool& first,
96  NamedArguments& named_args,
97  bool call_by_name
98  );
99 
100  void parse_specific_output(const MdRecord* mdd,
101  ArrayOfIndex& output,
102  bool& first,
103  NamedArguments& named_args,
104  bool call_by_name
105  );
106 
107 
108  void parse_method_args(const MdRecord*& mdd,
109  Index& id,
110  String& methodname,
111  ArrayOfIndex& output,
112  ArrayOfIndex& input,
113  ArrayOfIndex& auto_vars,
114  Array<TokVal>& auto_vars_values);
115 
117  ArrayOfIndex& auto_vars,
118  Array<TokVal>& auto_vars_values,
119  Index keyword_index);
120 
121  void tasklist_insert_set_delete(const ArrayOfIndex& auto_vars,
122  const Array<TokVal>& auto_vars_values,
123  const Index method_type,
124  Agenda& tasklist);
125 
126  bool is_whitespace(const char c);
127 
128  void eat_whitespace();
129 
130  void eat_whitespace_from_string(String& str, size_t& pos);
131 
132  void read_name(String& name);
133 
135  ArrayOfIndex& auto_vars,
136  Array<TokVal>& auto_vars_values,
137  const String& default_name,
138  const MdRecord* mdd,
139  const Index group);
140 
141  void assertain_character(char c);
142 
143  void parse_String(String& res);
144 
145  void read_integer(String& res);
146 
147  void read_numeric(String& res);
148 
149  void parse_integer(Index& n);
150 
151  void parse_numeric(Numeric& n);
152 
154 
155  void parse_intvector(ArrayOfIndex& res);
156 
157  void parse_numvector(Vector& res);
158 
159  void parse_matrix(Matrix& res);
160 
161  bool parse_numvector_from_string (Vector& res, String& str);
162 
164 
166 
168 
170 
172 
174 };
175 
176 #endif /* parser_h */
177 
ArtsParser::NamedArgument
Definition: parser.h:34
Matrix
The Matrix class.
Definition: matpackI.h:788
ArtsParser::eat_whitespace_from_string
void eat_whitespace_from_string(String &str, size_t &pos)
Eats whitespace from a String.
Definition: parser.cc:1840
ArtsParser::parse_method
void parse_method(Index &id, ArrayOfIndex &output, ArrayOfIndex &input, Agenda &tasks, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, String &include_file, bool no_eot=false)
Parse the Contents of text as ARTS control input.
Definition: parser.cc:546
ArtsParser::read_integer
void read_integer(String &res)
Reads an integer.
Definition: parser.cc:2098
ArtsParser::is_whitespace
bool is_whitespace(const char c)
Returns true if this character is considered whitespace.
Definition: parser.cc:1779
ArtsParser::NamedArgument::column
Index column
Definition: parser.h:37
ArtsParser::mcfile
String mcfile
Definition: parser.h:167
ArtsParser::eat_whitespace
void eat_whitespace()
Eats whitespace.
Definition: parser.cc:1804
ArtsParser::parse_matrix
void parse_matrix(Matrix &res)
Read a Matrix.
Definition: parser.cc:2457
ArtsParser::read_name
void read_name(String &name)
Reads name of method, keyword, or workspace variable.
Definition: parser.cc:1858
ArtsParser::parse_generic_output
void parse_generic_output(const MdRecord *&mdd, Index &id, String &methodname, ArrayOfIndex &output, bool &first, bool &still_supergeneric, String &supergeneric_args, Index &supergeneric_index, NamedArguments &named_args, bool call_by_name)
Parse the generic output WSVs for current method from the controlfile.
Definition: parser.cc:1242
ArtsParser::msource
SourceText msource
Definition: parser.h:169
ArtsParser::assertain_character
void assertain_character(char c)
Make sure that the current character is equal to c and go to the next character.
Definition: parser.cc:2024
Agenda
The Agenda class.
Definition: agenda_class.h:44
ArtsParser::parse_intvector
void parse_intvector(ArrayOfIndex &res)
Read a vector of integers.
Definition: parser.cc:2356
Array< Index >
ArtsParser::verbosity
const Verbosity & verbosity
Definition: parser.h:173
agenda_class.h
Declarations for agendas.
ArtsParser::at_end_of_argument
void at_end_of_argument(const String &argname)
Check if current position in controlfile is at the end of an argument.
Definition: parser.cc:169
ArtsParser::find_named_arguments
void find_named_arguments(vector< NamedArgument > &named_args)
Find named arguments.
Definition: parser.cc:62
ArtsParser::set_gin_to_default
String set_gin_to_default(const MdRecord *mdd, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, Index keyword_index)
Set generic input to default value.
Definition: parser.cc:667
ArtsParser::get_argument_index_by_name
void get_argument_index_by_name(Index &arg_index, NamedArguments &named_args, String name)
Return the index of the argument with the given name.
Definition: parser.cc:188
ArtsParser::parse_numvector_from_string
bool parse_numvector_from_string(Vector &res, String &str)
Read a vector of Numerics from a String.
Definition: parser.cc:2565
ArtsParser::parse_Stringvector
void parse_Stringvector(ArrayOfString &res)
Read a vector of Strings.
Definition: parser.cc:2311
ArtsParser::parse_stringarray_from_string
bool parse_stringarray_from_string(ArrayOfString &res, String &str)
Read an Array of Strings from a String.
Definition: parser.cc:2634
my_basic_string< char >
ArtsParser::parse_agenda
void parse_agenda(Agenda &tasklist)
Parse the Contents of text as ARTS control input.
Definition: parser.cc:374
ArtsParser::parse_method_args
void parse_method_args(const MdRecord *&mdd, Index &id, String &methodname, ArrayOfIndex &output, ArrayOfIndex &input, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values)
Parse method's argument list.
Definition: parser.cc:810
ArtsParser::parse_specific_output
void parse_specific_output(const MdRecord *mdd, ArrayOfIndex &output, bool &first, NamedArguments &named_args, bool call_by_name)
Parse the output WSVs for current method from the controlfile.
Definition: parser.cc:1576
ArtsParser::NamedArgument::name
String name
Definition: parser.h:35
ArtsParser::parse_tasklist
void parse_tasklist()
Public interface to the main function of the parser.
Definition: parser.cc:48
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
Verbosity
Definition: messages.h:50
ArtsParser::read_numeric
void read_numeric(String &res)
Reads a floating point number.
Definition: parser.cc:2160
SourceText
A smart class to hold the text for parsing.
Definition: sourcetext.h:37
ArtsParser::mtasklist
Agenda & mtasklist
Definition: parser.h:165
ArtsParser::read_name_or_value
Index read_name_or_value(String &name, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, const String &default_name, const MdRecord *mdd, const Index group)
Reads name of a workspace variable or a value.
Definition: parser.cc:1912
ArtsParser::ArtsParser
ArtsParser(Agenda &tasklist, String controlfile, const Verbosity &verbosity)
Constructs a new parser.
Definition: parser.cc:37
MdRecord
All information for one workspace method.
Definition: methods.h:42
ArtsParser
Definition: parser.h:27
ArtsParser::parse_numeric
void parse_numeric(Numeric &n)
Use a String stream to parse a floating point number.
Definition: parser.cc:2288
ArtsParser::parse_main
void parse_main()
The main function of the parser.
Definition: parser.cc:207
ArtsParser::parse_numvector
void parse_numvector(Vector &res)
Read a vector of Numerics.
Definition: parser.cc:2401
ArtsParser::parse_integer
void parse_integer(Index &n)
Use a String stream to parse an integer number.
Definition: parser.cc:2275
ArtsParser::parse_generic_input
void parse_generic_input(const MdRecord *&mdd, Index &id, String &methodname, ArrayOfIndex &input, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, bool &first, bool &still_supergeneric, String &supergeneric_args, Index &supergeneric_index, NamedArguments &named_args, bool call_by_name)
Parse the generic input WSVs for current method from the controlfile.
Definition: parser.cc:1034
ArtsParser::parse_specific_input
void parse_specific_input(const MdRecord *mdd, ArrayOfIndex &input, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, bool &first, NamedArguments &named_args, bool call_by_name)
Parse the specific input WSVs for current method from the controlfile.
Definition: parser.cc:1470
sourcetext.h
ArtsParser::mcfile_version
Index mcfile_version
Definition: parser.h:171
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
ArtsParser::NamedArguments
vector< NamedArgument > NamedArguments
Definition: parser.h:40
ArtsParser::parse_String
void parse_String(String &res)
Reads a String, complete with quotation marks.
Definition: parser.cc:2050
Vector
The Vector class.
Definition: matpackI.h:556
ArtsParser::skip_to_next_argument
void skip_to_next_argument()
Skips forward to the next argument.
Definition: parser.cc:99
methods.h
Declaration of the class MdRecord.
ArtsParser::NamedArgument::line
Index line
Definition: parser.h:36
ArtsParser::tasklist_insert_set_delete
void tasklist_insert_set_delete(const ArrayOfIndex &auto_vars, const Array< TokVal > &auto_vars_values, const Index method_type, Agenda &tasklist)
Insert Set and Delete methods for automatically allocated output WSVs.
Definition: parser.cc:1705