KiCad PCB EDA Suite
Loading...
Searching...
No Matches
altium_rule_transformer.cpp
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 (C) 2021 Thomas Pointhuber <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22
23#include <iostream>
24#include <wx/wxcrt.h> // for wxIsspace
25
27{
29
30 // skip whitespaces
31 for( ; m_it != m_expr.end() && wxIsspace( curChar() ); nextChar() )
32 ;
33
34 // check for end of string
35 if( m_it == m_expr.end() )
36 {
38 return m_currentToken;
39 }
40
41 const size_t startPos = m_pos;
42 const wxUniChar curCh = curChar();
43 wxUniChar nextCh = nextChar();
44
45 if( curCh == '(' )
46 {
48 return m_currentToken;
49 }
50 else if( curCh == ')' )
51 {
53 return m_currentToken;
54 }
55 else if( curCh == '*' )
56 {
58 return m_currentToken;
59 }
60 else if( curCh == '/' )
61 {
63 return m_currentToken;
64 }
65 else if( curCh == '=' )
66 {
68 return m_currentToken;
69 }
70 else if( curCh == '<' )
71 {
72 if( nextCh == '=' )
73 {
74 nextChar();
76 }
77 else if( nextCh == '>' )
78 {
79 nextChar();
81 }
82 else
83 {
85 }
86 return m_currentToken;
87 }
88 else if( curCh == '>' )
89 {
90 if( nextCh == '=' )
91 {
92 nextChar();
94 }
95 else
96 {
98 }
99 return m_currentToken;
100 }
101 else if( curCh == '&' && nextCh == '&' )
102 {
103 nextChar();
105 return m_currentToken;
106 }
107 else if( curCh == '|' && nextCh == '|' )
108 {
109 nextChar();
111 return m_currentToken;
112 }
113 else if( curCh == '\'' )
114 {
115 wxString constString;
116 while( m_it != m_expr.end() && nextCh != '\'' )
117 {
118 constString += nextCh; // TODO: escaping?
119 nextCh = nextChar();
120 }
121
122 if( m_it != m_expr.end() )
123 {
124 nextChar(); // TODO: exception if EOF reached?
125 }
126
127 m_nextToken = { ALTIUM_RULE_TOKEN_KIND::CONST_STRING, startPos, constString };
128 return m_currentToken;
129 }
130 else if( curCh == '+' && !wxIsdigit( nextCh ) )
131 {
133 return m_currentToken;
134 }
135 else if( curCh == '-' && !wxIsdigit( nextCh ) )
136 {
138 return m_currentToken;
139 }
140 else if( curCh == '+' || curCh == '-' || wxIsdigit( curCh ) )
141 {
142 wxString digitString = curCh;
143 while( wxIsdigit( nextCh ) )
144 {
145 digitString += nextCh;
146 nextCh = nextChar();
147 }
148
149 long value;
150 digitString.ToLong( &value ); // TODO: check return value
151
152 m_nextToken = { ALTIUM_RULE_TOKEN_KIND::CONST_INT, startPos, value };
153 return m_currentToken;
154 }
155 else
156 {
157 wxString identString = curCh;
158 while( wxIsalnum( nextCh ) )
159 {
160 identString += nextCh;
161 nextCh = nextChar();
162 }
163
164 if( identString.IsSameAs( wxT( "True" ), false ) )
165 {
167 }
168 else if( identString.IsSameAs( wxT( "False" ), false ) )
169 {
171 }
172 else if( identString.IsSameAs( wxT( "Div" ), false ) )
173 {
175 }
176 else if( identString.IsSameAs( wxT( "Mod" ), false ) )
177 {
179 }
180 else if( identString.IsSameAs( wxT( "And" ), false ) )
181 {
183 }
184 else if( identString.IsSameAs( wxT( "Or" ), false ) )
185 {
187 }
188 else if( identString.IsSameAs( wxT( "Xor" ), false ) )
189 {
191 }
192 else if( identString.IsSameAs( wxT( "Not" ), false ) )
193 {
195 }
196 else if( identString.IsSameAs( wxT( "Between" ), false ) )
197 {
199 }
200 else if( identString.IsSameAs( wxT( "Like" ), false ) )
201 {
203 }
204 else
205 {
206 m_nextToken = { ALTIUM_RULE_TOKEN_KIND::IDENT, startPos, identString };
207 }
208
209 return m_currentToken;
210 }
211}
212
214{
215 return m_nextToken;
216}
const ALTIUM_RULE_TOKEN & Peek() const
const ALTIUM_RULE_TOKEN & Next()
wxString::const_iterator m_it