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