213
214 return Token.unicode(value);
215 }
216 });
217
218 }
219
220 /**
221 * JavaScript Token to Java regex substring framework.
222 *
223 */
224 private static class ToString {
225 String toString(final Token token) {
226 final StringBuilder sb = new StringBuilder();
227 for (final Object child : token.getChildren()) {
228 sb.append(child);
229 }
230
231 //perform global substitutions that hold true for any evaluated form
232 String str = sb.toString();
233 switch (str) {
234 case "\\s":
235 str = "[" + Lexer.getWhitespaceRegExp() + "]";
236 break;
237 case "\\S":
238 str = "[^" + Lexer.getWhitespaceRegExp() + "]";
239 break;
240 case "[^]":
241 str = "[\\s\\S]";
242 break;
243 default:
244 break;
245 }
246 return str;
247 }
248 }
249
250 /**
251 * Token iterator. Doesn't return "atom" children. i.e. string representations,
252 * just tokens
253 *
254 */
255 private static class TokenIterator implements Iterator<Token> {
256 private final List<Token> preorder;
257
258 private void init(final Token root) {
259 preorder.add(root);
260 for (final Object child : root.getChildren()) {
261 if (child instanceof Token) {
262 init((Token)child);
263 }
264 }
|
213
214 return Token.unicode(value);
215 }
216 });
217
218 }
219
220 /**
221 * JavaScript Token to Java regex substring framework.
222 *
223 */
224 private static class ToString {
225 String toString(final Token token) {
226 final StringBuilder sb = new StringBuilder();
227 for (final Object child : token.getChildren()) {
228 sb.append(child);
229 }
230
231 //perform global substitutions that hold true for any evaluated form
232 String str = sb.toString();
233 if (str.equals("[^]")) {
234 str = "[\\s\\S]";
235 }
236 return str;
237 }
238 }
239
240 /**
241 * Token iterator. Doesn't return "atom" children. i.e. string representations,
242 * just tokens
243 *
244 */
245 private static class TokenIterator implements Iterator<Token> {
246 private final List<Token> preorder;
247
248 private void init(final Token root) {
249 preorder.add(root);
250 for (final Object child : root.getChildren()) {
251 if (child instanceof Token) {
252 init((Token)child);
253 }
254 }
|