forked from bminor/bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax.hh
157 lines (122 loc) · 4.85 KB
/
syntax.hh
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* syntax.h -- Syntax definitions for the shell */
/* Copyright (C) 2000, 2001, 2005, 2008, 2009-2020 Free Software Foundation,
Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SYNTAX_H_
#define _SYNTAX_H_
#include "bashtypes.hh"
namespace bash
{
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
/* Defines for use by mksyntax.c */
static const char *slashify_in_quotes = "\\`$\"\n";
static const char *slashify_in_here_document = "\\`$";
static const char *shell_meta_chars = "()<>;&|";
static const char *shell_break_chars = "()<>;&| \t\n";
static const char *shell_quote_chars = "\"`'";
#if defined(PROCESS_SUBSTITUTION)
static const char *shell_exp_chars = "$<>";
#else
static const char *shell_exp_chars = "$";
#endif
#if defined(EXTENDED_GLOB)
static const char *ext_glob_chars = "@*+?!";
#else
static const char *ext_glob_chars = "";
#endif
static const char *shell_glob_chars = "*?[]^";
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
/* Defines shared by mksyntax.cc and the rest of the shell code. */
/* Values for character flags in syntax tables */
enum char_flags
{
CWORD = 0x0000, /* nothing special; an ordinary character */
CSHMETA = 0x0001, /* shell meta character */
CSHBRK = 0x0002, /* shell break character */
CBACKQ = 0x0004, /* back quote */
CQUOTE = 0x0008, /* shell quote character */
CSPECL = 0x0010, /* special character that needs quoting */
CEXP = 0x0020, /* shell expansion character */
CBSDQUOTE = 0x0040, /* characters escaped by backslash in double quotes */
CBSHDOC = 0x0080, /* characters escaped by backslash in here doc */
CGLOB = 0x0100, /* globbing characters */
CXGLOB = 0x0200, /* extended globbing characters */
CXQUOTE = 0x0400, /* cquote + backslash */
CSPECVAR = 0x0800, /* single-character shell variable name */
CSUBSTOP = 0x1000, /* values of OP for ${word[:]OPstuff} */
CBLANK = 0x2000 /* whitespace (blank) character */
};
static inline char_flags &
operator|= (char_flags &a, const char_flags &b)
{
a = static_cast<char_flags> (static_cast<uint32_t> (a)
| static_cast<uint32_t> (b));
return a;
}
static inline char_flags
operator| (const char_flags &a, const char_flags &b)
{
return static_cast<char_flags> (static_cast<uint32_t> (a)
| static_cast<uint32_t> (b));
}
static inline char_flags &
operator&= (char_flags &a, const char_flags &b)
{
a = static_cast<char_flags> (static_cast<uint32_t> (a)
& static_cast<uint32_t> (b));
return a;
}
static inline char_flags
operator& (const char_flags &a, const char_flags &b)
{
return static_cast<char_flags> (static_cast<uint32_t> (a)
& static_cast<uint32_t> (b));
}
static inline char_flags
operator~(const char_flags &a)
{
return static_cast<char_flags> (~static_cast<uint32_t> (a));
}
#define shellmeta(c) (sh_syntaxtab[static_cast<unsigned char> (c)] & CSHMETA)
#define shellbreak(c) (sh_syntaxtab[static_cast<unsigned char> (c)] & CSHBRK)
#define shellquote(c) (sh_syntaxtab[static_cast<unsigned char> (c)] & CQUOTE)
#define shellxquote(c) (sh_syntaxtab[static_cast<unsigned char> (c)] & CXQUOTE)
#define shellblank(c) (sh_syntaxtab[static_cast<unsigned char> (c)] & CBLANK)
#define parserblank(c) ((c) == ' ' || (c) == '\t')
#define issyntype(c, t) \
((sh_syntaxtab[static_cast<unsigned char> (c)] & (t)) != 0)
#define notsyntype(c, t) \
((sh_syntaxtab[static_cast<unsigned char> (c)] & (t)) == 0)
#if defined(PROCESS_SUBSTITUTION)
#define shellexp(c) ((c) == '$' || (c) == '<' || (c) == '>')
#else
#define shellexp(c) ((c) == '$')
#endif
#if defined(EXTENDED_GLOB)
#define PATTERN_CHAR(c) \
((c) == '@' || (c) == '*' || (c) == '+' || (c) == '?' || (c) == '!')
#else
#define PATTERN_CHAR(c) 0
#endif
#define GLOB_CHAR(c) \
((c) == '*' || (c) == '?' || (c) == '[' || (c) == ']' || (c) == '^')
#define CTLESC '\001'
#define CTLNUL '\177'
} // namespace bash
#endif /* _SYNTAX_H_ */