core-parser.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef AFUN_CORE_PARSER_H
  2. #define AFUN_CORE_PARSER_H
  3. #include "aFunToolExport.h"
  4. #include "reader.h"
  5. namespace aFuncore {
  6. class AFUN_CORE_EXPORT Parser {
  7. public:
  8. typedef enum LexicalStatus {
  9. lex_begin = 0, // 起始类型
  10. lex_prefix_block_p = 1, // 前缀括号 !
  11. lex_prefix_block_b = 2, // 前缀括号 @
  12. lex_prefix_block_c = 3, // 前缀括号 #
  13. lex_comment_before = 4, // 注释
  14. lex_element_long = 5,
  15. lex_mutli_comment = 6, // 多行注释
  16. lex_uni_comment = 7, // 当行注释
  17. lex_mutli_comment_end_before = 8, // 多行注释遇到;
  18. lex_prefix = -1, // prefix类型
  19. lex_lp = -2,
  20. lex_lb = -3,
  21. lex_lc = -4,
  22. lex_rp = -5,
  23. lex_rb = -6,
  24. lex_rc = -7,
  25. lex_space = -8,
  26. lex_uni_comment_end = -9,
  27. lex_mutli_comment_end = -10,
  28. lex_nul = -11,
  29. lex_element_short = -12,
  30. lex_element_long_end = -13,
  31. } LexicalStatus;
  32. typedef enum TokenType {
  33. TK_ERROR = -1,
  34. TK_PREFIX = 0, // 前缀
  35. TK_LP = 1,
  36. TK_LB = 2,
  37. TK_LC = 3,
  38. TK_RP = 4,
  39. TK_RB = 5,
  40. TK_RC = 6,
  41. TK_ELEMENT_SHORT = 7,
  42. TK_ELEMENT_LONG = 8,
  43. TK_COMMENT = 9,
  44. TK_SPACE = 10,
  45. TK_EOF = 11,
  46. } TokenType;
  47. inline explicit Parser(Reader &reader_);
  48. TokenType getTokenFromLexical(std::string &text);
  49. private:
  50. typedef enum DoneStatus {
  51. DEL_TOKEN = 0,
  52. FINISH_TOKEN = -1,
  53. CONTINUE_TOKEN = 1,
  54. ERROR_TOKEN = -2
  55. } DoneStatus;
  56. Reader &reader;
  57. struct {
  58. LexicalStatus status;
  59. TokenType token; // token类型
  60. size_t last; // 最后一次词法匹配的有效长度
  61. size_t mutli_comment; // 多行注释嵌套等级
  62. bool is_end;
  63. bool is_error;
  64. } lexical;
  65. void setLexicalLast(LexicalStatus status, TokenType token);
  66. DoneStatus doneBegin(char ch);
  67. DoneStatus donePrefixBlock(char ch);
  68. DoneStatus doneCommentBefore(char ch);
  69. DoneStatus doneUniComment(char ch);
  70. DoneStatus doneMutliComment(char ch);
  71. DoneStatus doneMutliCommentBeforeEnd(char ch);
  72. DoneStatus doneElementLong(char ch);
  73. DoneStatus doneElementLongEnd(char ch);
  74. DoneStatus doneElementShort(char ch);
  75. DoneStatus doneSpace(char ch);
  76. };
  77. }
  78. #include "core-parser.inline.h"
  79. #endif //AFUN_CORE_PARSER_H