1 ///////////////////////////////////////////////////////////////////////////
6 // Copyright: H.Saido, portions by Tim Gerundt, Stcherbatchenko Andrei
7 // E-mail: saido.nv@gmail.com
9 // VHDL syntax highlighing definition
11 // You are free to use or modify this code to the following restrictions:
12 // - Acknowledge me somewhere in your about box, simple "Parts of code by.."
13 // will be enough. If you can't (or don't want to), contact me personally.
14 // - LEAVE THIS HEADER INTACT
15 ////////////////////////////////////////////////////////////////////////////
18 #include "crystallineparser.h"
19 #include "../SyntaxColors.h"
20 #include "../utils/string_util.h"
27 static LPCTSTR s_apszVhdlKeywordList[] =
115 static LPCTSTR s_apszVhdlAttributeList[] =
122 _T ("'driving_value"),
126 _T ("'instance_name"),
139 _T ("'reverse_range"),
151 static LPCTSTR s_apszVhdlTypeList[] =
173 _T ("std_logic_vector"),
175 _T ("std_ulogic_vector"),
185 static LPCTSTR s_apszVhdlFunctionList[] =
189 _T ("conv_std_logic_vector"),
190 _T ("conv_unsigned"),
202 _T ("to_stdlogicvector"),
204 _T ("to_stdulogicvector"),
211 IsVhdlKeyword (LPCTSTR pszChars, int nLength)
213 return ISXKEYWORDI(s_apszVhdlKeywordList, pszChars, nLength);
217 IsVhdlAttribute (LPCTSTR pszChars, int nLength, int *nAttributeBegin)
219 for (int I = 0; I < nLength; I++)
221 if (pszChars[I] == '\'')
223 *nAttributeBegin = I;
224 return ISXKEYWORDI(s_apszVhdlAttributeList, &pszChars[I], nLength-I);
231 IsVhdlType (LPCTSTR pszChars, int nLength)
233 return ISXKEYWORDI(s_apszVhdlTypeList, pszChars, nLength);
237 IsVhdlFunction (LPCTSTR pszChars, int nLength)
239 return ISXKEYWORDI(s_apszVhdlFunctionList, pszChars, nLength);
243 IsVhdlNumber (LPCTSTR pszChars, int nLength)
245 if (nLength == 3 && pszChars[0] == '\'' && pszChars[2] == '\'')
247 if (pszChars[1] == '0' ||
248 pszChars[1] == '1' ||
249 pszChars[1] == 'u' ||
250 pszChars[1] == 'U' ||
251 pszChars[1] == 'x' ||
252 pszChars[1] == 'X' ||
253 pszChars[1] == 'w' ||
254 pszChars[1] == 'W' ||
255 pszChars[1] == 'l' ||
256 pszChars[1] == 'L' ||
257 pszChars[1] == 'h' ||
258 pszChars[1] == 'H' ||
259 pszChars[1] == 'z' ||
260 pszChars[1] == 'Z' ||
261 pszChars[1] == '-' ||
265 if (nLength > 4 && pszChars[1] == '"' && pszChars[nLength-1] == '"')
267 if (pszChars[0] == 'x' ||
268 pszChars[0] == 'X' ||
269 pszChars[0] == 'b' ||
270 pszChars[0] == 'B' ||
271 pszChars[0] == 'o' ||
274 for (int I = 2; I < nLength-1; I++)
276 if (_istdigit (pszChars[I]) ||
277 (pszChars[I] >= 'A' && pszChars[I] <= 'F') ||
278 (pszChars[I] >= 'a' && pszChars[I] <= 'f') ||
279 pszChars[I] == 'u' || pszChars[I] == 'U' ||
280 pszChars[I] == 'x' || pszChars[I] == 'X' ||
281 pszChars[I] == 'w' || pszChars[I] == 'W' ||
282 pszChars[I] == 'l' || pszChars[I] == 'L' ||
283 pszChars[I] == 'h' || pszChars[I] == 'H' ||
284 pszChars[I] == 'z' || pszChars[I] == 'Z' ||
285 // FIXME: Could not display "----", yet.
286 /* pszChars[I] == '-' || */ pszChars[I] == '_' )
293 if (nLength > 3 && pszChars[0] == '"' && pszChars[nLength-1] == '"')
295 for (int I = 1; I < nLength-1; I++)
297 if (_istdigit (pszChars[I]) ||
298 (pszChars[I] >= 'A' && pszChars[I] <= 'F') ||
299 (pszChars[I] >= 'a' && pszChars[I] <= 'f') ||
300 pszChars[I] == 'u' || pszChars[I] == 'U' ||
301 pszChars[I] == 'x' || pszChars[I] == 'X' ||
302 pszChars[I] == 'w' || pszChars[I] == 'W' ||
303 pszChars[I] == 'l' || pszChars[I] == 'L' ||
304 pszChars[I] == 'h' || pszChars[I] == 'H' ||
305 pszChars[I] == 'z' || pszChars[I] == 'Z' ||
306 // FIXME: Could not display "----", yet.
307 /* pszChars[I] == '-' || */ pszChars[I] == '_' )
313 for (int I = 0; I < nLength; I++)
315 if (!_istdigit (pszChars[I]) && pszChars[I] != '+' &&
316 pszChars[I] != '-' && pszChars[I] != '.' && pszChars[I] != 'e' &&
317 pszChars[I] != 'E' && pszChars[I] != '_')
324 IsVhdlString (LPCTSTR pszChars, int nLength)
326 if (nLength > 3 && pszChars[0] == '"' && pszChars[nLength-1] == '"')
332 IsVhdlChar (LPCTSTR pszChars, int nLength)
334 if (nLength == 3 && pszChars[0] == '\'' && pszChars[2] == '\'')
340 CrystalLineParser::ParseLineVhdl (DWORD dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
343 return dwCookie & COOKIE_EXT_COMMENT;
345 bool bRedefineBlock = true;
346 bool bDecIndex = false;
348 int nIdentBegin = -1;
349 int nAttributeBegin = 0;
352 for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars))
356 // CharNext did not advance, so we're at the end of the string
357 // and we already handled this character, so stop
366 if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
368 DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
370 else if (dwCookie & (COOKIE_STRING))
372 DEFINE_BLOCK (nPos, COLORINDEX_STRING);
374 else if (dwCookie & COOKIE_PREPROCESSOR)
376 DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR);
380 if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
382 DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
384 else if (pszChars[nPos] == '"' || pszChars[nPos] == '\'')
386 DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
390 DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR);
391 bRedefineBlock = true;
396 bRedefineBlock = false;
401 // Can be bigger than length if there is binary data
402 // See bug #1474782 Crash when comparing SQL with with binary data
406 if (dwCookie & COOKIE_COMMENT)
408 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
409 dwCookie |= COOKIE_COMMENT;
413 // Line comment --...
414 if (I > 0 && pszChars[I] == '-' && pszChars[nPrevI] == '-')
416 DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
417 dwCookie |= COOKIE_COMMENT;
421 // String constant "...."
422 if (dwCookie & COOKIE_STRING)
424 if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
426 dwCookie &= ~COOKIE_STRING;
427 bRedefineBlock = true;
433 // if (pszChars[I] == '"')
435 // DEFINE_BLOCK (I, COLORINDEX_STRING);
436 // dwCookie |= COOKIE_STRING;
441 continue; // We don't need to extract keywords,
442 // for faster parsing skip the rest of loop
444 if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
446 if (nIdentBegin == -1)
449 else if (pszChars[I] == '"' || pszChars[I] == '\'')
451 if (nIdentBegin == -1)
456 if (nIdentBegin >= 0)
458 if (IsVhdlNumber (pszChars + nIdentBegin, I - nIdentBegin))
460 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
462 else if (pszChars[nIdentBegin] == '"')
464 DEFINE_BLOCK (nIdentBegin, COLORINDEX_STRING);
465 dwCookie |= COOKIE_STRING;
468 else if (IsVhdlKeyword (pszChars + nIdentBegin, I - nIdentBegin))
470 DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
472 else if (IsVhdlAttribute (pszChars + nIdentBegin, I - nIdentBegin, &nAttributeBegin))
474 DEFINE_BLOCK (nIdentBegin + nAttributeBegin, COLORINDEX_FUNCNAME);
476 else if (IsVhdlType (pszChars + nIdentBegin, I - nIdentBegin))
478 DEFINE_BLOCK (nIdentBegin, COLORINDEX_PREPROCESSOR);
480 else if (IsVhdlFunction (pszChars + nIdentBegin, I - nIdentBegin))
482 DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
484 else if (IsVhdlChar (pszChars + nIdentBegin, I - nIdentBegin))
486 DEFINE_BLOCK (nIdentBegin, COLORINDEX_STRING);
488 bRedefineBlock = true;
495 if (nIdentBegin >= 0)
497 if (IsVhdlNumber (pszChars + nIdentBegin, I - nIdentBegin))
499 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
501 else if (pszChars[nIdentBegin] == '"')
503 DEFINE_BLOCK (nIdentBegin, COLORINDEX_STRING);
504 dwCookie |= COOKIE_STRING;
506 else if (IsVhdlKeyword (pszChars + nIdentBegin, I - nIdentBegin))
508 DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
510 else if (IsVhdlAttribute (pszChars + nIdentBegin, I - nIdentBegin, &nAttributeBegin))
512 DEFINE_BLOCK (nIdentBegin + nAttributeBegin, COLORINDEX_FUNCNAME);
514 else if (IsVhdlType (pszChars + nIdentBegin, I - nIdentBegin))
516 DEFINE_BLOCK (nIdentBegin, COLORINDEX_PREPROCESSOR);
518 else if (IsVhdlFunction (pszChars + nIdentBegin, I - nIdentBegin))
520 DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
522 else if (IsVhdlChar (pszChars + nIdentBegin, I - nIdentBegin))
524 DEFINE_BLOCK (nIdentBegin, COLORINDEX_STRING);
528 dwCookie &= COOKIE_EXT_COMMENT;