0001: /* Generated By:JavaCC: Do not edit this line. HTMLParser.java */
0002: // package com.tchibo.misc.lucene;
0003: package vqwiki.utils.lucene;
0004:
0005: import java.io.*;
0006:
0007: /**
0008: * TODO: Document this class.
0009: *
0010: * @version $Id: HTMLParser.java 622 2006-04-18 07:33:12Z wrh2 $
0011: */
0012: public class HTMLParser implements HTMLParserConstants {
0013: /**
0014: * TODO: Document this field.
0015: */
0016: public static int SUMMARY_LENGTH = 200;
0017: /**
0018: * TODO: Document this field.
0019: */
0020: boolean afterSpace = false;
0021: /**
0022: * TODO: Document this field.
0023: */
0024: boolean afterTag = false;
0025: /**
0026: * TODO: Document this field.
0027: */
0028: String eol = System.getProperty("line.separator");
0029: /**
0030: * TODO: Document this field.
0031: */
0032: boolean inScript = false;
0033: /**
0034: * TODO: Document this field.
0035: */
0036: boolean inTitle = false;
0037: /**
0038: * TODO: Document this field.
0039: */
0040: private final JJCalls[] jj_2_rtns = new JJCalls[2];
0041: /**
0042: * TODO: Document this field.
0043: */
0044: private int jj_endpos;
0045:
0046: /**
0047: * TODO: Document this field.
0048: */
0049: private java.util.Vector jj_expentries = new java.util.Vector();
0050: /**
0051: * TODO: Document this field.
0052: */
0053: private int[] jj_expentry;
0054: /**
0055: * TODO: Document this field.
0056: */
0057: private int jj_gc = 0;
0058: /**
0059: * TODO: Document this field.
0060: */
0061: private int jj_gen;
0062: /**
0063: * TODO: Document this field.
0064: */
0065: SimpleCharStream jj_input_stream;
0066: /**
0067: * TODO: Document this field.
0068: */
0069: private int jj_kind = -1;
0070: /**
0071: * TODO: Document this field.
0072: */
0073: private int jj_la;
0074: /**
0075: * TODO: Document this field.
0076: */
0077: private final int[] jj_la1 = new int[13];
0078: /**
0079: * TODO: Document this field.
0080: */
0081: private final int[] jj_la1_0 = { 0xb3e, 0xb3e, 0x1000, 0x38000,
0082: 0x2000, 0x8000, 0x10000, 0x20000, 0x3b000, 0x3b000,
0083: 0x800000, 0x2000000, 0x18, };
0084: /**
0085: * TODO: Document this field.
0086: */
0087: private int[] jj_lasttokens = new int[100];
0088: /**
0089: * TODO: Document this field.
0090: */
0091: private int jj_ntk;
0092: /**
0093: * TODO: Document this field.
0094: */
0095: private boolean jj_rescan = false;
0096: /**
0097: * TODO: Document this field.
0098: */
0099: private Token jj_scanpos, jj_lastpos;
0100: /**
0101: * TODO: Document this field.
0102: */
0103: private boolean jj_semLA;
0104: /**
0105: * TODO: Document this field.
0106: */
0107: int length = 0;
0108: /**
0109: * TODO: Document this field.
0110: */
0111: public boolean lookingAhead = false;
0112: /**
0113: * TODO: Document this field.
0114: */
0115: PipedReader pipeIn = null;
0116: /**
0117: * TODO: Document this field.
0118: */
0119: PipedWriter pipeOut;
0120: /**
0121: * TODO: Document this field.
0122: */
0123: StringBuffer summary = new StringBuffer(SUMMARY_LENGTH * 2);
0124:
0125: /**
0126: * TODO: Document this field.
0127: */
0128: StringBuffer title = new StringBuffer(SUMMARY_LENGTH);
0129: /**
0130: * TODO: Document this field.
0131: */
0132: boolean titleComplete = false;
0133: /**
0134: * TODO: Document this field.
0135: */
0136: public Token token, jj_nt;
0137:
0138: /**
0139: * TODO: Document this field.
0140: */
0141: public HTMLParserTokenManager token_source;
0142:
0143: /**
0144: *Creates a new HTMLParser.
0145: *
0146: * @param file TODO: Document this parameter.
0147: * @exception FileNotFoundException TODO: Document this exception.
0148: */
0149: public HTMLParser(File file) throws FileNotFoundException {
0150: this (new FileInputStream(file));
0151: }
0152:
0153: /**
0154: *Creates a new HTMLParser.
0155: *
0156: * @param stream TODO: Document this parameter.
0157: */
0158: public HTMLParser(java.io.InputStream stream) {
0159: jj_input_stream = new SimpleCharStream(stream, 1, 1);
0160: token_source = new HTMLParserTokenManager(jj_input_stream);
0161: token = new Token();
0162: jj_ntk = -1;
0163: jj_gen = 0;
0164: for (int i = 0; i < 13; i++) {
0165: jj_la1[i] = -1;
0166: }
0167: for (int i = 0; i < jj_2_rtns.length; i++) {
0168: jj_2_rtns[i] = new JJCalls();
0169: }
0170: }
0171:
0172: /**
0173: *Creates a new HTMLParser.
0174: *
0175: * @param stream TODO: Document this parameter.
0176: */
0177: public HTMLParser(java.io.Reader stream) {
0178: jj_input_stream = new SimpleCharStream(stream, 1, 1);
0179: token_source = new HTMLParserTokenManager(jj_input_stream);
0180: token = new Token();
0181: jj_ntk = -1;
0182: jj_gen = 0;
0183: for (int i = 0; i < 13; i++) {
0184: jj_la1[i] = -1;
0185: }
0186: for (int i = 0; i < jj_2_rtns.length; i++) {
0187: jj_2_rtns[i] = new JJCalls();
0188: }
0189: }
0190:
0191: /**
0192: *Creates a new HTMLParser.
0193: *
0194: * @param tm TODO: Document this parameter.
0195: */
0196: public HTMLParser(HTMLParserTokenManager tm) {
0197: token_source = tm;
0198: token = new Token();
0199: jj_ntk = -1;
0200: jj_gen = 0;
0201: for (int i = 0; i < 13; i++) {
0202: jj_la1[i] = -1;
0203: }
0204: for (int i = 0; i < jj_2_rtns.length; i++) {
0205: jj_2_rtns[i] = new JJCalls();
0206: }
0207: }
0208:
0209: /**
0210: * TODO: Document this method.
0211: *
0212: * @return TODO: Document the result.
0213: * @exception ParseException TODO: Document this exception.
0214: */
0215: public final Token ArgValue() throws ParseException {
0216: Token t = null;
0217: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0218: case ArgValue:
0219: t = jj_consume_token(ArgValue);
0220: {
0221: if (true) {
0222: return t;
0223: }
0224: }
0225: break;
0226: default:
0227: jj_la1[5] = jj_gen;
0228: if (jj_2_1(2)) {
0229: jj_consume_token(ArgQuote1);
0230: jj_consume_token(CloseQuote1);
0231: {
0232: if (true) {
0233: return t;
0234: }
0235: }
0236: } else {
0237: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0238: case ArgQuote1:
0239: jj_consume_token(ArgQuote1);
0240: t = jj_consume_token(Quote1Text);
0241: jj_consume_token(CloseQuote1);
0242: {
0243: if (true) {
0244: return t;
0245: }
0246: }
0247: break;
0248: default:
0249: jj_la1[6] = jj_gen;
0250: if (jj_2_2(2)) {
0251: jj_consume_token(ArgQuote2);
0252: jj_consume_token(CloseQuote2);
0253: {
0254: if (true) {
0255: return t;
0256: }
0257: }
0258: } else {
0259: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0260: case ArgQuote2:
0261: jj_consume_token(ArgQuote2);
0262: t = jj_consume_token(Quote2Text);
0263: jj_consume_token(CloseQuote2);
0264: {
0265: if (true) {
0266: return t;
0267: }
0268: }
0269: break;
0270: default:
0271: jj_la1[7] = jj_gen;
0272: jj_consume_token(-1);
0273: throw new ParseException();
0274: }
0275: }
0276: }
0277: }
0278: }
0279: throw new Error("Missing return statement in function");
0280: }
0281:
0282: /**
0283: * TODO: Document this method.
0284: *
0285: * @exception ParseException TODO: Document this exception.
0286: */
0287: public final void CommentTag() throws ParseException {
0288: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0289: case Comment1:
0290: jj_consume_token(Comment1);
0291: label_4: while (true) {
0292: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0293: case CommentText1:
0294: ;
0295: break;
0296: default:
0297: jj_la1[10] = jj_gen;
0298: break label_4;
0299: }
0300: jj_consume_token(CommentText1);
0301: }
0302: jj_consume_token(CommentEnd1);
0303: break;
0304: case Comment2:
0305: jj_consume_token(Comment2);
0306: label_5: while (true) {
0307: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0308: case CommentText2:
0309: ;
0310: break;
0311: default:
0312: jj_la1[11] = jj_gen;
0313: break label_5;
0314: }
0315: jj_consume_token(CommentText2);
0316: }
0317: jj_consume_token(CommentEnd2);
0318: break;
0319: default:
0320: jj_la1[12] = jj_gen;
0321: jj_consume_token(-1);
0322: throw new ParseException();
0323: }
0324: }
0325:
0326: /**
0327: * TODO: Document this method.
0328: *
0329: * @return TODO: Document the result.
0330: * @exception ParseException TODO: Document this exception.
0331: */
0332: public final Token Decl() throws ParseException {
0333: Token t;
0334: t = jj_consume_token(DeclName);
0335: label_3: while (true) {
0336: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0337: case ArgName:
0338: case ArgEquals:
0339: case ArgValue:
0340: case ArgQuote1:
0341: case ArgQuote2:
0342: ;
0343: break;
0344: default:
0345: jj_la1[8] = jj_gen;
0346: break label_3;
0347: }
0348: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0349: case ArgName:
0350: jj_consume_token(ArgName);
0351: break;
0352: case ArgValue:
0353: case ArgQuote1:
0354: case ArgQuote2:
0355: ArgValue();
0356: break;
0357: case ArgEquals:
0358: jj_consume_token(ArgEquals);
0359: break;
0360: default:
0361: jj_la1[9] = jj_gen;
0362: jj_consume_token(-1);
0363: throw new ParseException();
0364: }
0365: }
0366: jj_consume_token(TagEnd);
0367: {
0368: if (true) {
0369: return t;
0370: }
0371: }
0372: throw new Error("Missing return statement in function");
0373: }
0374:
0375: /**
0376: * TODO: Document this method.
0377: *
0378: * @exception ParseException TODO: Document this exception.
0379: * @exception IOException TODO: Document this exception.
0380: */
0381: public final void HTMLDocument() throws ParseException, IOException {
0382: Token t;
0383: label_1: while (true) {
0384: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0385: case TagName:
0386: case DeclName:
0387: case Comment1:
0388: case Comment2:
0389: case Word:
0390: case Entity:
0391: case Space:
0392: case Punct:
0393: ;
0394: break;
0395: default:
0396: jj_la1[0] = jj_gen;
0397: break label_1;
0398: }
0399: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0400: case TagName:
0401: Tag();
0402: afterTag = true;
0403: break;
0404: case DeclName:
0405: t = Decl();
0406: afterTag = true;
0407: break;
0408: case Comment1:
0409: case Comment2:
0410: CommentTag();
0411: afterTag = true;
0412: break;
0413: case Word:
0414: t = jj_consume_token(Word);
0415: addText(t.image);
0416: afterTag = false;
0417: break;
0418: case Entity:
0419: t = jj_consume_token(Entity);
0420: addText(Entities.decode(t.image));
0421: afterTag = false;
0422: break;
0423: case Punct:
0424: t = jj_consume_token(Punct);
0425: addText(t.image);
0426: afterTag = false;
0427: break;
0428: case Space:
0429: jj_consume_token(Space);
0430: addSpace();
0431: afterTag = false;
0432: break;
0433: default:
0434: jj_la1[1] = jj_gen;
0435: jj_consume_token(-1);
0436: throw new ParseException();
0437: }
0438: }
0439: jj_consume_token(0);
0440: }
0441:
0442: /**
0443: * TODO: Document this method.
0444: *
0445: * @param stream TODO: Document this parameter.
0446: */
0447: public void ReInit(java.io.InputStream stream) {
0448: jj_input_stream.ReInit(stream, 1, 1);
0449: token_source.ReInit(jj_input_stream);
0450: token = new Token();
0451: jj_ntk = -1;
0452: jj_gen = 0;
0453: for (int i = 0; i < 13; i++) {
0454: jj_la1[i] = -1;
0455: }
0456: for (int i = 0; i < jj_2_rtns.length; i++) {
0457: jj_2_rtns[i] = new JJCalls();
0458: }
0459: }
0460:
0461: /**
0462: * TODO: Document this method.
0463: *
0464: * @param stream TODO: Document this parameter.
0465: */
0466: public void ReInit(java.io.Reader stream) {
0467: jj_input_stream.ReInit(stream, 1, 1);
0468: token_source.ReInit(jj_input_stream);
0469: token = new Token();
0470: jj_ntk = -1;
0471: jj_gen = 0;
0472: for (int i = 0; i < 13; i++) {
0473: jj_la1[i] = -1;
0474: }
0475: for (int i = 0; i < jj_2_rtns.length; i++) {
0476: jj_2_rtns[i] = new JJCalls();
0477: }
0478: }
0479:
0480: /**
0481: * TODO: Document this method.
0482: *
0483: * @param tm TODO: Document this parameter.
0484: */
0485: public void ReInit(HTMLParserTokenManager tm) {
0486: token_source = tm;
0487: token = new Token();
0488: jj_ntk = -1;
0489: jj_gen = 0;
0490: for (int i = 0; i < 13; i++) {
0491: jj_la1[i] = -1;
0492: }
0493: for (int i = 0; i < jj_2_rtns.length; i++) {
0494: jj_2_rtns[i] = new JJCalls();
0495: }
0496: }
0497:
0498: /**
0499: * TODO: Document this method.
0500: *
0501: * @exception ParseException TODO: Document this exception.
0502: * @exception IOException TODO: Document this exception.
0503: */
0504: public final void Tag() throws ParseException, IOException {
0505: Token t1;
0506: Token t2;
0507: boolean inImg = false;
0508: t1 = jj_consume_token(TagName);
0509: inTitle = t1.image.equalsIgnoreCase("<title");
0510: // keep track if in <TITLE>
0511: inImg = t1.image.equalsIgnoreCase("<img");
0512: // keep track if in <IMG>
0513: if (inScript) {
0514: // keep track if in <SCRIPT>
0515: inScript = !t1.image.equalsIgnoreCase("</script");
0516: } else {
0517: inScript = t1.image.equalsIgnoreCase("<script");
0518: }
0519: label_2: while (true) {
0520: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0521: case ArgName:
0522: ;
0523: break;
0524: default:
0525: jj_la1[2] = jj_gen;
0526: break label_2;
0527: }
0528: t1 = jj_consume_token(ArgName);
0529: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0530: case ArgEquals:
0531: jj_consume_token(ArgEquals);
0532: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0533: case ArgValue:
0534: case ArgQuote1:
0535: case ArgQuote2:
0536: t2 = ArgValue();
0537: if (inImg && t1.image.equalsIgnoreCase("alt")
0538: && t2 != null) {
0539: addText("[" + t2.image + "]");
0540: }
0541: break;
0542: default:
0543: jj_la1[3] = jj_gen;
0544: ;
0545: }
0546: break;
0547: default:
0548: jj_la1[4] = jj_gen;
0549: ;
0550: }
0551: }
0552: jj_consume_token(TagEnd);
0553: }
0554:
0555: /**
0556: * Adds a feature to the Space.
0557: *
0558: * @exception IOException TODO: Document this exception.
0559: */
0560: void addSpace() throws IOException {
0561: if (inScript) {
0562: return;
0563: }
0564: if (!afterSpace) {
0565: if (inTitle) {
0566: title.append(" ");
0567: } else {
0568: addToSummary(" ");
0569: }
0570:
0571: String space = afterTag ? eol : " ";
0572: length += space.length();
0573: pipeOut.write(space);
0574: afterSpace = true;
0575: }
0576: }
0577:
0578: /**
0579: * Adds a feature to the Text.
0580: *
0581: * @param text The feature to be added.
0582: * @exception IOException TODO: Document this exception.
0583: */
0584: void addText(String text) throws IOException {
0585: if (inScript) {
0586: return;
0587: }
0588: if (inTitle) {
0589: title.append(text);
0590: } else {
0591: addToSummary(text);
0592: if (!titleComplete && !title.equals("")) {
0593: // finished title
0594: synchronized (this ) {
0595: titleComplete = true;
0596: // tell waiting threads
0597: notifyAll();
0598: }
0599: }
0600: }
0601:
0602: length += text.length();
0603: pipeOut.write(text);
0604:
0605: afterSpace = false;
0606: }
0607:
0608: /**
0609: * Adds a feature to the ToSummary.
0610: *
0611: * @param text The feature to be added.
0612: */
0613: void addToSummary(String text) {
0614: if (summary.length() < SUMMARY_LENGTH) {
0615: summary.append(text);
0616: if (summary.length() >= SUMMARY_LENGTH) {
0617: synchronized (this ) {
0618: notifyAll();
0619: }
0620: }
0621: }
0622: }
0623:
0624: /**
0625: * TODO: Document this method.
0626: */
0627: public final void disable_tracing() {
0628: }
0629:
0630: /**
0631: * TODO: Document this method.
0632: */
0633: public final void enable_tracing() {
0634: }
0635:
0636: /**
0637: * TODO: Document this method.
0638: *
0639: * @return TODO: Document the result.
0640: */
0641: public final ParseException generateParseException() {
0642: jj_expentries.removeAllElements();
0643: boolean[] la1tokens = new boolean[27];
0644: for (int i = 0; i < 27; i++) {
0645: la1tokens[i] = false;
0646: }
0647: if (jj_kind >= 0) {
0648: la1tokens[jj_kind] = true;
0649: jj_kind = -1;
0650: }
0651: for (int i = 0; i < 13; i++) {
0652: if (jj_la1[i] == jj_gen) {
0653: for (int j = 0; j < 32; j++) {
0654: if ((jj_la1_0[i] & (1 << j)) != 0) {
0655: la1tokens[j] = true;
0656: }
0657: }
0658: }
0659: }
0660: for (int i = 0; i < 27; i++) {
0661: if (la1tokens[i]) {
0662: jj_expentry = new int[1];
0663: jj_expentry[0] = i;
0664: jj_expentries.addElement(jj_expentry);
0665: }
0666: }
0667: jj_endpos = 0;
0668: jj_rescan_token();
0669: jj_add_error_token(0, 0);
0670: int[][] exptokseq = new int[jj_expentries.size()][];
0671: for (int i = 0; i < jj_expentries.size(); i++) {
0672: exptokseq[i] = (int[]) jj_expentries.elementAt(i);
0673: }
0674: return new ParseException(token, exptokseq, tokenImage);
0675: }
0676:
0677: /**
0678: * Returns the NextToken.
0679: *
0680: * @return The NextToken.
0681: */
0682: public final Token getNextToken() {
0683: if (token.next != null) {
0684: token = token.next;
0685: } else {
0686: token = token.next = token_source.getNextToken();
0687: }
0688: jj_ntk = -1;
0689: jj_gen++;
0690: return token;
0691: }
0692:
0693: /**
0694: * Returns the Reader.
0695: *
0696: * @return The Reader.
0697: * @exception IOException TODO: Document this exception.
0698: */
0699: public Reader getReader() throws IOException {
0700: if (pipeIn == null) {
0701: pipeIn = new PipedReader();
0702: pipeOut = new PipedWriter(pipeIn);
0703:
0704: Thread thread = new ParserThread(this );
0705: thread.start();
0706: // start parsing
0707: }
0708:
0709: return pipeIn;
0710: }
0711:
0712: /**
0713: * Returns the Summary.
0714: *
0715: * @return The Summary.
0716: * @exception IOException TODO: Document this exception.
0717: * @exception InterruptedException TODO: Document this exception.
0718: */
0719: public String getSummary() throws IOException, InterruptedException {
0720: if (pipeIn == null) {
0721: getReader();
0722: }
0723: // spawn parsing thread
0724: while (true) {
0725: synchronized (this ) {
0726: if (summary.length() >= SUMMARY_LENGTH) {
0727: break;
0728: }
0729: wait(10);
0730: }
0731: }
0732: if (summary.length() > SUMMARY_LENGTH) {
0733: summary.setLength(SUMMARY_LENGTH);
0734: }
0735:
0736: String sum = summary.toString().trim();
0737: String tit = getTitle();
0738: if (sum.startsWith(tit)) {
0739: return sum.substring(tit.length());
0740: } else {
0741: return sum;
0742: }
0743: }
0744:
0745: /**
0746: * Returns the Title.
0747: *
0748: * @return The Title.
0749: * @exception IOException TODO: Document this exception.
0750: * @exception InterruptedException TODO: Document this exception.
0751: */
0752: public String getTitle() throws IOException, InterruptedException {
0753: if (pipeIn == null) {
0754: getReader();
0755: }
0756: // spawn parsing thread
0757: while (true) {
0758: synchronized (this ) {
0759: if (titleComplete || (length > SUMMARY_LENGTH)) {
0760: break;
0761: }
0762: wait(10);
0763: }
0764: }
0765: return title.toString().trim();
0766: }
0767:
0768: /**
0769: * Returns the Token.
0770: *
0771: * @param index TODO: Document this parameter.
0772: * @return The Token.
0773: */
0774: public final Token getToken(int index) {
0775: Token t = lookingAhead ? jj_scanpos : token;
0776: for (int i = 0; i < index; i++) {
0777: if (t.next != null) {
0778: t = t.next;
0779: } else {
0780: t = t.next = token_source.getNextToken();
0781: }
0782: }
0783: return t;
0784: }
0785:
0786: /**
0787: * TODO: Document this method.
0788: *
0789: * @param xla TODO: Document this parameter.
0790: * @return TODO: Document the result.
0791: */
0792: private final boolean jj_2_1(int xla) {
0793: jj_la = xla;
0794: jj_lastpos = jj_scanpos = token;
0795: boolean retval = !jj_3_1();
0796: jj_save(0, xla);
0797: return retval;
0798: }
0799:
0800: /**
0801: * TODO: Document this method.
0802: *
0803: * @param xla TODO: Document this parameter.
0804: * @return TODO: Document the result.
0805: */
0806: private final boolean jj_2_2(int xla) {
0807: jj_la = xla;
0808: jj_lastpos = jj_scanpos = token;
0809: boolean retval = !jj_3_2();
0810: jj_save(1, xla);
0811: return retval;
0812: }
0813:
0814: /**
0815: * TODO: Document this method.
0816: *
0817: * @return TODO: Document the result.
0818: */
0819: private final boolean jj_3_1() {
0820: if (jj_scan_token(ArgQuote1)) {
0821: return true;
0822: }
0823: if (jj_la == 0 && jj_scanpos == jj_lastpos) {
0824: return false;
0825: }
0826: if (jj_scan_token(CloseQuote1)) {
0827: return true;
0828: }
0829: if (jj_la == 0 && jj_scanpos == jj_lastpos) {
0830: return false;
0831: }
0832: return false;
0833: }
0834:
0835: /**
0836: * TODO: Document this method.
0837: *
0838: * @return TODO: Document the result.
0839: */
0840: private final boolean jj_3_2() {
0841: if (jj_scan_token(ArgQuote2)) {
0842: return true;
0843: }
0844: if (jj_la == 0 && jj_scanpos == jj_lastpos) {
0845: return false;
0846: }
0847: if (jj_scan_token(CloseQuote2)) {
0848: return true;
0849: }
0850: if (jj_la == 0 && jj_scanpos == jj_lastpos) {
0851: return false;
0852: }
0853: return false;
0854: }
0855:
0856: /**
0857: * TODO: Document this method.
0858: *
0859: * @param kind TODO: Document this parameter.
0860: * @param pos TODO: Document this parameter.
0861: */
0862: private void jj_add_error_token(int kind, int pos) {
0863: if (pos >= 100) {
0864: return;
0865: }
0866: if (pos == jj_endpos + 1) {
0867: jj_lasttokens[jj_endpos++] = kind;
0868: } else if (jj_endpos != 0) {
0869: jj_expentry = new int[jj_endpos];
0870: for (int i = 0; i < jj_endpos; i++) {
0871: jj_expentry[i] = jj_lasttokens[i];
0872: }
0873: boolean exists = false;
0874: for (java.util.Enumeration jjenum = jj_expentries
0875: .elements(); jjenum.hasMoreElements();) {
0876: int[] oldentry = (int[]) (jjenum.nextElement());
0877: if (oldentry.length == jj_expentry.length) {
0878: exists = true;
0879: for (int i = 0; i < jj_expentry.length; i++) {
0880: if (oldentry[i] != jj_expentry[i]) {
0881: exists = false;
0882: break;
0883: }
0884: }
0885: if (exists) {
0886: break;
0887: }
0888: }
0889: }
0890: if (!exists) {
0891: jj_expentries.addElement(jj_expentry);
0892: }
0893: if (pos != 0) {
0894: jj_lasttokens[(jj_endpos = pos) - 1] = kind;
0895: }
0896: }
0897: }
0898:
0899: /**
0900: * TODO: Document this method.
0901: *
0902: * @param kind TODO: Document this parameter.
0903: * @return TODO: Document the result.
0904: * @exception ParseException TODO: Document this exception.
0905: */
0906: private final Token jj_consume_token(int kind)
0907: throws ParseException {
0908: Token oldToken;
0909: if ((oldToken = token).next != null) {
0910: token = token.next;
0911: } else {
0912: token = token.next = token_source.getNextToken();
0913: }
0914: jj_ntk = -1;
0915: if (token.kind == kind) {
0916: jj_gen++;
0917: if (++jj_gc > 100) {
0918: jj_gc = 0;
0919: for (int i = 0; i < jj_2_rtns.length; i++) {
0920: JJCalls c = jj_2_rtns[i];
0921: while (c != null) {
0922: if (c.gen < jj_gen) {
0923: c.first = null;
0924: }
0925: c = c.next;
0926: }
0927: }
0928: }
0929: return token;
0930: }
0931: token = oldToken;
0932: jj_kind = kind;
0933: throw generateParseException();
0934: }
0935:
0936: /**
0937: * TODO: Document this method.
0938: *
0939: * @return TODO: Document the result.
0940: */
0941: private final int jj_ntk() {
0942: if ((jj_nt = token.next) == null) {
0943: return (jj_ntk = (token.next = token_source.getNextToken()).kind);
0944: } else {
0945: return (jj_ntk = jj_nt.kind);
0946: }
0947: }
0948:
0949: /**
0950: * TODO: Document this method.
0951: */
0952: private final void jj_rescan_token() {
0953: jj_rescan = true;
0954: for (int i = 0; i < 2; i++) {
0955: JJCalls p = jj_2_rtns[i];
0956: do {
0957: if (p.gen > jj_gen) {
0958: jj_la = p.arg;
0959: jj_lastpos = jj_scanpos = p.first;
0960: switch (i) {
0961: case 0:
0962: jj_3_1();
0963: break;
0964: case 1:
0965: jj_3_2();
0966: break;
0967: }
0968: }
0969: p = p.next;
0970: } while (p != null);
0971: }
0972: jj_rescan = false;
0973: }
0974:
0975: /**
0976: * TODO: Document this method.
0977: *
0978: * @param index TODO: Document this parameter.
0979: * @param xla TODO: Document this parameter.
0980: */
0981: private final void jj_save(int index, int xla) {
0982: JJCalls p = jj_2_rtns[index];
0983: while (p.gen > jj_gen) {
0984: if (p.next == null) {
0985: p = p.next = new JJCalls();
0986: break;
0987: }
0988: p = p.next;
0989: }
0990: p.gen = jj_gen + xla - jj_la;
0991: p.first = token;
0992: p.arg = xla;
0993: }
0994:
0995: /**
0996: * TODO: Document this method.
0997: *
0998: * @param kind TODO: Document this parameter.
0999: * @return TODO: Document the result.
1000: */
1001: private final boolean jj_scan_token(int kind) {
1002: if (jj_scanpos == jj_lastpos) {
1003: jj_la--;
1004: if (jj_scanpos.next == null) {
1005: jj_lastpos = jj_scanpos = jj_scanpos.next = token_source
1006: .getNextToken();
1007: } else {
1008: jj_lastpos = jj_scanpos = jj_scanpos.next;
1009: }
1010: } else {
1011: jj_scanpos = jj_scanpos.next;
1012: }
1013: if (jj_rescan) {
1014: int i = 0;
1015: Token tok = token;
1016: while (tok != null && tok != jj_scanpos) {
1017: i++;
1018: tok = tok.next;
1019: }
1020: if (tok != null) {
1021: jj_add_error_token(kind, i);
1022: }
1023: }
1024: return (jj_scanpos.kind != kind);
1025: }
1026:
1027: /**
1028: * TODO: Document this class.
1029: *
1030: * @version $Id: HTMLParser.java 622 2006-04-18 07:33:12Z wrh2 $
1031: */
1032: final static class JJCalls {
1033: /**
1034: * TODO: Document this field.
1035: */
1036: int arg;
1037: /**
1038: * TODO: Document this field.
1039: */
1040: Token first;
1041: /**
1042: * TODO: Document this field.
1043: */
1044: int gen;
1045: /**
1046: * TODO: Document this field.
1047: */
1048: JJCalls next;
1049: }
1050: }
|