forked from fish-shell/fish-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_keywords.cpp
75 lines (60 loc) · 1.28 KB
/
parser_keywords.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/** \file parser_keywords.c
Functions having to do with parser keywords, like testing if a function is a block command.
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include "fallback.h"
#include "common.h"
#include "parser_keywords.h"
bool parser_keywords_is_switch( const wcstring &cmd )
{
if (cmd == L"--") {
return ARG_SKIP;
} else if (! cmd.empty() && cmd.at(0) == L'-') {
return ARG_SWITCH;
} else {
return ARG_NON_SWITCH;
}
}
bool parser_keywords_skip_arguments( const wcstring &cmd )
{
return contains( cmd,
L"else",
L"begin" );
}
bool parser_keywords_is_subcommand( const wcstring &cmd )
{
return parser_keywords_skip_arguments( cmd ) ||
contains( cmd,
L"command",
L"builtin",
L"while",
L"exec",
L"if",
L"and",
L"or",
L"not" );
}
bool parser_keywords_is_block( const wcstring &word)
{
return contains( word,
L"for",
L"while",
L"if",
L"function",
L"switch",
L"begin" );
}
bool parser_keywords_is_reserved( const wcstring &word)
{
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" );
}