KiCad PCB EDA Suite
ALTIUM_RULE_TOKENIZER Class Reference

#include <altium_rule_transformer.h>

Public Member Functions

 ALTIUM_RULE_TOKENIZER (const wxString &aExpr)
 
const ALTIUM_RULE_TOKENNext ()
 
const ALTIUM_RULE_TOKENPeek () const
 

Private Member Functions

wxUniChar curChar ()
 
wxUniChar nextChar ()
 

Private Attributes

size_t m_pos
 
const wxString m_expr
 
wxString::const_iterator m_it
 
ALTIUM_RULE_TOKEN m_currentToken
 
ALTIUM_RULE_TOKEN m_nextToken
 

Detailed Description

Definition at line 109 of file altium_rule_transformer.h.

Constructor & Destructor Documentation

◆ ALTIUM_RULE_TOKENIZER()

ALTIUM_RULE_TOKENIZER::ALTIUM_RULE_TOKENIZER ( const wxString &  aExpr)
inline

Definition at line 112 of file altium_rule_transformer.h.

112 : m_pos( 0 ), m_expr( aExpr )
113 {
114 m_it = m_expr.begin();
115 Next();
116 }
const ALTIUM_RULE_TOKEN & Next()
wxString::const_iterator m_it

References m_expr, m_it, and Next().

Member Function Documentation

◆ curChar()

wxUniChar ALTIUM_RULE_TOKENIZER::curChar ( )
inlineprivate

Definition at line 123 of file altium_rule_transformer.h.

123{ return *m_it; }

References m_it.

Referenced by Next().

◆ Next()

const ALTIUM_RULE_TOKEN & ALTIUM_RULE_TOKENIZER::Next ( )

Definition at line 30 of file altium_rule_transformer.cpp.

31{
33
34 // skip whitespaces
35 for( ; m_it != m_expr.end() && wxIsspace( curChar() ); nextChar() )
36 ;
37
38 // check for end of string
39 if( m_it == m_expr.end() )
40 {
42 return m_currentToken;
43 }
44
45 const size_t startPos = m_pos;
46 const wxUniChar curCh = curChar();
47 wxUniChar nextCh = nextChar();
48
49 if( curCh == '(' )
50 {
52 return m_currentToken;
53 }
54 else if( curCh == ')' )
55 {
57 return m_currentToken;
58 }
59 else if( curCh == '*' )
60 {
62 return m_currentToken;
63 }
64 else if( curCh == '/' )
65 {
67 return m_currentToken;
68 }
69 else if( curCh == '=' )
70 {
72 return m_currentToken;
73 }
74 else if( curCh == '<' )
75 {
76 if( nextCh == '=' )
77 {
78 nextChar();
80 }
81 else if( nextCh == '>' )
82 {
83 nextChar();
85 }
86 else
87 {
89 }
90 return m_currentToken;
91 }
92 else if( curCh == '>' )
93 {
94 if( nextCh == '=' )
95 {
96 nextChar();
98 }
99 else
100 {
102 }
103 return m_currentToken;
104 }
105 else if( curCh == '&' && nextCh == '&' )
106 {
107 nextChar();
109 return m_currentToken;
110 }
111 else if( curCh == '|' && nextCh == '|' )
112 {
113 nextChar();
115 return m_currentToken;
116 }
117 else if( curCh == '\'' )
118 {
119 std::cout << "start const string" << std::endl;
120 wxString constString;
121 while( m_it != m_expr.end() && nextCh != '\'' )
122 {
123 constString += nextCh; // TODO: escaping?
124 nextCh = nextChar();
125 }
126 std::cout << "end const string: " << constString << std::endl;
127
128 if( m_it != m_expr.end() )
129 {
130 nextChar(); // TODO: exception if EOF reached?
131 }
132
133 m_nextToken = { ALTIUM_RULE_TOKEN_KIND::CONST_STRING, startPos, constString };
134 return m_currentToken;
135 }
136 else if( curCh == '+' && !wxIsdigit( nextCh ) )
137 {
139 return m_currentToken;
140 }
141 else if( curCh == '-' && !wxIsdigit( nextCh ) )
142 {
144 return m_currentToken;
145 }
146 else if( curCh == '+' || curCh == '-' || wxIsdigit( curCh ) )
147 {
148 wxString digitString = curCh;
149 while( wxIsdigit( nextCh ) )
150 {
151 digitString += nextCh;
152 nextCh = nextChar();
153 }
154
155 long value;
156 digitString.ToLong( &value ); // TODO: check return value
157
158 m_nextToken = { ALTIUM_RULE_TOKEN_KIND::CONST_INT, startPos, value };
159 return m_currentToken;
160 }
161 else
162 {
163 wxString identString = curCh;
164 while( wxIsalnum( nextCh ) )
165 {
166 identString += nextCh;
167 nextCh = nextChar();
168 }
169
170 if( identString.IsSameAs( wxT( "True" ), false ) )
171 {
173 }
174 else if( identString.IsSameAs( wxT( "False" ), false ) )
175 {
177 }
178 else if( identString.IsSameAs( wxT( "Div" ), false ) )
179 {
181 }
182 else if( identString.IsSameAs( wxT( "Mod" ), false ) )
183 {
185 }
186 else if( identString.IsSameAs( wxT( "And" ), false ) )
187 {
189 }
190 else if( identString.IsSameAs( wxT( "Or" ), false ) )
191 {
193 }
194 else if( identString.IsSameAs( wxT( "Xor" ), false ) )
195 {
197 }
198 else if( identString.IsSameAs( wxT( "Not" ), false ) )
199 {
201 }
202 else if( identString.IsSameAs( wxT( "Between" ), false ) )
203 {
205 }
206 else if( identString.IsSameAs( wxT( "Like" ), false ) )
207 {
209 }
210 else
211 {
212 m_nextToken = { ALTIUM_RULE_TOKEN_KIND::IDENT, startPos, identString };
213 }
214
215 return m_currentToken;
216 }
217}
ALTIUM_RULE_TOKEN m_currentToken

