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, you may find one here:
18
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19
* or you may search the http://www.gnu.org website for the version 2 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*/
23
#ifndef SIM_XSPCIE_PARSER_H_
24
#define SIM_XSPCIE_PARSER_H_
25
26
#include "
sim/sim_value.h
"
27
#include <pegtl.hpp>
28
#include <pegtl/eol.hpp>
29
#include <pegtl/rules.hpp>
30
31
namespace
SIM_XSPICE_PARSER_GRAMMAR
32
{
33
using namespace
SIM_VALUE_GRAMMAR
;
34
45
struct
nodeName
: one<'?'>
46
{
47
};
48
struct
squareBracketO
: one<'['>
49
{
50
};
51
struct
squareBracketC
: one<']'>
52
{
53
};
54
struct
invertionDigital
: one<'~'>
55
{
56
};
57
struct
sep
: opt<plus<sor<space,
58
one<'('>,
59
one<')'>>>>
60
{
61
};
62
63
struct
invertionSeparated
: seq<sep, invertionDigital, sep>
64
{
65
};
66
struct
portInversionDouble
: if_must<invertionSeparated, not_at<invertionSeparated>>
67
{
68
};
69
struct
portInversionVector
: if_must<portInversionDouble, not_at<squareBracketO>>
70
{
71
};
72
struct
portInversion
: if_must<portInversionVector, not_at<one<'%'>>>
73
{
74
};
75
76
struct
portModifiersSingleNames
: sor<istring<'v', 'n', 'a', 'm'>,
77
string<'v'>,
78
istring<'i'>,
79
istring<'g'>,
80
istring<'h'>,
81
istring<'d'>>
82
{
83
};
84
struct
portModifierDifferentialNames
85
: sor<istring<'v', 'd'>,
86
istring<'i', 'd'>,
87
istring<'g', 'd'>,
88
istring<'h', 'd'>>
89
{
90
};
91
92
struct
portModifierDigital
: seq<one<'%'>, sep, istring<'d'>>
93
{
94
};
95
struct
portModifiersSingle
: seq<one<'%'>, sep, portModifiersSingleNames>
96
{
97
};
98
struct
portModifiersDifferential
: seq<one<'%'>, sep, portModifierDifferentialNames>
99
{
100
};
101
struct
validPortTypes
102
: until<if_must<one<'%'>, sep,
103
sor<portModifierDifferentialNames,
104
portModifiersSingleNames,
105
istring<'d'>>>>
106
{
107
};
108
109
struct
nodeNameSeparated
: seq<sep, nodeName, sep>
110
{
111
};
112
struct
nodeDigital
113
: seq<sep, opt<portModifierDigital>, opt<portInversion>, rep_min<1, nodeNameSeparated>>
114
{
115
};
116
struct
nodeSingle
: seq<sep, if_must<portModifiersSingle, sep, rep_min<1, nodeNameSeparated>>>
117
{
118
};
119
struct
nodeDifferential
120
: seq<sep, if_must<portModifiersDifferential, sep, rep_min<2, nodeNameSeparated>>>
121
{
122
};
123
struct
nodeSequence
: sor<nodeDifferential,
124
nodeDigital,
125
nodeSingle>
126
{
127
};
128
129
struct
vectorPattern
: if_must<squareBracketO, until<squareBracketC, nodeSequence>>
130
{
131
};
132
struct
vectorExpr
: seq<opt<portModifierDigital>, opt<portModifiersDifferential>,
133
opt<portModifiersSingle>, sep, vectorPattern>
134
{
135
};
136
struct
nodeSequenceGrammar
: must<at<rep_min<0, validPortTypes>>, sep,
137
plus<sor<vectorExpr,
138
nodeSequence>>,
139
not_at<squareBracketC>>
140
{
141
};
142
143
template
<
typename
>
144
inline
constexpr
const
char
*
errorMessage
=
nullptr
;
145
template
<>
146
inline
constexpr
auto
errorMessage<plus<sor<vectorExpr, nodeSequence>
>> =
147
"Expected at least one '?', are all modifiers and vectors correct?"
;
148
template
<>
149
inline
constexpr
auto
errorMessage<until<squareBracketC, nodeSequence>
> =
150
"Vectors [ must be closed ] and not nested."
;
151
template
<>
152
inline
constexpr
auto
153
errorMessage
<sor<
portModifierDifferentialNames
,
portModifiersSingleNames
, istring<
'd'
>>> =
154
"Port type is invalid. '%%' needs to be followed by a valid name."
;
155
template
<>
156
inline
constexpr
auto
errorMessage<at<rep_min<0, validPortTypes>
>> =
""
;
157
template
<>
158
inline
constexpr
auto
errorMessage<rep_min<1, nodeNameSeparated>
> =
159
"Port type is invalid. '%%' needs to be followed by a valid name and a '?'."
;
160
template
<>
161
inline
constexpr
auto
errorMessage<not_at<invertionSeparated>
> =
"'~~' is not supported."
;
162
template
<>
163
inline
constexpr
auto
errorMessage
<not_at<one<
'%'
>>> =
164
"'~ %%d' not supported, consider changing to '%%d ~'."
;
165
template
<>
166
inline
constexpr
auto
errorMessage<rep_min<2, nodeNameSeparated>
> =
167
"Differential ports need two nodes, and '~' is not supported for those nodes. Also check "
168
"if port modifier name is valid."
;
169
template
<>
170
inline
constexpr
auto
errorMessage<not_at<squareBracketO>
> =
"'~[' not supported."
;
171
template
<>
172
inline
constexpr
auto
errorMessage<not_at<squareBracketC>
> =
173
"Vector is either empty, open or nested."
;
174
template
<>
175
inline
constexpr
auto
errorMessage<sep>
=
""
;
176
177
178
struct
error
179
{
180
template
<
typename
Rule>
181
static
constexpr
bool
raise_on_failure
=
false
;
182
template
<
typename
Rule>
183
static
constexpr
auto
message
=
errorMessage<Rule>
;
184
};
185
template
<
typename
Rule>
186
using
control
= must_if<error>::control<Rule>;
187
188
189
template
<
typename
Rule>
190
struct
spiceUnitSelector
: std::false_type
191
{
192
};
193
template
<>
194
struct
spiceUnitSelector
<
squareBracketO
> : std::true_type
195
{
196
};
197
template
<>
198
struct
spiceUnitSelector
<
portModifierDigital
> : std::true_type
199
{
200
};
201
template
<>
202
struct
spiceUnitSelector
<
portModifiersSingle
> : std::true_type
203
{
204
};
205
template
<>
206
struct
spiceUnitSelector
<
portModifiersDifferential
> : std::true_type
207
{
208
};
209
template
<>
210
struct
spiceUnitSelector
<
invertionDigital
> : std::true_type
211
{
212
};
213
template
<>
214
struct
spiceUnitSelector
<
squareBracketC
> : std::true_type
215
{
216
};
217
template
<>
218
struct
spiceUnitSelector
<
nodeName
> : std::true_type
219
{
220
};
221
222
}
// namespace SIM_XSPICE_PARSER_GRAMMAR
223
#endif
// SIM_XSPCIE_PARSER_H_
SIM_VALUE_GRAMMAR
Definition
sim_value.h:47
SIM_XSPICE_PARSER_GRAMMAR
Definition
sim_xspice_parser.h:32
SIM_XSPICE_PARSER_GRAMMAR::control
must_if< error >::control< Rule > control
Definition
sim_xspice_parser.h:186
SIM_XSPICE_PARSER_GRAMMAR::errorMessage
constexpr const char * errorMessage
Definition
sim_xspice_parser.h:144
sim_value.h
SIM_XSPICE_PARSER_GRAMMAR::error
Definition
sim_xspice_parser.h:179
SIM_XSPICE_PARSER_GRAMMAR::error::message
static constexpr auto message
Definition
sim_xspice_parser.h:183
SIM_XSPICE_PARSER_GRAMMAR::error::raise_on_failure
static constexpr bool raise_on_failure
Definition
sim_xspice_parser.h:181
SIM_XSPICE_PARSER_GRAMMAR::invertionDigital
Definition
sim_xspice_parser.h:55
SIM_XSPICE_PARSER_GRAMMAR::invertionSeparated
Definition
sim_xspice_parser.h:64
SIM_XSPICE_PARSER_GRAMMAR::nodeDifferential
Definition
sim_xspice_parser.h:121
SIM_XSPICE_PARSER_GRAMMAR::nodeDigital
Definition
sim_xspice_parser.h:114
SIM_XSPICE_PARSER_GRAMMAR::nodeNameSeparated
Definition
sim_xspice_parser.h:110
SIM_XSPICE_PARSER_GRAMMAR::nodeName
Notes: spaces are allowed everywhere in any number ~ can only be before ?
Definition
sim_xspice_parser.h:46
SIM_XSPICE_PARSER_GRAMMAR::nodeSequenceGrammar
Definition
sim_xspice_parser.h:140
SIM_XSPICE_PARSER_GRAMMAR::nodeSequence
Definition
sim_xspice_parser.h:126
SIM_XSPICE_PARSER_GRAMMAR::nodeSingle
Definition
sim_xspice_parser.h:117
SIM_XSPICE_PARSER_GRAMMAR::portInversionDouble
Definition
sim_xspice_parser.h:67
SIM_XSPICE_PARSER_GRAMMAR::portInversionVector
Definition
sim_xspice_parser.h:70
SIM_XSPICE_PARSER_GRAMMAR::portInversion
Definition
sim_xspice_parser.h:73
SIM_XSPICE_PARSER_GRAMMAR::portModifierDifferentialNames
Definition
sim_xspice_parser.h:89
SIM_XSPICE_PARSER_GRAMMAR::portModifierDigital
Definition
sim_xspice_parser.h:93
SIM_XSPICE_PARSER_GRAMMAR::portModifiersDifferential
Definition
sim_xspice_parser.h:99
SIM_XSPICE_PARSER_GRAMMAR::portModifiersSingleNames
Definition
sim_xspice_parser.h:82
SIM_XSPICE_PARSER_GRAMMAR::portModifiersSingle
Definition
sim_xspice_parser.h:96
SIM_XSPICE_PARSER_GRAMMAR::sep
Definition
sim_xspice_parser.h:60
SIM_XSPICE_PARSER_GRAMMAR::spiceUnitSelector
Definition
sim_xspice_parser.h:191
SIM_XSPICE_PARSER_GRAMMAR::squareBracketC
Definition
sim_xspice_parser.h:52
SIM_XSPICE_PARSER_GRAMMAR::squareBracketO
Definition
sim_xspice_parser.h:49
SIM_XSPICE_PARSER_GRAMMAR::validPortTypes
Definition
sim_xspice_parser.h:106
SIM_XSPICE_PARSER_GRAMMAR::vectorExpr
Definition
sim_xspice_parser.h:134
SIM_XSPICE_PARSER_GRAMMAR::vectorPattern
Definition
sim_xspice_parser.h:130
src
eeschema
sim
sim_xspice_parser.h
Generated on Sun Sep 21 2025 01:05:24 for KiCad PCB EDA Suite by
1.13.2