ARTS  2.4.0(git:4fb77825)
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 "methods.h"
24 #include "sourcetext.h"
25 
26 class ArtsParser {
27  public:
28  ArtsParser(Agenda& tasklist, String controlfile, const Verbosity& verbosity);
29 
30  void parse_tasklist();
31 
32  private:
33  typedef struct {
37  } NamedArgument;
38 
39  typedef vector<NamedArgument> NamedArguments;
40 
41  void find_named_arguments(vector<NamedArgument>& named_args);
42 
43  void skip_to_next_argument();
44 
45  void at_end_of_argument(const String& argname);
46 
47  void get_argument_index_by_name(Index& arg_index,
48  NamedArguments& named_args,
49  String name);
50 
51  void parse_main();
52 
53  void parse_agenda(Agenda& tasklist, const String& agenda_name);
54 
55  void parse_method(Index& id,
56  ArrayOfIndex& output,
57  ArrayOfIndex& input,
58  Agenda& tasks,
59  ArrayOfIndex& auto_vars,
60  Array<TokVal>& auto_vars_values,
61  String& include_file,
62  bool no_eot = false);
63 
64  void parse_generic_input(const MdRecord*& mdd,
65  Index& id,
66  String& methodname,
67  ArrayOfIndex& input,
68  ArrayOfIndex& auto_vars,
69  Array<TokVal>& auto_vars_values,
70  bool& first,
71  bool& still_supergeneric,
72  String& supergeneric_args,
73  Index& supergeneric_index,
74  NamedArguments& named_args,
75  bool call_by_name);
76 
77  void parse_generic_output(const MdRecord*& mdd,
78  Index& id,
79  String& methodname,
80  ArrayOfIndex& output,
81  bool& first,
82  bool& still_supergeneric,
83  String& supergeneric_args,
84  Index& supergeneric_index,
85  NamedArguments& named_args,
86  bool call_by_name);
87 
88  void parse_specific_input(const MdRecord* mdd,
89  ArrayOfIndex& input,
90  ArrayOfIndex& auto_vars,
91  Array<TokVal>& auto_vars_values,
92  bool& first,
93  NamedArguments& named_args,
94  bool call_by_name);
95 
96  void parse_specific_output(const MdRecord* mdd,
97  ArrayOfIndex& output,
98  bool& first,
99  NamedArguments& named_args,
100  bool call_by_name);
101 
102  void parse_method_args(const MdRecord*& mdd,
103  Index& id,
104  String& methodname,
105  ArrayOfIndex& output,
106  ArrayOfIndex& input,
107  ArrayOfIndex& auto_vars,
108  Array<TokVal>& auto_vars_values);
109 
111  ArrayOfIndex& auto_vars,
112  Array<TokVal>& auto_vars_values,
113  Index keyword_index);
114 
115  void tasklist_insert_set_delete(const ArrayOfIndex& auto_vars,
116  const Array<TokVal>& auto_vars_values,
117  const Index method_type,
118  Agenda& tasklist);
119 
120  bool is_whitespace(const char c);
121 
122  void eat_whitespace();
123 
124  void eat_whitespace_from_string(String& str, size_t& pos);
125 
126  void read_name(String& name);
127 
129  ArrayOfIndex& auto_vars,
130  Array<TokVal>& auto_vars_values,
131  const String& default_name,
132  const MdRecord* mdd,
133  const Index group);
134 
135  void assertain_character(char c);
136 
137  void parse_String(String& res);
138 
139  void read_integer(String& res);
140 
141  void read_numeric(String& res);
142 
143  void parse_integer(Index& n);
144 
145  void parse_numeric(Numeric& n);
146 
148 
149  void parse_intvector(ArrayOfIndex& res);
150 
151  void parse_numvector(Vector& res);
152 
153  void parse_matrix(Matrix& res);
154 
156 
157  bool parse_numvector_from_string(Vector& res, String& str);
158 
160 
162 
164 
166 
168 
170 };
171 
172 #endif /* parser_h */
ArtsParser::NamedArgument
Definition: parser.h:33
Matrix
The Matrix class.
Definition: matpackI.h:1193
ArtsParser::eat_whitespace_from_string
void eat_whitespace_from_string(String &str, size_t &pos)
Eats whitespace from a String.
Definition: parser.cc:1694
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:496
ArtsParser::read_integer
void read_integer(String &res)
Reads an integer.
Definition: parser.cc:1901
ArtsParser::is_whitespace
bool is_whitespace(const char c)
Returns true if this character is considered whitespace.
Definition: parser.cc:1643
ArtsParser::NamedArgument::column
Index column
Definition: parser.h:36
ArtsParser::mcfile
String mcfile
Definition: parser.h:163
ArtsParser::eat_whitespace
void eat_whitespace()
Eats whitespace.
Definition: parser.cc:1665
ArtsParser::parse_matrix
void parse_matrix(Matrix &res)
Read a Matrix.
Definition: parser.cc:2217
ArtsParser::read_name
void read_name(String &name)
Reads name of method, keyword, or workspace variable.
Definition: parser.cc:1709
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:1163
ArtsParser::msource
SourceText msource
Definition: parser.h:165
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:1838
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:2125
Array< Index >
ArtsParser::verbosity
const Verbosity & verbosity
Definition: parser.h:169
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:154
ArtsParser::find_named_arguments
void find_named_arguments(vector< NamedArgument > &named_args)
Find named arguments.
Definition: parser.cc:60
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:603
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:169
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:2370
ArtsParser::parse_Stringvector
void parse_Stringvector(ArrayOfString &res)
Read a vector of Strings.
Definition: parser.cc:2084
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:2437
my_basic_string< char >
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:746
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:1458
ArtsParser::NamedArgument::name
String name
Definition: parser.h:34
ArtsParser::parse_tasklist
void parse_tasklist()
Public interface to the main function of the parser.
Definition: parser.cc:50
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Verbosity
Definition: messages.h:49
ArtsParser::parse_intvector_from_string
bool parse_intvector_from_string(ArrayOfIndex &res, String &str)
Read an array of integers from a String.
Definition: parser.cc:2308
ArtsParser::read_numeric
void read_numeric(String &res)
Reads a floating point number.
Definition: parser.cc:1953
SourceText
A smart class to hold the text for parsing.
Definition: sourcetext.h:36
ArtsParser::mtasklist
Agenda & mtasklist
Definition: parser.h:161
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:1754
ArtsParser::ArtsParser
ArtsParser(Agenda &tasklist, String controlfile, const Verbosity &verbosity)
Constructs a new parser.
Definition: parser.cc:36
MdRecord
All information for one workspace method.
Definition: methods.h:41
ArtsParser
Definition: parser.h:26
ArtsParser::parse_numeric
void parse_numeric(Numeric &n)
Use a String stream to parse a floating point number.
Definition: parser.cc:2063
ArtsParser::parse_main
void parse_main()
The main function of the parser.
Definition: parser.cc:184
ArtsParser::parse_numvector
void parse_numvector(Vector &res)
Read a vector of Numerics.
Definition: parser.cc:2166
ArtsParser::parse_integer
void parse_integer(Index &n)
Use a String stream to parse an integer number.
Definition: parser.cc:2052
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:977
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:1358
ArtsParser::parse_agenda
void parse_agenda(Agenda &tasklist, const String &agenda_name)
Parse the Contents of text as ARTS control input.
Definition: parser.cc:333
sourcetext.h
ArtsParser::mcfile_version
Index mcfile_version
Definition: parser.h:167
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
ArtsParser::NamedArguments
vector< NamedArgument > NamedArguments
Definition: parser.h:39
ArtsParser::parse_String
void parse_String(String &res)
Reads a String, complete with quotation marks.
Definition: parser.cc:1859
Vector
The Vector class.
Definition: matpackI.h:860
ArtsParser::skip_to_next_argument
void skip_to_next_argument()
Skips forward to the next argument.
Definition: parser.cc:91
methods.h
Declaration of the class MdRecord.
ArtsParser::NamedArgument::line
Index line
Definition: parser.h:35
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:1567