/contrib/groff/src/roff/troff/token.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 242 lines · 187 code · 35 blank · 20 comment · 23 complexity · de281a489a06ad6061d963bc5de6c4d4 MD5 · raw file

  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004
  3. Free Software Foundation, Inc.
  4. Written by James Clark (jjc@jclark.com)
  5. This file is part of groff.
  6. groff is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation; either version 2, or (at your option) any later
  9. version.
  10. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. for more details.
  14. You should have received a copy of the GNU General Public License along
  15. with groff; see the file COPYING. If not, write to the Free Software
  16. Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
  17. class charinfo;
  18. struct node;
  19. class vunits;
  20. class token {
  21. symbol nm;
  22. node *nd;
  23. unsigned char c;
  24. int val;
  25. units dim;
  26. enum token_type {
  27. TOKEN_BACKSPACE,
  28. TOKEN_BEGIN_TRAP,
  29. TOKEN_CHAR, // a normal printing character
  30. TOKEN_DUMMY, // \&
  31. TOKEN_EMPTY, // this is the initial value
  32. TOKEN_END_TRAP,
  33. TOKEN_ESCAPE, // \e
  34. TOKEN_HYPHEN_INDICATOR,
  35. TOKEN_INTERRUPT, // \c
  36. TOKEN_ITALIC_CORRECTION, // \/
  37. TOKEN_LEADER, // ^A
  38. TOKEN_LEFT_BRACE,
  39. TOKEN_MARK_INPUT, // \k -- `nm' is the name of the register
  40. TOKEN_NEWLINE, // newline
  41. TOKEN_NODE,
  42. TOKEN_NUMBERED_CHAR,
  43. TOKEN_PAGE_EJECTOR,
  44. TOKEN_REQUEST,
  45. TOKEN_RIGHT_BRACE,
  46. TOKEN_SPACE, // ` ' -- ordinary space
  47. TOKEN_SPECIAL, // a special character -- \' \` \- \(xx \[xxx]
  48. TOKEN_SPREAD, // \p -- break and spread output line
  49. TOKEN_STRETCHABLE_SPACE, // \~
  50. TOKEN_UNSTRETCHABLE_SPACE, // `\ '
  51. TOKEN_TAB, // tab
  52. TOKEN_TRANSPARENT, // \!
  53. TOKEN_TRANSPARENT_DUMMY, // \)
  54. TOKEN_ZERO_WIDTH_BREAK, // \:
  55. TOKEN_EOF // end of file
  56. } type;
  57. public:
  58. token();
  59. ~token();
  60. token(const token &);
  61. void operator=(const token &);
  62. void next();
  63. void process();
  64. void skip();
  65. int eof();
  66. int nspaces(); // 1 if space, 2 if double space, 0 otherwise
  67. int space(); // is the current token a space?
  68. int stretchable_space(); // is the current token a stretchable space?
  69. int unstretchable_space(); // is the current token an unstretchable space?
  70. int white_space(); // is the current token space or tab?
  71. int special(); // is the current token a special character?
  72. int newline(); // is the current token a newline?
  73. int tab(); // is the current token a tab?
  74. int leader();
  75. int backspace();
  76. int delimiter(int warn = 0); // is it suitable for use as a delimiter?
  77. int dummy();
  78. int transparent_dummy();
  79. int transparent();
  80. int left_brace();
  81. int right_brace();
  82. int page_ejector();
  83. int hyphen_indicator();
  84. int zero_width_break();
  85. int operator==(const token &); // need this for delimiters, and for conditions
  86. int operator!=(const token &); // ditto
  87. unsigned char ch();
  88. charinfo *get_char(int required = 0);
  89. int add_to_node_list(node **);
  90. int title();
  91. void make_space();
  92. void make_newline();
  93. const char *description();
  94. friend void process_input_stack();
  95. };
  96. extern token tok; // the current token
  97. extern symbol get_name(int required = 0);
  98. extern symbol get_long_name(int required = 0);
  99. extern charinfo *get_optional_char();
  100. extern char *read_string();
  101. extern void check_missing_character();
  102. extern void skip_line();
  103. extern void handle_initial_title();
  104. enum char_mode {
  105. CHAR_NORMAL,
  106. CHAR_FALLBACK,
  107. CHAR_FONT_SPECIAL,
  108. CHAR_SPECIAL
  109. };
  110. extern void do_define_character(char_mode, const char * = 0);
  111. class hunits;
  112. extern void read_title_parts(node **part, hunits *part_width);
  113. extern int get_number_rigidly(units *result, unsigned char si);
  114. extern int get_number(units *result, unsigned char si);
  115. extern int get_integer(int *result);
  116. extern int get_number(units *result, unsigned char si, units prev_value);
  117. extern int get_integer(int *result, int prev_value);
  118. void interpolate_number_reg(symbol, int);
  119. const char *asciify(int c);
  120. inline int token::newline()
  121. {
  122. return type == TOKEN_NEWLINE;
  123. }
  124. inline int token::space()
  125. {
  126. return type == TOKEN_SPACE;
  127. }
  128. inline int token::stretchable_space()
  129. {
  130. return type == TOKEN_STRETCHABLE_SPACE;
  131. }
  132. inline int token::unstretchable_space()
  133. {
  134. return type == TOKEN_UNSTRETCHABLE_SPACE;
  135. }
  136. inline int token::special()
  137. {
  138. return type == TOKEN_SPECIAL;
  139. }
  140. inline int token::nspaces()
  141. {
  142. if (type == TOKEN_SPACE)
  143. return 1;
  144. else
  145. return 0;
  146. }
  147. inline int token::white_space()
  148. {
  149. return type == TOKEN_SPACE || type == TOKEN_TAB;
  150. }
  151. inline int token::transparent()
  152. {
  153. return type == TOKEN_TRANSPARENT;
  154. }
  155. inline int token::page_ejector()
  156. {
  157. return type == TOKEN_PAGE_EJECTOR;
  158. }
  159. inline unsigned char token::ch()
  160. {
  161. return type == TOKEN_CHAR ? c : 0;
  162. }
  163. inline int token::eof()
  164. {
  165. return type == TOKEN_EOF;
  166. }
  167. inline int token::dummy()
  168. {
  169. return type == TOKEN_DUMMY;
  170. }
  171. inline int token::transparent_dummy()
  172. {
  173. return type == TOKEN_TRANSPARENT_DUMMY;
  174. }
  175. inline int token::left_brace()
  176. {
  177. return type == TOKEN_LEFT_BRACE;
  178. }
  179. inline int token::right_brace()
  180. {
  181. return type == TOKEN_RIGHT_BRACE;
  182. }
  183. inline int token::tab()
  184. {
  185. return type == TOKEN_TAB;
  186. }
  187. inline int token::leader()
  188. {
  189. return type == TOKEN_LEADER;
  190. }
  191. inline int token::backspace()
  192. {
  193. return type == TOKEN_BACKSPACE;
  194. }
  195. inline int token::hyphen_indicator()
  196. {
  197. return type == TOKEN_HYPHEN_INDICATOR;
  198. }
  199. inline int token::zero_width_break()
  200. {
  201. return type == TOKEN_ZERO_WIDTH_BREAK;
  202. }
  203. int has_arg();