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