libcm is a C development framework with an emphasis on audio signal processing applications.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cmLex.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef cmLex_h
  2. #define cmLex_h
  3. //{
  4. //(
  5. //)
  6. //(
  7. // Predefined Lexer Id's
  8. enum
  9. {
  10. kErrorLexTId, // 0 the lexer was unable to identify the current token
  11. kEofLexTId, // 1 the lexer reached the end of input
  12. kSpaceLexTId, // 2 white space
  13. kRealLexTId, // 3 real number (contains a decimal point or is in scientific notation)
  14. kIntLexTId, // 4 decimal integer
  15. kHexLexTId, // 5 hexidecimal integer
  16. kIdentLexTId, // 6 identifier
  17. kQStrLexTId, // 7 quoted string
  18. kBlockCmtLexTId, // 8 block comment
  19. kLineCmtLexTId, // 9 line comment
  20. kUserLexTId // 10 user registered token (See cmLexRegisterToken().)
  21. };
  22. // Lexer control flags used with cmLexInit().
  23. enum
  24. {
  25. kReturnSpaceLexFl = 0x01, //< Return space tokens
  26. kReturnCommentsLexFl = 0x02 //< Return comment tokens
  27. };
  28. // cmLex result codes.
  29. enum
  30. {
  31. kOkLexRC = cmOkRC, //< 0 No error. The operation completed successfully
  32. kDuplicateTokenLexRC, //< 1 The text or id passed as a user token is already in use by another token
  33. kMissingCmtEndLexRC, //< 2 The end of a block comment could not be found.
  34. kMissingEndQuoteLexRC, //< 3 The end of a quoted string could not be found.
  35. kNoMatchLexRC, //< 4 The lexer encountered a string which could not be classified.
  36. kFileOpenErrLexRC, //< 5 File open failed on cmLexSetFile()
  37. kFileSeekErrLexRC, //< 6 File seek failed on cmLexSetFile()
  38. kFileTellErrLexRC, //< 7 File tell failed on cmLexSetFile()
  39. kFileReadErrLexRC, //< 8 File read failed on cmLexSetFile()
  40. kFileCloseErrLexRC, //< 9 File close failed on cmLexSetFile()
  41. kMemAllocErrLexRC, //< 10 An attempted memory allocation failed
  42. kEofRC, //< 11 The end of the input text was encountered (this is a normal condition not an error)
  43. kInvalidLexRC //< 12 Sentinal value.
  44. };
  45. typedef cmHandle_t cmLexH;
  46. extern cmLexH cmLexNullH;
  47. // Iniitalize the lexer and receive a lexer handle in return.
  48. // Set cp to NULL if the buffer will be later via cmLexSetTextBuffer();
  49. // See the kXXXLexFl enum's above for possible flag values.
  50. cmLexH cmLexInit( const cmChar_t* cp, unsigned cn, unsigned flags, cmRpt_t* rpt );
  51. // Finalize a lexer created by an earlier call to cmLexInit()
  52. cmRC_t cmLexFinal( cmLexH* hp );
  53. // Rewind the lexer to the begining of the buffer (the same as post initialize state)
  54. cmRC_t cmLexReset( cmLexH h );
  55. // Verify that a lexer handle is valid
  56. bool cmLexIsValid( cmLexH h );
  57. // Set a new text buffer and reset the lexer to the post initialize state.
  58. cmRC_t cmLexSetTextBuffer( cmLexH h, const cmChar_t* cp, unsigned cn );
  59. cmRC_t cmLexSetFile( cmLexH h, const cmChar_t* fn );
  60. // Register a user defined token. The id of the first user defined token should be
  61. // kUserLexTId+1. Neither the id or token text can be used by a previously registered
  62. // or built-in token.
  63. cmRC_t cmLexRegisterToken( cmLexH h, unsigned id, const cmChar_t* token );
  64. // Register a user defined token recognition function. This function should return the count
  65. // of initial, consecutive, characters in 'cp' which match its token pattern.
  66. typedef unsigned (*cmLexUserMatcherPtr_t)( const cmChar_t* cp, unsigned cn );
  67. cmRC_t cmLexRegisterMatcher( cmLexH h, unsigned id, cmLexUserMatcherPtr_t funcPtr );
  68. // Return the type id of the current token and advances to the next token
  69. unsigned cmLexGetNextToken( cmLexH h );
  70. // Return the type id associated with the current token. This is the same value
  71. // returned by the previous call to cmLexGetNextToken().
  72. unsigned cmLexTokenId( cmLexH h );
  73. // Return a pointer to the first character of text associated with the
  74. // current token. The returned pointer directly references the text contained
  75. // in the buffer given to the lexer in the call to cmLexInit(). The string
  76. // is therefore not zero terminated. Use cmLexTokenCharCount() to get the
  77. // length of the token string.
  78. const cmChar_t* cmLexTokenText( cmLexH h );
  79. // Return the count of characters in the text associated with the current token.
  80. // This is the only way to get this count since the string returned by
  81. // cmLexTokenText() is not zero terminated.
  82. unsigned cmLexTokenCharCount( cmLexH h );
  83. // Return the value of the current token as an integer.
  84. int cmLexTokenInt( cmLexH h );
  85. // Return the value of the current token as an integer.
  86. unsigned cmLexTokenUInt( cmLexH h );
  87. // Return the value of the current token as an integer.
  88. float cmLexTokenFloat( cmLexH h );
  89. // Return the value of the current token as a double.
  90. double cmLexTokenDouble( cmLexH h );
  91. // Return the line number associated with the current token
  92. unsigned cmLexCurrentLineNumber( cmLexH h );
  93. // Return the starting column of the current token
  94. unsigned cmLexCurrentColumnNumber( cmLexH h );
  95. // Return the RC code associated with the last error
  96. unsigned cmLexErrorRC( cmLexH h );
  97. // Return the label associated with a token id
  98. const cmChar_t* cmLexIdToLabel( cmLexH h, unsigned typeId );
  99. // Return the text message associated with a return code.
  100. const cmChar_t* cmLexRcToMsg( unsigned rc );
  101. // Lexer testing stub.
  102. void cmLexTest( cmRpt_t* rpt );
  103. //)
  104. //}
  105. #endif