KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_xspice_parser.h
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18
*/
19
#ifndef SIM_XSPCIE_PARSER_H_
20
#define SIM_XSPCIE_PARSER_H_
21
22
#include "
sim/sim_value.h
"
23
#include <pegtl.hpp>
24
#include <pegtl/eol.hpp>
25
#include <pegtl/rules.hpp>
26
27
namespace
SIM_XSPICE_PARSER_GRAMMAR
28
{
29
using namespace
SIM_VALUE_GRAMMAR
;
30
41
struct
nodeName
: one<'?'>
42
{
43
};
44
struct
squareBracketO
: one<'['>
45
{
46
};
47
struct
squareBracketC
: one<']'>
48
{
49
};
50
struct
invertionDigital
: one<'~'>
51
{
52
};
53
struct
sep
: opt<plus<sor<space,
54
one<'('>,
55
one<')'>>>>
56
{
57
};
58
59
struct
invertionSeparated
: seq<sep, invertionDigital, sep>
60
{
61
};
62
struct
portInversionDouble
: if_must<invertionSeparated, not_at<invertionSeparated>>
63
{
64
};
65
struct
portInversionVector
: if_must<portInversionDouble, not_at<squareBracketO>>
66
{
67
};
68
struct
portInversion
: if_must<portInversionVector, not_at<one<'%'>>>
69
{
70
};
71
72
struct
portModifiersSingleNames
: sor<istring<'v', 'n', 'a', 'm'>,
73
string<'v'>,
74
istring<'i'>,
75
istring<'g'>,
76
istring<'h'>,
77
istring<'d'>>
78
{
79
};
80
struct
portModifierDifferentialNames
81
: sor<istring<'v', 'd'>,
82
istring<'i', 'd'>,
83
istring<'g', 'd'>,
84
istring<'h', 'd'>>
85
{
86
};
87
88
struct
portModifierDigital
: seq<one<'%'>, sep, istring<'d'>>
89
{
90
};
91
struct
portModifiersSingle
: seq<one<'%'>, sep, portModifiersSingleNames>
92
{
93
};
94
struct
portModifiersDifferential
: seq<one<'%'>, sep, portModifierDifferentialNames>
95
{
96
};
97
struct
validPortTypes
98
: until<if_must<one<'%'>, sep,
99
sor<portModifierDifferentialNames,
100
portModifiersSingleNames,
101
istring<'d'>>>>
102
{
103
};
104
105
struct
nodeNameSeparated
: seq<sep, nodeName, sep>
106
{
107
};
108
struct
nodeDigital
109
: seq<sep, opt<portModifierDigital>, opt<portInversion>, rep_min<1, nodeNameSeparated>>
110
{
111
};
112
struct
nodeSingle
: seq<sep, if_must<portModifiersSingle, sep, rep_min<1, nodeNameSeparated>>>
113
{
114
};
115
struct
nodeDifferential
116
: seq<sep, if_must<portModifiersDifferential, sep, rep_min<2, nodeNameSeparated>>>
117
{
118
};
119
struct
nodeSequence
: sor<nodeDifferential,
120
nodeDigital,
121
nodeSingle>
122
{
123
};
124
125
struct
vectorPattern
: if_must<squareBracketO, until<squareBracketC, nodeSequence>>
126
{
127
};
128
struct
vectorExpr
: seq<opt<portModifierDigital>, opt<portModifiersDifferential>,
129
opt<portModifiersSingle>, sep, vectorPattern>
130
{
131
};
132
struct
nodeSequenceGrammar
: must<at<rep_min<0, validPortTypes>>, sep,
133
plus<sor<vectorExpr,
134
nodeSequence>>,
135
not_at<squareBracketC>>
136
{
137
};
138
139
template
<
typename
>
140
inline
constexpr
const
char
*
errorMessage
=
nullptr
;
141
template
<>
142
inline
constexpr
auto
errorMessage<plus<sor<vectorExpr, nodeSequence>
>> =
143
"Expected at least one '?', are all modifiers and vectors correct?"
;
144
template
<>
145
inline
constexpr
auto
errorMessage<until<squareBracketC, nodeSequence>
> =
146
"Vectors [ must be closed ] and not nested."
;
147
template
<>
148
inline
constexpr
auto
149
errorMessage
<sor<
portModifierDifferentialNames
,
portModifiersSingleNames
, istring<
'd'
>>> =
150
"Port type is invalid. '%%' needs to be followed by a valid name."
;
151
template
<>
152
inline
constexpr
auto
errorMessage<at<rep_min<0, validPortTypes>
>> =
""
;
153
template
<>
154
inline
constexpr
auto
errorMessage<rep_min<1, nodeNameSeparated>
> =
155
"Port type is invalid. '%%' needs to be followed by a valid name and a '?'."
;
156
template
<>
157
inline
constexpr
auto
errorMessage<not_at<invertionSeparated>
> =
"'~~' is not supported."
;
158
template
<>
159
inline
constexpr
auto
errorMessage
<not_at<one<
'%'
>>> =
160
"'~ %%d' not supported, consider changing to '%%d ~'."
;
161
template
<>
162
inline
constexpr
auto
errorMessage<rep_min<2, nodeNameSeparated>
> =
163
"Differential ports need two nodes, and '~' is not supported for those nodes. Also check "
164
"if port modifier name is valid."
;
165
template
<>
166
inline
constexpr
auto
errorMessage<not_at<squareBracketO>
> =
"'~[' not supported."
;
167
template
<>
168
inline
constexpr
auto
errorMessage<not_at<squareBracketC>
> =
169
"Vector is either empty, open or nested."
;
170
template
<>
171
inline
constexpr
auto
errorMessage<sep>
=
""
;
172
173
174
struct
error
175
{
176
template
<
typename
Rule>
177
static
constexpr
bool
raise_on_failure
=
false
;
178
template
<
typename
Rule>
179
static
constexpr
auto
message
=
errorMessage<Rule>
;
180
};
181
template
<
typename
Rule>
182
using
control
= must_if<error>::control<Rule>;
183
184
185
template
<
typename
Rule>
186
struct
spiceUnitSelector
: std::false_type
187
{
188
};
189
template
<>
190
struct
spiceUnitSelector
<
squareBracketO
> : std::true_type
191
{
192
};
193
template
<>
194
struct
spiceUnitSelector
<
portModifierDigital
> : std::true_type
195
{
196
};
197
template
<>
198
struct
spiceUnitSelector
<
portModifiersSingle
> : std::true_type
199
{
200
};
201
template
<>
202
struct
spiceUnitSelector
<
portModifiersDifferential
> : std::true_type
203
{
204
};
205
template
<>
206
struct
spiceUnitSelector
<
invertionDigital
> : std::true_type
207
{
208
};
209
template
<>
210
struct
spiceUnitSelector
<
squareBracketC
> : std::true_type
211
{
212
};
213
template
<>
214
struct
spiceUnitSelector
<
nodeName
> : std::true_type
215
{
216
};
217
218
}
// namespace SIM_XSPICE_PARSER_GRAMMAR
219
#endif
// SIM_XSPCIE_PARSER_H_
SIM_VALUE_GRAMMAR
Definition
sim_value.h:43
SIM_XSPICE_PARSER_GRAMMAR
Definition
sim_xspice_parser.h:28
SIM_XSPICE_PARSER_GRAMMAR::control
must_if< error >::control< Rule > control
Definition
sim_xspice_parser.h:182
SIM_XSPICE_PARSER_GRAMMAR::errorMessage
constexpr const char * errorMessage
Definition
sim_xspice_parser.h:140
sim_value.h
SIM_XSPICE_PARSER_GRAMMAR::error
Definition
sim_xspice_parser.h:175
SIM_XSPICE_PARSER_GRAMMAR::error::message
static constexpr auto message
Definition
sim_xspice_parser.h:179
SIM_XSPICE_PARSER_GRAMMAR::error::raise_on_failure
static constexpr bool raise_on_failure
Definition
sim_xspice_parser.h:177
SIM_XSPICE_PARSER_GRAMMAR::invertionDigital
Definition
sim_xspice_parser.h:51
SIM_XSPICE_PARSER_GRAMMAR::invertionSeparated
Definition
sim_xspice_parser.h:60
SIM_XSPICE_PARSER_GRAMMAR::nodeDifferential
Definition
sim_xspice_parser.h:117
SIM_XSPICE_PARSER_GRAMMAR::nodeDigital
Definition
sim_xspice_parser.h:110
SIM_XSPICE_PARSER_GRAMMAR::nodeNameSeparated
Definition
sim_xspice_parser.h:106
SIM_XSPICE_PARSER_GRAMMAR::nodeName
Notes: spaces are allowed everywhere in any number ~ can only be before ?
Definition
sim_xspice_parser.h:42
SIM_XSPICE_PARSER_GRAMMAR::nodeSequenceGrammar
Definition
sim_xspice_parser.h:136
SIM_XSPICE_PARSER_GRAMMAR::nodeSequence
Definition
sim_xspice_parser.h:122
SIM_XSPICE_PARSER_GRAMMAR::nodeSingle
Definition
sim_xspice_parser.h:113
SIM_XSPICE_PARSER_GRAMMAR::portInversionDouble
Definition
sim_xspice_parser.h:63
SIM_XSPICE_PARSER_GRAMMAR::portInversionVector
Definition
sim_xspice_parser.h:66
SIM_XSPICE_PARSER_GRAMMAR::portInversion
Definition
sim_xspice_parser.h:69
SIM_XSPICE_PARSER_GRAMMAR::portModifierDifferentialNames
Definition
sim_xspice_parser.h:85
SIM_XSPICE_PARSER_GRAMMAR::portModifierDigital
Definition
sim_xspice_parser.h:89
SIM_XSPICE_PARSER_GRAMMAR::portModifiersDifferential
Definition
sim_xspice_parser.h:95
SIM_XSPICE_PARSER_GRAMMAR::portModifiersSingleNames
Definition
sim_xspice_parser.h:78
SIM_XSPICE_PARSER_GRAMMAR::portModifiersSingle
Definition
sim_xspice_parser.h:92
SIM_XSPICE_PARSER_GRAMMAR::sep
Definition
sim_xspice_parser.h:56
SIM_XSPICE_PARSER_GRAMMAR::spiceUnitSelector
Definition
sim_xspice_parser.h:187
SIM_XSPICE_PARSER_GRAMMAR::squareBracketC
Definition
sim_xspice_parser.h:48
SIM_XSPICE_PARSER_GRAMMAR::squareBracketO
Definition
sim_xspice_parser.h:45
SIM_XSPICE_PARSER_GRAMMAR::validPortTypes
Definition
sim_xspice_parser.h:102
SIM_XSPICE_PARSER_GRAMMAR::vectorExpr
Definition
sim_xspice_parser.h:130
SIM_XSPICE_PARSER_GRAMMAR::vectorPattern
Definition
sim_xspice_parser.h:126
src
eeschema
sim
sim_xspice_parser.h
Generated on Fri Jun 26 2026 00:05:36 for KiCad PCB EDA Suite by
1.13.2