p.mark();
// If we have '/*', it's a comment till '*/' found or eof
if (p.peek() == '*') {
- StringBuffer value = new StringBuffer();
- c = p.getNext();
- value.append('/');
- while (!( c == '*' && p.peek() == '/' ) && !p.isDone()) {
- value.append(c);
- c = p.getNext();
- }
- if (!p.isDone()){
- value.append(c);
- c = p.getNext();
- value.append(c);
- }
- tokens.addElement(new Token(Token.COMMENT, value.toString(), offset, offset + value.length()));
+ tokens.addElement(tokenizeComment(p, offset));
} else {
// It's not '/*' , so it's a group token
- tokens.addElement(new Token(Token.GROUP, group, offset, offset + 1));
+ // BCH ??? what's this business about groups?
+ // Shouldn't '/' be a divide operator?
+ tokens.addElement(new Token(Token.SYMBOL, new String(new char[] {c}) /*group*/, offset, offset + 1));
p.reset();
}
// Adds SYMBOL token;
// }
return tokens;
}
+ /**
+ * @param tokens
+ * @param p
+ * @param offset
+ */
+ private static Token tokenizeComment(StringPointer p, int offset) {
+ char c;
+ StringBuffer value = new StringBuffer();
+ c = p.getNext();
+ value.append('/');
+ while (!( c == '*' && p.peek() == '/' ) && !p.isDone()) {
+ value.append(c);
+ c = p.getNext();
+ }
+ if (!p.isDone()){
+ value.append(c);
+ c = p.getNext();
+ value.append(c);
+ }
+ return new Token(Token.COMMENT, value.toString(), offset, offset + value.length());
+ }
}