001: /* Generated By:JavaCC: Do not edit this line. ArchiveParser.java */
002: package org.apache.commons.jrcs.rcs;
003:
004: import java.util.Map;
005: import java.io.FileInputStream;
006: import java.io.FileNotFoundException;
007: import java.io.InputStream;
008:
009: /**
010: * Parses an RCS/CVS style version control archive into an Archive.
011: * This class is NOT thread safe.
012: *
013: * @author <a href="mailto:juanco@suigeneris.org">Juanco Anez</a>
014: * @version $Revision: 2967 $ $Date: 2005-10-26 06:52:33 -0400 (Wed, 26 Oct 2005) $
015: * @see Archive
016: */
017: class ArchiveParser implements ArchiveParserConstants {
018:
019: static final String ident = "RCS ArchiveParser Parser $version$:";
020:
021: public static void main(String args[]) {
022: ArchiveParser parser;
023: if (args.length == 0) {
024: System.out.println(ident
025: + " Reading from standard input . . .");
026: parser = new ArchiveParser(System.in);
027: } else if (args.length == 1) {
028: System.out.println(ident + " Reading from file " + args[0]
029: + " . . .");
030: try {
031: parser = new ArchiveParser(new FileInputStream(args[0]));
032: } catch (java.io.FileNotFoundException e) {
033: System.out.println(ident + " File " + args[0]
034: + " not found.");
035: return;
036: }
037: } else {
038: System.out.println(ident + " Usage is one of:");
039: System.out
040: .println(" java ArchiveParser < inputfile");
041: System.out.println("OR");
042: System.out.println(" java ArchiveParser inputfile");
043: return;
044: }
045: parser.parse();
046: }
047:
048: public static void load(Archive arc, InputStream input)
049: throws ParseException {
050: ArchiveParser parser = new ArchiveParser(input);
051: parser.archive(arc);
052: }
053:
054: public static void load(Archive arc, String fname)
055: throws FileNotFoundException, ParseException {
056: load(arc, new FileInputStream(fname));
057: }
058:
059: public void parse() {
060: try {
061: archive(null);
062: System.out
063: .println("RCS ArchiveParser Parser version 1.1: RCS ArchiveParser parsed successfully.");
064: } catch (ParseException e) {
065: System.out
066: .println("RCS ArchiveParser Parser version 1.1: Encountered errors during parse.");
067: }
068: }
069:
070: /**
071: * PARSER STARTS HERE
072: */
073: final public void archive(Archive arc) throws ParseException {
074: admin(arc);
075: label_1: while (true) {
076: switch (jj_nt.kind) {
077: case NUM:
078: ;
079: break;
080: default:
081: break label_1;
082: }
083: delta(arc);
084: }
085: desc(arc);
086: label_2: while (true) {
087: switch (jj_nt.kind) {
088: case NUM:
089: ;
090: break;
091: default:
092: break label_2;
093: }
094: text(arc);
095: }
096: jj_consume_token(0);
097: }
098:
099: final public void admin(Archive arc) throws ParseException {
100: head(arc);
101: switch (jj_nt.kind) {
102: case BRANCH:
103: branch(arc);
104: break;
105: default:
106: ;
107: }
108: access(arc);
109: symbols(arc);
110: locks(arc);
111: optionals(arc);
112: }
113:
114: final public void optionals(Archive arc) throws ParseException {
115: label_3: while (true) {
116: switch (jj_nt.kind) {
117: case COMMENT:
118: case EXPAND:
119: case ID:
120: ;
121: break;
122: default:
123: break label_3;
124: }
125: switch (jj_nt.kind) {
126: case COMMENT:
127: comment(arc);
128: break;
129: case EXPAND:
130: expand(arc);
131: break;
132: case ID:
133: newPhrase(arc.phrases);
134: break;
135: default:
136: jj_consume_token(-1);
137: throw new ParseException();
138: }
139: }
140: }
141:
142: final public void newPhrases(Map map) throws ParseException {
143: label_4: while (true) {
144: switch (jj_nt.kind) {
145: case ID:
146: ;
147: break;
148: default:
149: break label_4;
150: }
151: newPhrase(map);
152: }
153: }
154:
155: final public void head(Archive arc) throws ParseException {
156: Version v;
157: jj_consume_token(HEAD);
158: switch (jj_nt.kind) {
159: case NUM:
160: v = version();
161: arc.setHead(v);
162: break;
163: default:
164: ;
165: }
166: jj_consume_token(28);
167: }
168:
169: final public void branch(Archive arc) throws ParseException {
170: Version v;
171: jj_consume_token(BRANCH);
172: switch (jj_nt.kind) {
173: case NUM:
174: v = version();
175: arc.setBranch(v);
176: break;
177: default:
178: ;
179: }
180: jj_consume_token(28);
181: }
182:
183: final public void access(Archive arc) throws ParseException {
184: String name;
185: jj_consume_token(ACCESS);
186: label_5: while (true) {
187: switch (jj_nt.kind) {
188: case ID:
189: ;
190: break;
191: default:
192: break label_5;
193: }
194: name = id();
195: arc.addUser(name);
196: }
197: jj_consume_token(28);
198: }
199:
200: final public void symbols(Archive arc) throws ParseException {
201: String s;
202: Version v;
203: jj_consume_token(SYMBOLS);
204: label_6: while (true) {
205: switch (jj_nt.kind) {
206: case ID:
207: case SYM:
208: ;
209: break;
210: default:
211: break label_6;
212: }
213: s = sym();
214: jj_consume_token(29);
215: v = version();
216: arc.addSymbol(s, v);
217: }
218: jj_consume_token(28);
219: }
220:
221: final public void locks(Archive arc) throws ParseException {
222: String name;
223: Version v;
224: jj_consume_token(LOCKS);
225: label_7: while (true) {
226: switch (jj_nt.kind) {
227: case ID:
228: ;
229: break;
230: default:
231: break label_7;
232: }
233: name = id();
234: jj_consume_token(29);
235: v = version();
236: arc.addLock(name, v);
237: }
238: jj_consume_token(28);
239: switch (jj_nt.kind) {
240: case STRICT:
241: jj_consume_token(STRICT);
242: jj_consume_token(28);
243: arc.setStrictLocking(true);
244: break;
245: default:
246: ;
247: }
248: }
249:
250: final public void comment(Archive arc) throws ParseException {
251: String s;
252: jj_consume_token(COMMENT);
253: switch (jj_nt.kind) {
254: case STRING:
255: s = string();
256: arc.setComment(s);
257: break;
258: default:
259: ;
260: }
261: jj_consume_token(28);
262: }
263:
264: final public void expand(Archive arc) throws ParseException {
265: String s;
266: jj_consume_token(EXPAND);
267: switch (jj_nt.kind) {
268: case STRING:
269: s = string();
270: arc.setExpand(s);
271: break;
272: default:
273: ;
274: }
275: jj_consume_token(28);
276: }
277:
278: final public void newPhrase(Map map) throws ParseException {
279: String key;
280: String value;
281: StringBuffer values = new StringBuffer();
282: key = id();
283: label_8: while (true) {
284: switch (jj_nt.kind) {
285: case ID:
286: case STRING:
287: case NUM:
288: ;
289: break;
290: default:
291: break label_8;
292: }
293: value = word();
294: values.append(" " + value);
295: }
296: jj_consume_token(28);
297: if (map != null)
298: map.put(key, values.toString());
299: }
300:
301: final public String word() throws ParseException {
302: String result, right;
303: result = simpleWord();
304: switch (jj_nt.kind) {
305: case 29:
306: right = range();
307: result = result + right;
308: break;
309: default:
310: ;
311: }
312: {
313: if (true)
314: return result;
315: }
316: throw new Error("Missing return statement in function");
317: }
318:
319: final public String simpleWord() throws ParseException {
320: String result;
321: Version v;
322: switch (jj_nt.kind) {
323: case ID:
324: result = id();
325: break;
326: case NUM:
327: v = version();
328: result = v.toString();
329: break;
330: case STRING:
331: result = string();
332: break;
333: default:
334: jj_consume_token(-1);
335: throw new ParseException();
336: }
337: {
338: if (true)
339: return result;
340: }
341: throw new Error("Missing return statement in function");
342: }
343:
344: final public String range() throws ParseException {
345: String rightSide;
346: jj_consume_token(29);
347: rightSide = simpleWord();
348: {
349: if (true)
350: return ":" + rightSide;
351: }
352: throw new Error("Missing return statement in function");
353: }
354:
355: final public void desc(Archive arc) throws ParseException {
356: String s;
357: jj_consume_token(DESC);
358: s = string();
359: arc.setDesc(s);
360: }
361:
362: final public void delta(Archive arc) throws ParseException {
363: Version v;
364: Node node;
365: int[] d;
366: String s;
367: v = version();
368: node = arc.newNode(v);
369: jj_consume_token(DATE);
370: d = date();
371: node.setDate(d);
372: jj_consume_token(28);
373: jj_consume_token(AUTHOR);
374: s = id();
375: node.setAuthor(s);
376: jj_consume_token(28);
377: jj_consume_token(STATE);
378: switch (jj_nt.kind) {
379: case ID:
380: s = id();
381: node.setState(s);
382: break;
383: default:
384: ;
385: }
386: jj_consume_token(28);
387: jj_consume_token(BRANCHES);
388: label_9: while (true) {
389: switch (jj_nt.kind) {
390: case NUM:
391: ;
392: break;
393: default:
394: break label_9;
395: }
396: v = version();
397: node.addBranch(arc.newBranchNode(v));
398: }
399: jj_consume_token(28);
400: jj_consume_token(NEXT);
401: switch (jj_nt.kind) {
402: case NUM:
403: v = version();
404: node.setRCSNext(arc.newNode(v));
405: break;
406: default:
407: ;
408: }
409: jj_consume_token(28);
410: newPhrases(node.phrases);
411: }
412:
413: final public void text(Archive arc) throws ParseException {
414: Version v;
415: Node node;
416: String log;
417: String txt;
418: v = version();
419: node = arc.getNode(v);
420: jj_consume_token(LOG);
421: log = string();
422: node.setLog(log);
423: newPhrases(node.phrases);
424: jj_consume_token(TEXT);
425: txt = string();
426: node.setText(txt);
427: }
428:
429: final public String id() throws ParseException {
430: Token t;
431: t = jj_consume_token(ID);
432: {
433: if (true)
434: return t.image;
435: }
436: throw new Error("Missing return statement in function");
437: }
438:
439: final public String sym() throws ParseException {
440: Token t;
441: switch (jj_nt.kind) {
442: case SYM:
443: t = jj_consume_token(SYM);
444: break;
445: case ID:
446: t = jj_consume_token(ID);
447: break;
448: default:
449: jj_consume_token(-1);
450: throw new ParseException();
451: }
452: {
453: if (true)
454: return t.image;
455: }
456: throw new Error("Missing return statement in function");
457: }
458:
459: final public Version version() throws ParseException {
460: Version v;
461: int n, r;
462: n = num();
463: v = new Version(n);
464: label_10: while (true) {
465: switch (jj_nt.kind) {
466: case 30:
467: ;
468: break;
469: default:
470: break label_10;
471: }
472: jj_consume_token(30);
473: n = num();
474: v.__addBranch(n);
475: }
476: {
477: if (true)
478: return v;
479: }
480: throw new Error("Missing return statement in function");
481: }
482:
483: final public int[] date() throws ParseException {
484: int[] n = new int[6];
485: n[0] = num();
486: jj_consume_token(30);
487: n[1] = num();
488: jj_consume_token(30);
489: n[2] = num();
490: jj_consume_token(30);
491: n[3] = num();
492: jj_consume_token(30);
493: n[4] = num();
494: jj_consume_token(30);
495: n[5] = num();
496: {
497: if (true)
498: return n;
499: }
500: throw new Error("Missing return statement in function");
501: }
502:
503: final public int num() throws ParseException {
504: Token t;
505: t = jj_consume_token(NUM);
506: {
507: if (true)
508: return Integer.parseInt(t.image);
509: }
510: throw new Error("Missing return statement in function");
511: }
512:
513: final public String string() throws ParseException {
514: Token t;
515: t = jj_consume_token(STRING);
516: {
517: if (true)
518: return Archive.unquoteString(t.image);
519: }
520: throw new Error("Missing return statement in function");
521: }
522:
523: public ArchiveParserTokenManager token_source;
524: SimpleCharStream jj_input_stream;
525: public Token token, jj_nt;
526:
527: public ArchiveParser(java.io.InputStream stream) {
528: jj_input_stream = new SimpleCharStream(stream, 1, 1);
529: token_source = new ArchiveParserTokenManager(jj_input_stream);
530: token = new Token();
531: token.next = jj_nt = token_source.getNextToken();
532: }
533:
534: public void ReInit(java.io.InputStream stream) {
535: jj_input_stream.ReInit(stream, 1, 1);
536: token_source.ReInit(jj_input_stream);
537: token = new Token();
538: token.next = jj_nt = token_source.getNextToken();
539: }
540:
541: public ArchiveParser(java.io.Reader stream) {
542: jj_input_stream = new SimpleCharStream(stream, 1, 1);
543: token_source = new ArchiveParserTokenManager(jj_input_stream);
544: token = new Token();
545: token.next = jj_nt = token_source.getNextToken();
546: }
547:
548: public void ReInit(java.io.Reader stream) {
549: jj_input_stream.ReInit(stream, 1, 1);
550: token_source.ReInit(jj_input_stream);
551: token = new Token();
552: token.next = jj_nt = token_source.getNextToken();
553: }
554:
555: public ArchiveParser(ArchiveParserTokenManager tm) {
556: token_source = tm;
557: token = new Token();
558: token.next = jj_nt = token_source.getNextToken();
559: }
560:
561: public void ReInit(ArchiveParserTokenManager tm) {
562: token_source = tm;
563: token = new Token();
564: token.next = jj_nt = token_source.getNextToken();
565: }
566:
567: final private Token jj_consume_token(int kind)
568: throws ParseException {
569: Token oldToken = token;
570: if ((token = jj_nt).next != null)
571: jj_nt = jj_nt.next;
572: else
573: jj_nt = jj_nt.next = token_source.getNextToken();
574: if (token.kind == kind) {
575: return token;
576: }
577: jj_nt = token;
578: token = oldToken;
579: throw generateParseException();
580: }
581:
582: final public Token getNextToken() {
583: if ((token = jj_nt).next != null)
584: jj_nt = jj_nt.next;
585: else
586: jj_nt = jj_nt.next = token_source.getNextToken();
587: return token;
588: }
589:
590: final public Token getToken(int index) {
591: Token t = token;
592: for (int i = 0; i < index; i++) {
593: if (t.next != null)
594: t = t.next;
595: else
596: t = t.next = token_source.getNextToken();
597: }
598: return t;
599: }
600:
601: final public ParseException generateParseException() {
602: Token errortok = token.next;
603: int line = errortok.beginLine, column = errortok.beginColumn;
604: String mess = (errortok.kind == 0) ? tokenImage[0]
605: : errortok.image;
606: return new ParseException("Parse error at line " + line
607: + ", column " + column + ". Encountered: " + mess);
608: }
609:
610: final public void enable_tracing() {
611: }
612:
613: final public void disable_tracing() {
614: }
615:
616: }
|