3 * IPRT - Parser, Bourne-like Shell.
7 * Copyright (C) 2022-2024 Oracle and/or its affiliates.
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
37 #ifndef IPRT_INCLUDED_parseshell_h
38 #define IPRT_INCLUDED_parseshell_h
39 #ifndef RT_WITHOUT_PRAGMA_ONCE
43 #include <iprt/list.h>
47 /** @defgroup grp_rt_parse RTParse - Generic Parser
52 * IPRT parse node types.
54 typedef enum RTPARSENODETYPE
56 RTPARSENODETYPE_INVALID
= 0,
58 /** Single quoted (sub-)string. */
59 RTPARSENODETYPE_STRING_SQ
,
60 /** Double quoted (sub-)string. */
61 RTPARSENODETYPE_STRING_DQ
,
62 /** Unquoted string. */
63 RTPARSENODETYPE_STRING_UQ
,
70 * Type info for an IPRT parser node.
72 * This is for simplifying generic processing, dumping and such things. It may
73 * be extended with method pointers if deemed useful/sensible.
75 typedef struct RTPARSENODETYPEINFO
78 RTPARSENODETYPE enmType
;
79 /** Number of child pointers. */
83 /** Pointer to a list of child member names. */
84 const char * const *papszChild
;
85 } RTPARSENODETYPEINFO
;
86 /** Pointer (const) to type info for a parser node. */
87 typedef RTPARSENODETYPEINFO
const *PCRTPARSENODETYPEINFO
;
91 * Source location for an IPRT parser instance.
93 typedef struct RTPARSESRCLOC
95 /** The line number (0-based). */
96 RT_GCC_EXTENSION
uint64_t iLine
: 24;
97 /** The line offset (0-based). */
98 RT_GCC_EXTENSION
uint64_t offLine
: 24;
99 /** The file index (zero is invalid). */
100 RT_GCC_EXTENSION
uint64_t idxFile
: 16;
102 /** Pointer to a source location for an IPRT parser instance. */
103 typedef RTPARSESRCLOC
*PRTPARSESRCLOC
;
104 /** Pointer to a const source location for an IPRT parser instance. */
105 typedef RTPARSESRCLOC
const *PCRTPARSESRCLOC
;
108 /** Pointer to a parser base node. */
109 typedef struct RTPARSENODE RT_FAR
*PRTPARSENODE
;
110 /** Pointer to a const parser base node. */
111 typedef struct RTPARSENODE
const RT_FAR
*PCRTPARSENODE
;
113 * IPRT parser base node.
115 * All parse three nodes derive from this one.
117 * @note If there are children, their list anchors must all follow immediately
118 * after this structure.
120 typedef struct RTPARSENODE
122 /** The node type info. */
123 PCRTPARSENODETYPEINFO pType
;
124 /** Node type specific flags. */
126 /** User flags/whatever. */
128 /** Pointer to user specified data. */
130 /** Source location. */
131 RTPARSESRCLOC SrcLoc
;
132 /** The parent node. */
133 PRTPARSENODE pParent
;
134 /** The sibling list entry (PRTPARSENODE). */
135 RTLISTNODE ListEntry
;
139 typedef struct RTPARSENODEBODY
141 /** The common part. */
143 /** The children list (PRTPARSENODE). */
148 typedef struct RTPARSENODEBINARY
150 /** The common part. */
152 /** The first child (left side) (PRTPARSENODE). */
154 /** The second child (right side) (PRTPARSENODE). */
164 typedef struct RTPARSENODESTRING
166 /** The common part. */
168 /** Pointer to the string. */
170 /** String length. */
176 /** @defgroup grp_rt_parse_shell RTParseShell - Bourne-like Shell Parser
179 struct RTPARSESHELLINT
;
180 /** Handle to a bourne-like shell parser. */
181 typedef struct RTPARSESHELLINT
*RTPARSESHELL
;
182 /** Pointer to a bourne-like shell parser. */
183 typedef RTPARSESHELL
*PRTPARSESHELL
;
184 /** NIL handle to a bourne-like shell parser. */
185 #define NIL_RTPARSESHELL ((RTPARSESHELL)~(uintptr_t)0)
192 #endif /* !IPRT_INCLUDED_parseshell_h */