StreamTokenizer.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /* StreamTokenizer.java -- parses streams of characters into tokens
  2. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.io;
  32. import gnu.java.lang.CPStringBuilder;
  33. /**
  34. * This class parses streams of characters into tokens. There are a
  35. * million-zillion flags that can be set to control the parsing, as
  36. * described under the various method headings.
  37. *
  38. * @author Warren Levy (warrenl@cygnus.com)
  39. * @date October 25, 1998.
  40. */
  41. /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
  42. * "The Java Language Specification", ISBN 0-201-63451-1
  43. * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
  44. * Status: Believed complete and correct.
  45. */
  46. public class StreamTokenizer
  47. {
  48. /** A constant indicating that the end of the stream has been read. */
  49. public static final int TT_EOF = -1;
  50. /** A constant indicating that the end of the line has been read. */
  51. public static final int TT_EOL = '\n';
  52. /** A constant indicating that a number token has been read. */
  53. public static final int TT_NUMBER = -2;
  54. /** A constant indicating that a word token has been read. */
  55. public static final int TT_WORD = -3;
  56. /** A constant indicating that no tokens have been read yet. */
  57. private static final int TT_NONE = -4;
  58. /**
  59. * Contains the type of the token read resulting from a call to nextToken
  60. * The rules are as follows:
  61. * <ul>
  62. * <li>For a token consisting of a single ordinary character, this is the
  63. * value of that character.</li>
  64. * <li>For a quoted string, this is the value of the quote character</li>
  65. * <li>For a word, this is TT_WORD</li>
  66. * <li>For a number, this is TT_NUMBER</li>
  67. * <li>For the end of the line, this is TT_EOL</li>
  68. * <li>For the end of the stream, this is TT_EOF</li>
  69. * </ul>
  70. */
  71. public int ttype = TT_NONE;
  72. /** The String associated with word and string tokens. */
  73. public String sval;
  74. /** The numeric value associated with number tokens. */
  75. public double nval;
  76. /* Indicates whether end-of-line is recognized as a token. */
  77. private boolean eolSignificant = false;
  78. /* Indicates whether word tokens are automatically made lower case. */
  79. private boolean lowerCase = false;
  80. /* Indicates whether C++ style comments are recognized and skipped. */
  81. private boolean slashSlash = false;
  82. /* Indicates whether C style comments are recognized and skipped. */
  83. private boolean slashStar = false;
  84. /* Attribute tables of each byte from 0x00 to 0xFF. */
  85. private boolean[] whitespace = new boolean[256];
  86. private boolean[] alphabetic = new boolean[256];
  87. private boolean[] numeric = new boolean[256];
  88. private boolean[] quote = new boolean[256];
  89. private boolean[] comment = new boolean[256];
  90. /* The Reader associated with this class. */
  91. private PushbackReader in;
  92. /* Indicates if a token has been pushed back. */
  93. private boolean pushedBack = false;
  94. /* Contains the current line number of the reader. */
  95. private int lineNumber = 1;
  96. /**
  97. * This method reads bytes from an <code>InputStream</code> and tokenizes
  98. * them. For details on how this method operates by default, see
  99. * <code>StreamTokenizer(Reader)</code>.
  100. *
  101. * @param is The <code>InputStream</code> to read from
  102. *
  103. * @deprecated Since JDK 1.1.
  104. */
  105. public StreamTokenizer(InputStream is)
  106. {
  107. this(new InputStreamReader(is));
  108. }
  109. /**
  110. * This method initializes a new <code>StreamTokenizer</code> to read
  111. * characters from a <code>Reader</code> and parse them. The char values
  112. * have their hight bits masked so that the value is treated a character
  113. * in the range of 0x0000 to 0x00FF.
  114. * <p>
  115. * This constructor sets up the parsing table to parse the stream in the
  116. * following manner:
  117. * <ul>
  118. * <li>The values 'A' through 'Z', 'a' through 'z' and 0xA0 through 0xFF
  119. * are initialized as alphabetic</li>
  120. * <li>The values 0x00 through 0x20 are initialized as whitespace</li>
  121. * <li>The values '\'' and '"' are initialized as quote characters</li>
  122. * <li>'/' is a comment character</li>
  123. * <li>Numbers will be parsed</li>
  124. * <li>EOL is not treated as significant</li>
  125. * <li>C and C++ (//) comments are not recognized</li>
  126. * </ul>
  127. *
  128. * @param r The <code>Reader</code> to read chars from
  129. */
  130. public StreamTokenizer(Reader r)
  131. {
  132. in = new PushbackReader(r);
  133. whitespaceChars(0x00, 0x20);
  134. wordChars('A', 'Z');
  135. wordChars('a', 'z');
  136. wordChars(0xA0, 0xFF);
  137. commentChar('/');
  138. quoteChar('\'');
  139. quoteChar('"');
  140. parseNumbers();
  141. }
  142. /**
  143. * This method sets the comment attribute on the specified
  144. * character. Other attributes for the character are cleared.
  145. *
  146. * @param ch The character to set the comment attribute for, passed as an int
  147. */
  148. public void commentChar(int ch)
  149. {
  150. if (ch >= 0 && ch <= 255)
  151. {
  152. comment[ch] = true;
  153. whitespace[ch] = false;
  154. alphabetic[ch] = false;
  155. numeric[ch] = false;
  156. quote[ch] = false;
  157. }
  158. }
  159. /**
  160. * This method sets a flag that indicates whether or not the end of line
  161. * sequence terminates and is a token. The defaults to <code>false</code>
  162. *
  163. * @param flag <code>true</code> if EOF is significant, <code>false</code>
  164. * otherwise
  165. */
  166. public void eolIsSignificant(boolean flag)
  167. {
  168. eolSignificant = flag;
  169. }
  170. /**
  171. * This method returns the current line number. Note that if the
  172. * <code>pushBack()</code> method is called, it has no effect on the
  173. * line number returned by this method.
  174. *
  175. * @return The current line number
  176. */
  177. public int lineno()
  178. {
  179. return lineNumber;
  180. }
  181. /**
  182. * This method sets a flag that indicates whether or not alphabetic
  183. * tokens that are returned should be converted to lower case.
  184. *
  185. * @param flag <code>true</code> to convert to lower case,
  186. * <code>false</code> otherwise
  187. */
  188. public void lowerCaseMode(boolean flag)
  189. {
  190. lowerCase = flag;
  191. }
  192. private boolean isWhitespace(int ch)
  193. {
  194. return (ch >= 0 && ch <= 255 && whitespace[ch]);
  195. }
  196. private boolean isAlphabetic(int ch)
  197. {
  198. return ((ch > 255) || (ch >= 0 && alphabetic[ch]));
  199. }
  200. private boolean isNumeric(int ch)
  201. {
  202. return (ch >= 0 && ch <= 255 && numeric[ch]);
  203. }
  204. private boolean isQuote(int ch)
  205. {
  206. return (ch >= 0 && ch <= 255 && quote[ch]);
  207. }
  208. private boolean isComment(int ch)
  209. {
  210. return (ch >= 0 && ch <= 255 && comment[ch]);
  211. }
  212. /**
  213. * This method reads the next token from the stream. It sets the
  214. * <code>ttype</code> variable to the appropriate token type and
  215. * returns it. It also can set <code>sval</code> or <code>nval</code>
  216. * as described below. The parsing strategy is as follows:
  217. * <ul>
  218. * <li>Skip any whitespace characters.</li>
  219. * <li>If a numeric character is encountered, attempt to parse a numeric
  220. * value. Leading '-' characters indicate a numeric only if followed by
  221. * another non-'-' numeric. The value of the numeric token is terminated
  222. * by either the first non-numeric encountered, or the second occurrence of
  223. * '-' or '.'. The token type returned is TT_NUMBER and <code>nval</code>
  224. * is set to the value parsed.</li>
  225. * <li>If an alphabetic character is parsed, all subsequent characters
  226. * are read until the first non-alphabetic or non-numeric character is
  227. * encountered. The token type returned is TT_WORD and the value parsed
  228. * is stored in <code>sval</code>. If lower case mode is set, the token
  229. * stored in <code>sval</code> is converted to lower case. The end of line
  230. * sequence terminates a word only if EOL signficance has been turned on.
  231. * The start of a comment also terminates a word. Any character with a
  232. * non-alphabetic and non-numeric attribute (such as white space, a quote,
  233. * or a commet) are treated as non-alphabetic and terminate the word.</li>
  234. * <li>If a comment character is parsed, then all remaining characters on
  235. * the current line are skipped and another token is parsed. Any EOL or
  236. * EOF's encountered are not discarded, but rather terminate the comment.</li>
  237. * <li>If a quote character is parsed, then all characters up to the
  238. * second occurrence of the same quote character are parsed into a
  239. * <code>String</code>. This <code>String</code> is stored as
  240. * <code>sval</code>, but is not converted to lower case, even if lower case
  241. * mode is enabled. The token type returned is the value of the quote
  242. * character encountered. Any escape sequences
  243. * (\b (backspace), \t (HTAB), \n (linefeed), \f (form feed), \r
  244. * (carriage return), \" (double quote), \' (single quote), \\
  245. * (backslash), \XXX (octal esacpe)) are converted to the appropriate
  246. * char values. Invalid esacape sequences are left in untranslated.
  247. * Unicode characters like ('\ u0000') are not recognized. </li>
  248. * <li>If the C++ comment sequence "//" is encountered, and the parser
  249. * is configured to handle that sequence, then the remainder of the line
  250. * is skipped and another token is read exactly as if a character with
  251. * the comment attribute was encountered.</li>
  252. * <li>If the C comment sequence "/*" is encountered, and the parser
  253. * is configured to handle that sequence, then all characters up to and
  254. * including the comment terminator sequence are discarded and another
  255. * token is parsed.</li>
  256. * <li>If all cases above are not met, then the character is an ordinary
  257. * character that is parsed as a token by itself. The char encountered
  258. * is returned as the token type.</li>
  259. * </ul>
  260. *
  261. * @return The token type
  262. * @exception IOException If an I/O error occurs
  263. */
  264. public int nextToken() throws IOException
  265. {
  266. if (pushedBack)
  267. {
  268. pushedBack = false;
  269. if (ttype != TT_NONE)
  270. return ttype;
  271. }
  272. sval = null;
  273. int ch;
  274. // Skip whitespace. Deal with EOL along the way.
  275. while (isWhitespace(ch = in.read()))
  276. if (ch == '\n' || ch == '\r')
  277. {
  278. lineNumber++;
  279. // Throw away \n if in combination with \r.
  280. if (ch == '\r' && (ch = in.read()) != '\n')
  281. {
  282. if (ch != TT_EOF)
  283. in.unread(ch);
  284. }
  285. if (eolSignificant)
  286. return (ttype = TT_EOL);
  287. }
  288. if (ch == '/')
  289. if ((ch = in.read()) == '/' && slashSlash)
  290. {
  291. while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF)
  292. ;
  293. if (ch != TT_EOF)
  294. in.unread(ch);
  295. return nextToken(); // Recursive, but not too deep in normal cases
  296. }
  297. else if (ch == '*' && slashStar)
  298. {
  299. while (true)
  300. {
  301. ch = in.read();
  302. if (ch == '*')
  303. {
  304. if ((ch = in.read()) == '/')
  305. break;
  306. else if (ch != TT_EOF)
  307. in.unread(ch);
  308. }
  309. else if (ch == '\n' || ch == '\r')
  310. {
  311. lineNumber++;
  312. if (ch == '\r' && (ch = in.read()) != '\n')
  313. {
  314. if (ch != TT_EOF)
  315. in.unread(ch);
  316. }
  317. }
  318. else if (ch == TT_EOF)
  319. {
  320. break;
  321. }
  322. }
  323. return nextToken(); // Recursive, but not too deep in normal cases
  324. }
  325. else
  326. {
  327. if (ch != TT_EOF)
  328. in.unread(ch);
  329. ch = '/';
  330. }
  331. if (ch == TT_EOF)
  332. ttype = TT_EOF;
  333. else if (isNumeric(ch))
  334. {
  335. boolean isNegative = false;
  336. if (ch == '-')
  337. {
  338. // Read ahead to see if this is an ordinary '-' rather than numeric.
  339. ch = in.read();
  340. if (isNumeric(ch) && ch != '-')
  341. {
  342. isNegative = true;
  343. }
  344. else
  345. {
  346. if (ch != TT_EOF)
  347. in.unread(ch);
  348. return (ttype = '-');
  349. }
  350. }
  351. CPStringBuilder tokbuf = new CPStringBuilder();
  352. tokbuf.append((char) ch);
  353. int decCount = 0;
  354. while (isNumeric(ch = in.read()) && ch != '-')
  355. if (ch == '.' && decCount++ > 0)
  356. break;
  357. else
  358. tokbuf.append((char) ch);
  359. if (ch != TT_EOF)
  360. in.unread(ch);
  361. ttype = TT_NUMBER;
  362. try
  363. {
  364. nval = Double.valueOf(tokbuf.toString()).doubleValue();
  365. }
  366. catch (NumberFormatException _)
  367. {
  368. nval = 0.0;
  369. }
  370. if (isNegative)
  371. nval = -nval;
  372. }
  373. else if (isAlphabetic(ch))
  374. {
  375. CPStringBuilder tokbuf = new CPStringBuilder();
  376. tokbuf.append((char) ch);
  377. while (isAlphabetic(ch = in.read()) || isNumeric(ch))
  378. tokbuf.append((char) ch);
  379. if (ch != TT_EOF)
  380. in.unread(ch);
  381. ttype = TT_WORD;
  382. sval = tokbuf.toString();
  383. if (lowerCase)
  384. sval = sval.toLowerCase();
  385. }
  386. else if (isComment(ch))
  387. {
  388. while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF)
  389. ;
  390. if (ch != TT_EOF)
  391. in.unread(ch);
  392. return nextToken(); // Recursive, but not too deep in normal cases.
  393. }
  394. else if (isQuote(ch))
  395. {
  396. ttype = ch;
  397. CPStringBuilder tokbuf = new CPStringBuilder();
  398. while ((ch = in.read()) != ttype && ch != '\n' && ch != '\r' &&
  399. ch != TT_EOF)
  400. {
  401. if (ch == '\\')
  402. switch (ch = in.read())
  403. {
  404. case 'a': ch = 0x7;
  405. break;
  406. case 'b': ch = '\b';
  407. break;
  408. case 'f': ch = 0xC;
  409. break;
  410. case 'n': ch = '\n';
  411. break;
  412. case 'r': ch = '\r';
  413. break;
  414. case 't': ch = '\t';
  415. break;
  416. case 'v': ch = 0xB;
  417. break;
  418. case '\n': ch = '\n';
  419. break;
  420. case '\r': ch = '\r';
  421. break;
  422. case '\"':
  423. case '\'':
  424. case '\\':
  425. break;
  426. default:
  427. int ch1, nextch;
  428. if ((nextch = ch1 = ch) >= '0' && ch <= '7')
  429. {
  430. ch -= '0';
  431. if ((nextch = in.read()) >= '0' && nextch <= '7')
  432. {
  433. ch = ch * 8 + nextch - '0';
  434. if ((nextch = in.read()) >= '0' && nextch <= '7' &&
  435. ch1 >= '0' && ch1 <= '3')
  436. {
  437. ch = ch * 8 + nextch - '0';
  438. nextch = in.read();
  439. }
  440. }
  441. }
  442. if (nextch != TT_EOF)
  443. in.unread(nextch);
  444. }
  445. tokbuf.append((char) ch);
  446. }
  447. // Throw away matching quote char.
  448. if (ch != ttype && ch != TT_EOF)
  449. in.unread(ch);
  450. sval = tokbuf.toString();
  451. }
  452. else
  453. {
  454. ttype = ch;
  455. }
  456. return ttype;
  457. }
  458. private void resetChar(int ch)
  459. {
  460. whitespace[ch] = alphabetic[ch] = numeric[ch] = quote[ch] = comment[ch] =
  461. false;
  462. }
  463. /**
  464. * This method makes the specified character an ordinary character. This
  465. * means that none of the attributes (whitespace, alphabetic, numeric,
  466. * quote, or comment) will be set on this character. This character will
  467. * parse as its own token.
  468. *
  469. * @param ch The character to make ordinary, passed as an int
  470. */
  471. public void ordinaryChar(int ch)
  472. {
  473. if (ch >= 0 && ch <= 255)
  474. resetChar(ch);
  475. }
  476. /**
  477. * This method makes all the characters in the specified range, range
  478. * terminators included, ordinary. This means the none of the attributes
  479. * (whitespace, alphabetic, numeric, quote, or comment) will be set on
  480. * any of the characters in the range. This makes each character in this
  481. * range parse as its own token.
  482. *
  483. * @param low The low end of the range of values to set the whitespace
  484. * attribute for
  485. * @param hi The high end of the range of values to set the whitespace
  486. * attribute for
  487. */
  488. public void ordinaryChars(int low, int hi)
  489. {
  490. if (low < 0)
  491. low = 0;
  492. if (hi > 255)
  493. hi = 255;
  494. for (int i = low; i <= hi; i++)
  495. resetChar(i);
  496. }
  497. /**
  498. * This method sets the numeric attribute on the characters '0' - '9' and
  499. * the characters '.' and '-'.
  500. * When this method is used, the result of giving other attributes
  501. * (whitespace, quote, or comment) to the numeric characters may
  502. * vary depending on the implementation. For example, if
  503. * parseNumbers() and then whitespaceChars('1', '1') are called,
  504. * this implementation reads "121" as 2, while some other implementation
  505. * will read it as 21.
  506. */
  507. public void parseNumbers()
  508. {
  509. for (int i = 0; i <= 9; i++)
  510. numeric['0' + i] = true;
  511. numeric['.'] = true;
  512. numeric['-'] = true;
  513. }
  514. /**
  515. * Puts the current token back into the StreamTokenizer so
  516. * <code>nextToken</code> will return the same value on the next call.
  517. * May cause the lineno method to return an incorrect value
  518. * if lineno is called before the next call to nextToken.
  519. */
  520. public void pushBack()
  521. {
  522. pushedBack = true;
  523. }
  524. /**
  525. * This method sets the quote attribute on the specified character.
  526. * Other attributes for the character are cleared.
  527. *
  528. * @param ch The character to set the quote attribute for, passed as an int.
  529. */
  530. public void quoteChar(int ch)
  531. {
  532. if (ch >= 0 && ch <= 255)
  533. {
  534. quote[ch] = true;
  535. comment[ch] = false;
  536. whitespace[ch] = false;
  537. alphabetic[ch] = false;
  538. numeric[ch] = false;
  539. }
  540. }
  541. /**
  542. * This method removes all attributes (whitespace, alphabetic, numeric,
  543. * quote, and comment) from all characters. It is equivalent to calling
  544. * <code>ordinaryChars(0x00, 0xFF)</code>.
  545. *
  546. * @see #ordinaryChars(int, int)
  547. */
  548. public void resetSyntax()
  549. {
  550. ordinaryChars(0x00, 0xFF);
  551. }
  552. /**
  553. * This method sets a flag that indicates whether or not "C++" language style
  554. * comments ("//" comments through EOL ) are handled by the parser.
  555. * If this is <code>true</code> commented out sequences are skipped and
  556. * ignored by the parser. This defaults to <code>false</code>.
  557. *
  558. * @param flag <code>true</code> to recognized and handle "C++" style
  559. * comments, <code>false</code> otherwise
  560. */
  561. public void slashSlashComments(boolean flag)
  562. {
  563. slashSlash = flag;
  564. }
  565. /**
  566. * This method sets a flag that indicates whether or not "C" language style
  567. * comments (with nesting not allowed) are handled by the parser.
  568. * If this is <code>true</code> commented out sequences are skipped and
  569. * ignored by the parser. This defaults to <code>false</code>.
  570. *
  571. * @param flag <code>true</code> to recognized and handle "C" style comments,
  572. * <code>false</code> otherwise
  573. */
  574. public void slashStarComments(boolean flag)
  575. {
  576. slashStar = flag;
  577. }
  578. /**
  579. * This method returns the current token value as a <code>String</code> in
  580. * the form "Token[x], line n", where 'n' is the current line numbers and
  581. * 'x' is determined as follows.
  582. * <p>
  583. * <ul>
  584. * <li>If no token has been read, then 'x' is "NOTHING" and 'n' is 0</li>
  585. * <li>If <code>ttype</code> is TT_EOF, then 'x' is "EOF"</li>
  586. * <li>If <code>ttype</code> is TT_EOL, then 'x' is "EOL"</li>
  587. * <li>If <code>ttype</code> is TT_WORD, then 'x' is <code>sval</code></li>
  588. * <li>If <code>ttype</code> is TT_NUMBER, then 'x' is "n=strnval" where
  589. * 'strnval' is <code>String.valueOf(nval)</code>.</li>
  590. * <li>If <code>ttype</code> is a quote character, then 'x' is
  591. * <code>sval</code></li>
  592. * <li>For all other cases, 'x' is <code>ttype</code></li>
  593. * </ul>
  594. */
  595. public String toString()
  596. {
  597. String tempstr;
  598. if (ttype == TT_EOF)
  599. tempstr = "EOF";
  600. else if (ttype == TT_EOL)
  601. tempstr = "EOL";
  602. else if (ttype == TT_WORD)
  603. tempstr = sval;
  604. else if (ttype == TT_NUMBER)
  605. tempstr = "n=" + nval;
  606. else if (ttype == TT_NONE)
  607. tempstr = "NOTHING";
  608. else // must be an ordinary char.
  609. tempstr = "\'" + (char) ttype + "\'";
  610. return "Token[" + tempstr + "], line " + lineno();
  611. }
  612. /**
  613. * This method sets the whitespace attribute for all characters in the
  614. * specified range, range terminators included.
  615. *
  616. * @param low The low end of the range of values to set the whitespace
  617. * attribute for
  618. * @param hi The high end of the range of values to set the whitespace
  619. * attribute for
  620. */
  621. public void whitespaceChars(int low, int hi)
  622. {
  623. if (low < 0)
  624. low = 0;
  625. if (hi > 255)
  626. hi = 255;
  627. for (int i = low; i <= hi; i++)
  628. {
  629. resetChar(i);
  630. whitespace[i] = true;
  631. }
  632. }
  633. /**
  634. * This method sets the alphabetic attribute for all characters in the
  635. * specified range, range terminators included.
  636. *
  637. * @param low The low end of the range of values to set the alphabetic
  638. * attribute for
  639. * @param hi The high end of the range of values to set the alphabetic
  640. * attribute for
  641. */
  642. public void wordChars(int low, int hi)
  643. {
  644. if (low < 0)
  645. low = 0;
  646. if (hi > 255)
  647. hi = 255;
  648. for (int i = low; i <= hi; i++)
  649. alphabetic[i] = true;
  650. }
  651. }