Browse Source

cmLex.h/c : Added optional quoted character token recognizer.

master
kevin 11 years ago
parent
commit
83314506d7
2 changed files with 35 additions and 14 deletions
  1. 19
    0
      cmLex.c
  2. 16
    14
      cmLex.h

+ 19
- 0
cmLex.c View File

120
   return rc;
120
   return rc;
121
 }
121
 }
122
 
122
 
123
+// Locate 'keyStr' in cp[cn] and return the index into cp[cn] of the character
124
+// following the last char in 'keyStr'.  If keyStr is not found return cmInvalidIdx.
123
 unsigned _cmLexScanTo( const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )
125
 unsigned _cmLexScanTo( const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )
124
 {
126
 {
125
   unsigned i = 0;
127
   unsigned i = 0;
336
   return 0;
338
   return 0;
337
 }
339
 }
338
 
340
 
341
+unsigned _cmLexQCharMatcher( cmLex* p, const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )
342
+{
343
+  unsigned i = 0;
344
+  if( i >= cn || cp[i]!='\'' )
345
+    return 0;
346
+
347
+  i+=2;
348
+
349
+  if( i >= cn || cp[i]!='\'')
350
+    return 0;
351
+
352
+  return 3;
353
+}
354
+
339
 
355
 
340
 unsigned _cmLexBlockCmtMatcher( cmLex* p, const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )
356
 unsigned _cmLexBlockCmtMatcher( cmLex* p, const cmChar_t* cp, unsigned cn, const cmChar_t* keyStr )
341
 {  
357
 {  
474
   _cmLexInstallMatcher( p, kBlockCmtLexTId, _cmLexBlockCmtMatcher, NULL, NULL  );
490
   _cmLexInstallMatcher( p, kBlockCmtLexTId, _cmLexBlockCmtMatcher, NULL, NULL  );
475
   _cmLexInstallMatcher( p, kLineCmtLexTId,  _cmLexLineCmtMatcher,  NULL, NULL  );
491
   _cmLexInstallMatcher( p, kLineCmtLexTId,  _cmLexLineCmtMatcher,  NULL, NULL  );
476
 
492
 
493
+  if( cmIsFlag(flags,kReturnQCharLexFl) )
494
+    _cmLexInstallMatcher( p, kQCharLexTId,    _cmLexQCharMatcher,    NULL, NULL  );
495
+
477
   h.h = p;
496
   h.h = p;
478
 
497
 
479
   _cmLexReset(p);
498
   _cmLexReset(p);

+ 16
- 14
cmLex.h View File

11
 // Predefined Lexer Id's
11
 // Predefined Lexer Id's
12
 enum
12
 enum
13
 {
13
 {
14
-  kErrorLexTId,    // 0  the lexer was unable to identify the current token
15
-  kUnknownLexTId,  // 1  the token is of an unknown type (only used when kReturnUnknownLexFl is set)
16
-  kEofLexTId,      // 2  the lexer reached the end of input
17
-  kSpaceLexTId,    // 3  white space
18
-  kRealLexTId,     // 4  real number (contains a decimal point or is in scientific notation) 
19
-  kIntLexTId,      // 5  decimal integer
20
-  kHexLexTId,      // 6  hexidecimal integer
21
-  kIdentLexTId,    // 7  identifier
22
-  kQStrLexTId,     // 8  quoted string
23
-  kBlockCmtLexTId, // 9  block comment
24
-  kLineCmtLexTId,  // 10  line comment
25
-  kUserLexTId      // 11 user registered token (See cmLexRegisterToken().)
14
+  kErrorLexTId,    //  0  the lexer was unable to identify the current token
15
+  kUnknownLexTId,  //  1  the token is of an unknown type (only used when kReturnUnknownLexFl is set)
16
+  kEofLexTId,      //  2  the lexer reached the end of input
17
+  kSpaceLexTId,    //  3  white space
18
+  kRealLexTId,     //  4  real number (contains a decimal point or is in scientific notation) 
19
+  kIntLexTId,      //  5  decimal integer
20
+  kHexLexTId,      //  6  hexidecimal integer
21
+  kIdentLexTId,    //  7  identifier
22
+  kQStrLexTId,     //  8  quoted string
23
+  kQCharLexTId,    //  9  quoted char
24
+  kBlockCmtLexTId, // 10  block comment
25
+  kLineCmtLexTId,  // 11  line comment
26
+  kUserLexTId      // 12 user registered token (See cmLexRegisterToken().)
26
 };
27
 };
27
 
28
 
28
 // Lexer control flags used with cmLexInit().
29
 // Lexer control flags used with cmLexInit().
31
   kReturnSpaceLexFl    = 0x01, //< Return space tokens
32
   kReturnSpaceLexFl    = 0x01, //< Return space tokens
32
   kReturnCommentsLexFl = 0x02, //< Return comment tokens
33
   kReturnCommentsLexFl = 0x02, //< Return comment tokens
33
   kReturnUnknownLexFl  = 0x04, //< Return unknown tokens
34
   kReturnUnknownLexFl  = 0x04, //< Return unknown tokens
34
-  kUserDefPriorityLexFl= 0x08  //< User defined tokens take priority even if a kIdentLexTId token has a longer match
35
+  kReturnQCharLexFl    = 0x08, //< Return quoted characters
36
+  kUserDefPriorityLexFl= 0x10  //< User defined tokens take priority even if a kIdentLexTId token has a longer match
35
 };
37
 };
36
 
38
 
37
 // cmLex result codes.
39
 // cmLex result codes.
84
 cmRC_t             cmLexRegisterToken( cmLexH h, unsigned id, const cmChar_t* token );
86
 cmRC_t             cmLexRegisterToken( cmLexH h, unsigned id, const cmChar_t* token );
85
 
87
 
86
 // Register a user defined token recognition function.  This function should return the count
88
 // Register a user defined token recognition function.  This function should return the count
87
-// of initial, consecutive, characters in 'cp' which match its token pattern.
89
+// of initial, consecutive, characters in 'cp[cn]' which match its token pattern.
88
 typedef unsigned (*cmLexUserMatcherPtr_t)( const cmChar_t* cp, unsigned cn );
90
 typedef unsigned (*cmLexUserMatcherPtr_t)( const cmChar_t* cp, unsigned cn );
89
 
91
 
90
 cmRC_t             cmLexRegisterMatcher( cmLexH h, unsigned id, cmLexUserMatcherPtr_t funcPtr );
92
 cmRC_t             cmLexRegisterMatcher( cmLexH h, unsigned id, cmLexUserMatcherPtr_t funcPtr );

Loading…
Cancel
Save