1 /*
2 Copyright 2021 Northern.tech AS
3
4 This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; version 3.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18
19 To the extent this program is licensed as part of the Enterprise
20 versions of CFEngine, the applicable Commercial Open Source License
21 (COSL) may apply to this file if you as a licensee so wish it. See
22 included file COSL.txt.
23 */
24
25 // This header contains types and (inline) functions used
26 // when parsing policy. It is used in a few files related
27 // to parsing, for example cf3lex.l (flex generated lexer),
28 // cf3parse.y (yacc generated parser) and syntax.c
29 // It doesn't really contain the grammar, or syntax
30 // description just some helper functions, to enable those.
31 // The intention is to move a lot of logic (C code) out of
32 // the lex and yacc files to make them easier to understand
33 // and maintain.
34
35 // It could maybe be combined with parser_state.h, but
36 // there is a distinction, this file does not include anything
37 // about the state of the parser
38
39 #ifndef CF_PARSER_HELPERS_H
40 #define CF_PARSER_HELPERS_H
41
42 #include <condition_macros.h> // debug_abort_if_reached()
43
44 // Blocks are the top level elements of a policy file
45 // (excluding macros).
46
47 // Currently there are 3 types of blocks; bundle, body, promise
48 typedef enum
49 {
50 PARSER_BLOCK_BUNDLE = 1,
51 PARSER_BLOCK_BODY = 2,
52 PARSER_BLOCK_PROMISE = 3,
53 } ParserBlock;
54
ParserBlockString(ParserBlock b)55 static inline const char *ParserBlockString(ParserBlock b)
56 {
57 switch (b)
58 {
59 case PARSER_BLOCK_BUNDLE:
60 return "bundle";
61 case PARSER_BLOCK_BODY:
62 return "body";
63 case PARSER_BLOCK_PROMISE:
64 return "promise";
65 default:
66 break;
67 }
68 debug_abort_if_reached();
69 return "ERROR";
70 }
71
72 #endif // CF_PARSER_HELPERS_H
73