References ADD, AND, BETWEEN, CONST_FALSE, CONST_INT, CONST_STRING, CONST_TRUE, curChar(), DIV, END_OF_EXPR, EQUAL, GREATER, GREATER_EQUAL, IDENT, INTEGRAL_DIV, LESS, LESS_EQUAL, LIKE, LOW_AND, LOW_OR, LPAR, m_currentToken, m_expr, m_it, m_nextToken, m_pos, MOD, MUL, nextChar(), NOT, NOT_EQUAL, OR, RPAR, SUB, and XOR.

Referenced by ALTIUM_RULE_TOKENIZER(), and BOOST_AUTO_TEST_CASE().

◆ nextChar()

wxUniChar ALTIUM_RULE_TOKENIZER::nextChar ( )
inlineprivate

Definition at line 125 of file altium_rule_transformer.h.

126 {
127 if( m_it != m_expr.end() )
128 {
129 m_it++;
130 m_pos++;
131
132 if( m_it != m_expr.end() )
133 return *( m_it );
134 }
135
136 return wxUniChar();
137 }

References m_expr, m_it, and m_pos.

Referenced by Next().

◆ Peek()

const ALTIUM_RULE_TOKEN & ALTIUM_RULE_TOKENIZER::Peek ( ) const

Definition at line 219 of file altium_rule_transformer.cpp.

220{
221 return m_nextToken;
222}

References m_nextToken.

Referenced by BOOST_AUTO_TEST_CASE().

Member Data Documentation

◆ m_currentToken

ALTIUM_RULE_TOKEN ALTIUM_RULE_TOKENIZER::m_currentToken
private

Definition at line 143 of file altium_rule_transformer.h.

Referenced by Next().

◆ m_expr

const wxString ALTIUM_RULE_TOKENIZER::m_expr
private

Definition at line 140 of file altium_rule_transformer.h.

Referenced by ALTIUM_RULE_TOKENIZER(), Next(), and nextChar().

◆ m_it

wxString::const_iterator ALTIUM_RULE_TOKENIZER::m_it
private

Definition at line 141 of file altium_rule_transformer.h.

Referenced by ALTIUM_RULE_TOKENIZER(), curChar(), Next(), and nextChar().

◆ m_nextToken

ALTIUM_RULE_TOKEN ALTIUM_RULE_TOKENIZER::m_nextToken
private

Definition at line 144 of file altium_rule_transformer.h.

Referenced by Next(), and Peek().

◆ m_pos

size_t ALTIUM_RULE_TOKENIZER::m_pos
private

Definition at line 139 of file altium_rule_transformer.h.

Referenced by Next(), and nextChar().


The documentation for this class was generated from the following files: