89 reservedWords[
"OR"] =
TOK_OR;
101 input.push_back(line +
" ");
103 std::cout << input.size() <<
": " << line << std::endl;
107 inline void ArgLexer::nextLine()
120 pToken->end = pos + offset - 1;
121 pToken->lexeme = input[
line].substr(pos, offset);
125 String s = pToken->lexeme;
126 std::transform(s.begin(), s.end(), s.begin(),
128 std::map<String, ArgTokenType>::iterator it;
129 it = reservedWords.find(s);
130 if (it != reservedWords.end())
132 pToken->lexeme = it->first;
133 pToken->type = it->second;
143 pToken->lexeme =
"EOF";
146 void ArgLexer::checkVisibility()
148 while (input[
line][pos] ==
'+')
150 ++(pToken->visibility);
155 void ArgLexer::checkIndependent()
157 if (input[
line][pos]==
'*')
159 pToken->starred =
true;
167 pToken->visibility = 0;
168 pToken->starred =
false;
170 if (
line == input.size())
176 char c = input[
line][pos];
179 while (
line < input.size() && pos < input[
line].length() && isspace(c
183 if (c ==
'\0' || c ==
'\n' || pos == input[
line].
length())
189 if (
line == input.size())
191 else if (isalpha(c) || c ==
'_')
194 while (isalnum(c) || c ==
'_')
197 c = input[
line][pos + offset];
201 else if (isalnum(c) || (c ==
'-' && isdigit(input[
line][pos + 1])))
205 while (isdigit(input[
line][pos + offset]))
207 if (input[
line][pos + offset] ==
'.')
210 while (isdigit(input[
line][pos + offset]))
214 if (input[
line][pos + offset] ==
'e')
217 if (input[
line][pos + offset] !=
'+' && input[
line][pos + offset]
220 std::cerr <<
"ERROR: expected '+' or '-' " << std::endl
221 <<
"at line: " <<
line + 1 <<
" pos: " << offset + 1
226 while (isdigit(input[
line][pos + offset]))
246 if (input[
line][pos + offset] ==
'=')
248 pos = input[
line].find_first_not_of(
'=', pos + 1);
250 offset = input[
line].find_first_of(
'=', pos + 1);
275 if (input[
line][pos + offset] ==
'.' &&
276 input[
line][pos + offset + 1] ==
'.')
287 offset = input[
line].find_first_of(
"\n\r", pos);
293 if (input[
line][pos + offset] ==
'-')
296 c = input[
line][pos + offset];
297 if (isalpha(c) || c ==
'_')
299 while (isalnum(c) || c ==
'_')
303 c = input[
line][pos + offset];
308 std::cerr <<
"ERROR: Params should be of the form -ID or --ID" 317 offset = input[
line].find_first_of(
'"', pos + 1);
323 std::cerr <<
"ERROR: Unexpected character '" << c <<
"'" 324 << std::endl <<
"at line: " <<
line + 1 <<
" pos: " << pos
326 std::cerr <<
"WRONG LINE: " << input[
line] << std::endl;
353 this->parent = parent;
358 return pLexer->lookahead();
363 return pLexer->lookahead() ==
type;
368 return pLexer->currentToken();
382 if (currentToken() != NULL)
383 token = *currentToken();
400 comments.
addComment(token.lexeme, token.visibility);
408 std::cerr <<
">>> ERROR: " << msg << std::endl <<
" at line " 409 << token.line + 1 <<
" column " << token.start + 1 << std::endl;
415 token = *currentToken();
472 if (index == cmdArguments.size())
480 errors <<
"Not enough arguments, <" <<
name <<
"> has not default. ";
499 if (!
subParams[
i]->checkRequires(errors, prog))
510 errors << optionValue <<
" is not a valid option for <" <<
name <<
"> ";
611 std::cerr <<
"ERROR; on WHERE definition.\n Param '" <<
name 612 <<
"' not contains argument '" <<
token.
lexeme <<
"'" 644 bool previousList =
false;
645 bool previousDefault =
false;
655 error(
"A list <...> has found not at the end of argument list");
658 error(
"A non default argument was found before a default one");
660 previousList = arg->
isList;
708 errors <<
"Parameter " <<
name <<
" requires " <<
requires[
i] << std::endl;
722 errors <<
"Duplicated parameter: " <<
name <<
" (check alias)" << std::endl;
735 errors <<
"Parameter " <<
name <<
" doesn't take any argument, " 745 errors <<
" parameter: " <<
name << std::endl;
750 errors <<
"Too many arguments for parameter " <<
name << std::endl;
769 params.push_back(param);
779 for (
size_t i = 0;
i <
params.size(); ++
i)
815 exclusiveGroup = NULL;
851 if (map.find(name) != map.end())
859 if (exclusive.empty())
862 std::vector<ParamDef*> exclusive2;
863 for (
size_t i = 0;
i < exclusive.size(); ++
i)
864 if (exclusive[
i]->counter == 1)
865 exclusive2.push_back(exclusive[
i]);
866 if (exclusive2.size() > 1)
868 errors <<
"Parameters ";
869 for (
size_t i = 0; i < exclusive.size() - 1; ++
i)
870 errors << exclusive[i]->
name <<
" ";
871 errors <<
"and " << exclusive[exclusive.size()-1]->name <<
" are mutually exclusive (check alias)" << std::endl;
873 else if (exclusive2.empty() && exclusive[0]->notOptional)
875 errors <<
"You should provide parameter " << exclusive[0]->name;
876 for (
size_t i = 1; i < exclusive.size(); ++
i)
877 errors <<
" or " << exclusive[i]->
name;
885 std::vector<ParamDef*> exclusive;
892 for (
size_t j = 0;
j < section->
params.size(); ++
j)
896 param->
check(errors);
899 exclusive.push_back(param);
915 error((
String)
"The param '" + name +
"' is repeated.");
927 if (exclusiveGroup == NULL || param->
orBefore ==
false)
928 exclusiveGroup =
new std::vector<ParamDef*>();
929 exclusiveGroup->push_back(param);
942 for (
size_t j = 0;
j < section->
params.size(); ++
j)
954 std::stringstream errors;
962 if (argc > 1 && argv[1][0] !=
'-')
977 for (
int i = 1;
i < argc; ++
i)
980 if (argv[
i][0] ==
'-' && !isdigit(argv[
i][1]))
984 errors <<
"Unrecognized parameter: " << argv[
i] << std::endl;
992 else if (param != NULL)
1000 if (reportErrors && errors.str().length() > 0)
1012 section->
name = sectionName;
1013 section->
visible = visibility;
1021 if (paramDef == NULL)
1026 std::stringstream errors;
1027 size_t argIndex = 0;
1028 for (
size_t i = 0;
i < paramDef->
arguments.size(); ++
i)
1031 errors <<
" parameter: " << paramDef->
name << std::endl;
1042 if (argNumber < 0 || argNumber >= param->
cmdArguments.size())
Errors on command line parameters.
void addParamRequires(const String &name)
ArgTokenType type
Type of the token.
ArgTokenType lookahead() const
virtual bool consume(ArgTokenType type)
#define REPORT_ERROR(nerr, ErrormMsg)
std::vector< ParamDef * > * exclusiveGroup
ParamDef * findAndFillParam(const String ¶m)
bool acceptArguments(std::stringstream &errors, size_t &argIndex, std::vector< const char *> &cmdArguments)
This function will take an index and check if there are enougth arguments.
bool parseCommentList(CommentList &comments)
virtual void check(std::stringstream &errors)
void clear()
clear read arguments
ParamDef * findParam(const String ¶m)
Null pointer passed as parameter.
bool checkRequires(std::stringstream &errors, ProgramDef *prog)
SectionDef(ArgLexer *lexer, ASTNode *parent)
std::vector< SectionDef * > sections
static const char * typeString(ArgTokenType type)
std::vector< String > StringVector
void read(int argc, const char **argv, bool reportErrors=true)
Read and validate commmand line.
bool starred
Some special mark to tokens.
void addParamName(const String &name, ParamDef *param)
ASTNode(ArgLexer *lexer=NULL, ASTNode *parent=NULL)
void addParamDef(ParamDef *param)
Add a param to the section.
ArgToken * currentToken() const
if(fabs(c[*nmax+ *nmax *c_dim1])==0.e0)
Incorrect argument received.
ParamDef(ArgLexer *lexer, ASTNode *parent)
std::vector< ParamDef * > subParams
virtual void check(std::stringstream &errors)
__host__ __device__ float length(float2 v)
std::vector< const char * > cmdArguments
std::vector< ArgumentDef * > arguments
StringVector pendingRequires
This is for checking that requires names exists.
bool parseParamList(ArgTokenType startToken, ProgramDef *prog, StringVector ¶mList, bool addName)
void addOcurrence(std::map< String, int > &map, const String &name)
ArgToken * currentToken() const
struct _parameter * param
std::vector< ParamDef * > params
All params defined for the program.
void addParamExclusiveGroup(ParamDef *param)
void reportExclusiveErrors(std::stringstream &errors, std::vector< ParamDef *> &exclusive)
String formatString(const char *format,...)
bool containsArgument(const String &argName)
ArgumentDef(ArgLexer *lexer, ASTNode *parent)
const char * getParam(const char *paramName, size_t paramNumber=0)
int line
line where token was found
ArgumentDef * findArgument(const String &argName)
SectionDef * addSection(String sectionName, int visibility=0)
int counter
for count the number of times it appears in command line
void unexpectedToken(String msg="")
String nextToken(const String &str, size_t &i)
void addLine(const String &line)
String lexeme
the string literal value of the token
ArgTokenType lookahead() const
std::map< String, ParamDef * > paramsMap
Dictionary with all params and alias names.
bool containsAlias(const String &alias)