2014-02-28 10:15:24 +00:00
|
|
|
/** \file parser_keywords.c
|
2007-04-22 09:50:26 +00:00
|
|
|
|
2007-08-01 17:38:01 +00:00
|
|
|
Functions having to do with parser keywords, like testing if a function is a block command.
|
2007-04-22 09:50:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "fallback.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "parser_keywords.h"
|
|
|
|
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
bool parser_keywords_is_switch(const wcstring &cmd)
|
2007-04-22 09:50:26 +00:00
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
if (cmd == L"--")
|
|
|
|
{
|
|
|
|
return ARG_SKIP;
|
|
|
|
}
|
|
|
|
else if (! cmd.empty() && cmd.at(0) == L'-')
|
|
|
|
{
|
2012-05-07 19:55:13 +00:00
|
|
|
return ARG_SWITCH;
|
2012-11-19 00:30:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-07 19:55:13 +00:00
|
|
|
return ARG_NON_SWITCH;
|
|
|
|
}
|
2007-04-22 09:50:26 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
bool parser_keywords_skip_arguments(const wcstring &cmd)
|
2007-04-22 09:50:26 +00:00
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
return contains(cmd,
|
|
|
|
L"else",
|
|
|
|
L"begin");
|
2007-04-22 09:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
bool parser_keywords_is_subcommand(const wcstring &cmd)
|
2007-04-22 09:50:26 +00:00
|
|
|
{
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
return parser_keywords_skip_arguments(cmd) ||
|
|
|
|
contains(cmd,
|
|
|
|
L"command",
|
|
|
|
L"builtin",
|
|
|
|
L"while",
|
|
|
|
L"exec",
|
|
|
|
L"if",
|
|
|
|
L"and",
|
|
|
|
L"or",
|
|
|
|
L"not");
|
2012-11-18 10:23:22 +00:00
|
|
|
|
2007-04-22 09:50:26 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
bool parser_keywords_is_block(const wcstring &word)
|
2007-04-22 09:50:26 +00:00
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
return contains(word,
|
|
|
|
L"for",
|
|
|
|
L"while",
|
|
|
|
L"if",
|
|
|
|
L"function",
|
|
|
|
L"switch",
|
|
|
|
L"begin");
|
2007-04-22 09:50:26 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
bool parser_keywords_is_reserved(const wcstring &word)
|
2007-04-22 09:50:26 +00:00
|
|
|
{
|
2012-11-19 00:30:30 +00:00
|
|
|
return parser_keywords_is_block(word) ||
|
|
|
|
parser_keywords_is_subcommand(word) ||
|
|
|
|
contains(word,
|
|
|
|
L"end",
|
|
|
|
L"case",
|
|
|
|
L"else",
|
|
|
|
L"return",
|
|
|
|
L"continue",
|
|
|
|
L"break");
|
2007-04-22 09:50:26 +00:00
|
|
|
}
|
|
|
|
|