KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > wocompat > parser > Parser


1 /* Generated By:JavaCC: Do not edit this line. Parser.java */
2 /* ====================================================================
3  *
4  * The ObjectStyle Group Software License, version 1.1
5  * ObjectStyle Group - http://objectstyle.org/
6  *
7  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
8  * of the software. All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  *
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in
19  * the documentation and/or other materials provided with the
20  * distribution.
21  *
22  * 3. The end-user documentation included with the redistribution, if any,
23  * must include the following acknowlegement:
24  * "This product includes software developed by independent contributors
25  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
26  * Alternately, this acknowlegement may appear in the software itself,
27  * if and wherever such third-party acknowlegements normally appear.
28  *
29  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
30  * or promote products derived from this software without prior written
31  * permission. For written permission, email
32  * "andrus at objectstyle dot org".
33  *
34  * 5. Products derived from this software may not be called "ObjectStyle"
35  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
36  * names without prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
42  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49  * SUCH DAMAGE.
50  * ====================================================================
51  *
52  * This software consists of voluntary contributions made by many
53  * individuals and hosted on ObjectStyle Group web site. For more
54  * information on the ObjectStyle Group, please see
55  * <http://objectstyle.org/>.
56  */

57 package org.objectstyle.cayenne.wocompat.parser;
58
59 import org.apache.log4j.Logger;
60 import java.io.*;
61 import java.util.*;
62
63 /**
64  * NeXT/Apple Property List format parser.
65  *
66  * <p>Contributed by Jeff Martin <reportmill@yahoo.com> and Josh from Report Mill -
67  * <a HREF="http://www.reportmill.com/">http://www.reportmill.com/</a></p>
68  */

69 public class Parser implements ParserConstants {
70
71     private static Logger logObj = Logger.getLogger(Parser.class);
72
73     public Parser() {
74         this(System.in);
75     }
76
77     public Parser(String JavaDoc filename) throws FileNotFoundException {
78         this(new FileInputStream(filename));
79     }
80
81     public Parser(File f) throws FileNotFoundException {
82         this(new FileInputStream(f));
83     }
84
85     public Object JavaDoc propertyList() {
86         try {
87             return object();
88         }
89         catch (ParseException pe) {
90            logObj.info("Error parsing plist", pe);
91            return null;
92         }
93     }
94
95 public static void main(String JavaDoc args[]) {
96   Parser r = new Parser();
97   Object JavaDoc o = r.propertyList();
98   System.out.println(o);
99   }
100
101   final public Object JavaDoc object() throws ParseException {
102         Object JavaDoc node;
103     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
104     case 8:
105       node = array();
106                                {if (true) return node;}
107       break;
108     case 10:
109       node = dictionary();
110                                     {if (true) return node;}
111       break;
112     case INT:
113     case FLOAT:
114     case STRING:
115     case QUOTED_STRING:
116       node = leaf();
117                               {if (true) return node;}
118       break;
119     default:
120       jj_la1[0] = jj_gen;
121       jj_consume_token(-1);
122       throw new ParseException();
123     }
124     throw new Error JavaDoc("Missing return statement in function");
125   }
126
127   final public Object JavaDoc leaf() throws ParseException {
128     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
129     case INT:
130       jj_consume_token(INT);
131           {if (true) return Integer.valueOf(token.image);}
132       break;
133     case FLOAT:
134       jj_consume_token(FLOAT);
135             {if (true) return Double.valueOf(token.image);}
136       break;
137     case QUOTED_STRING:
138       jj_consume_token(QUOTED_STRING);
139                     {if (true) return token.image;}
140       break;
141     case STRING:
142       jj_consume_token(STRING);
143              {if (true) return token.image;}
144       break;
145     default:
146       jj_la1[1] = jj_gen;
147       jj_consume_token(-1);
148       throw new ParseException();
149     }
150     throw new Error JavaDoc("Missing return statement in function");
151   }
152
153   final public HashMap dictionary() throws ParseException {
154         HashMap h;
155     jj_consume_token(10);
156               h = new HashMap();
157     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
158     case INT:
159     case FLOAT:
160     case 8:
161     case 10:
162     case STRING:
163     case QUOTED_STRING:
164       keyValuePair(h);
165       label_1:
166       while (true) {
167         if (jj_2_1(2)) {
168           ;
169         } else {
170           break label_1;
171         }
172         jj_consume_token(13);
173         keyValuePair(h);
174       }
175       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
176       case 13:
177         jj_consume_token(13);
178         break;
179       default:
180         jj_la1[2] = jj_gen;
181         ;
182       }
183       break;
184     default:
185       jj_la1[3] = jj_gen;
186       ;
187     }
188     jj_consume_token(11);
189               {if (true) return h;}
190     throw new Error JavaDoc("Missing return statement in function");
191   }
192
193   final public void keyValuePair(Map map) throws ParseException {
194         Object JavaDoc key, val;
195     key = object();
196     jj_consume_token(7);
197     val = object();
198                                  map.put(key, val);
199   }
200
201   final public ArrayList array() throws ParseException {
202   ArrayList v;
203   Object JavaDoc o;
204     jj_consume_token(8);
205          v = new ArrayList();
206     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
207     case INT:
208     case FLOAT:
209     case 8:
210     case 10:
211     case STRING:
212     case QUOTED_STRING:
213       o = object();
214                    v.add(o);
215       label_2:
216       while (true) {
217         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
218         case 12:
219           ;
220           break;
221         default:
222           jj_la1[4] = jj_gen;
223           break label_2;
224         }
225         jj_consume_token(12);
226         o = object();
227                         v.add(o);
228       }
229       break;
230     default:
231       jj_la1[5] = jj_gen;
232       ;
233     }
234     jj_consume_token(9);
235         {if (true) return v;}
236     throw new Error JavaDoc("Missing return statement in function");
237   }
238
239   final private boolean jj_2_1(int xla) {
240     jj_la = xla; jj_lastpos = jj_scanpos = token;
241     try { return !jj_3_1(); }
242     catch(LookaheadSuccess ls) { return true; }
243     finally { jj_save(0, xla); }
244   }
245
246   final private boolean jj_3R_8() {
247     if (jj_scan_token(8)) return true;
248     return false;
249   }
250
251   final private boolean jj_3R_9() {
252     if (jj_scan_token(10)) return true;
253     return false;
254   }
255
256   final private boolean jj_3_1() {
257     if (jj_scan_token(13)) return true;
258     if (jj_3R_3()) return true;
259     return false;
260   }
261
262   final private boolean jj_3R_7() {
263     if (jj_3R_10()) return true;
264     return false;
265   }
266
267   final private boolean jj_3R_6() {
268     if (jj_3R_9()) return true;
269     return false;
270   }
271
272   final private boolean jj_3R_4() {
273     Token xsp;
274     xsp = jj_scanpos;
275     if (jj_3R_5()) {
276     jj_scanpos = xsp;
277     if (jj_3R_6()) {
278     jj_scanpos = xsp;
279     if (jj_3R_7()) return true;
280     }
281     }
282     return false;
283   }
284
285   final private boolean jj_3R_5() {
286     if (jj_3R_8()) return true;
287     return false;
288   }
289
290   final private boolean jj_3R_14() {
291     if (jj_scan_token(STRING)) return true;
292     return false;
293   }
294
295   final private boolean jj_3R_13() {
296     if (jj_scan_token(QUOTED_STRING)) return true;
297     return false;
298   }
299
300   final private boolean jj_3R_12() {
301     if (jj_scan_token(FLOAT)) return true;
302     return false;
303   }
304
305   final private boolean jj_3R_11() {
306     if (jj_scan_token(INT)) return true;
307     return false;
308   }
309
310   final private boolean jj_3R_10() {
311     Token xsp;
312     xsp = jj_scanpos;
313     if (jj_3R_11()) {
314     jj_scanpos = xsp;
315     if (jj_3R_12()) {
316     jj_scanpos = xsp;
317     if (jj_3R_13()) {
318     jj_scanpos = xsp;
319     if (jj_3R_14()) return true;
320     }
321     }
322     }
323     return false;
324   }
325
326   final private boolean jj_3R_3() {
327     if (jj_3R_4()) return true;
328     return false;
329   }
330
331   public ParserTokenManager token_source;
332   SimpleCharStream jj_input_stream;
333   public Token token, jj_nt;
334   private int jj_ntk;
335   private Token jj_scanpos, jj_lastpos;
336   private int jj_la;
337   public boolean lookingAhead = false;
338   private boolean jj_semLA;
339   private int jj_gen;
340   final private int[] jj_la1 = new int[6];
341   static private int[] jj_la1_0;
342   static {
343       jj_la1_0();
344    }
345    private static void jj_la1_0() {
346       jj_la1_0 = new int[] {0x40020560,0x40020060,0x2000,0x40020560,0x1000,0x40020560,};
347    }
348   final private JJCalls[] jj_2_rtns = new JJCalls[1];
349   private boolean jj_rescan = false;
350   private int jj_gc = 0;
351
352   public Parser(java.io.InputStream JavaDoc stream) {
353     jj_input_stream = new SimpleCharStream(stream, 1, 1);
354     token_source = new ParserTokenManager(jj_input_stream);
355     token = new Token();
356     jj_ntk = -1;
357     jj_gen = 0;
358     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
359     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
360   }
361
362   public void ReInit(java.io.InputStream JavaDoc stream) {
363     jj_input_stream.ReInit(stream, 1, 1);
364     token_source.ReInit(jj_input_stream);
365     token = new Token();
366     jj_ntk = -1;
367     jj_gen = 0;
368     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
369     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
370   }
371
372   public Parser(java.io.Reader JavaDoc stream) {
373     jj_input_stream = new SimpleCharStream(stream, 1, 1);
374     token_source = new ParserTokenManager(jj_input_stream);
375     token = new Token();
376     jj_ntk = -1;
377     jj_gen = 0;
378     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
379     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
380   }
381
382   public void ReInit(java.io.Reader JavaDoc stream) {
383     jj_input_stream.ReInit(stream, 1, 1);
384     token_source.ReInit(jj_input_stream);
385     token = new Token();
386     jj_ntk = -1;
387     jj_gen = 0;
388     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
389     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
390   }
391
392   public Parser(ParserTokenManager tm) {
393     token_source = tm;
394     token = new Token();
395     jj_ntk = -1;
396     jj_gen = 0;
397     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
398     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
399   }
400
401   public void ReInit(ParserTokenManager tm) {
402     token_source = tm;
403     token = new Token();
404     jj_ntk = -1;
405     jj_gen = 0;
406     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
407     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
408   }
409
410   final private Token jj_consume_token(int kind) throws ParseException {
411     Token oldToken;
412     if ((oldToken = token).next != null) token = token.next;
413     else token = token.next = token_source.getNextToken();
414     jj_ntk = -1;
415     if (token.kind == kind) {
416       jj_gen++;
417       if (++jj_gc > 100) {
418         jj_gc = 0;
419         for (int i = 0; i < jj_2_rtns.length; i++) {
420           JJCalls c = jj_2_rtns[i];
421           while (c != null) {
422             if (c.gen < jj_gen) c.first = null;
423             c = c.next;
424           }
425         }
426       }
427       return token;
428     }
429     token = oldToken;
430     jj_kind = kind;
431     throw generateParseException();
432   }
433
434   static private final class LookaheadSuccess extends java.lang.Error JavaDoc { }
435   final private LookaheadSuccess jj_ls = new LookaheadSuccess();
436   final private boolean jj_scan_token(int kind) {
437     if (jj_scanpos == jj_lastpos) {
438       jj_la--;
439       if (jj_scanpos.next == null) {
440         jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
441       } else {
442         jj_lastpos = jj_scanpos = jj_scanpos.next;
443       }
444     } else {
445       jj_scanpos = jj_scanpos.next;
446     }
447     if (jj_rescan) {
448       int i = 0; Token tok = token;
449       while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
450       if (tok != null) jj_add_error_token(kind, i);
451     }
452     if (jj_scanpos.kind != kind) return true;
453     if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
454     return false;
455   }
456
457   final public Token getNextToken() {
458     if (token.next != null) token = token.next;
459     else token = token.next = token_source.getNextToken();
460     jj_ntk = -1;
461     jj_gen++;
462     return token;
463   }
464
465   final public Token getToken(int index) {
466     Token t = lookingAhead ? jj_scanpos : token;
467     for (int i = 0; i < index; i++) {
468       if (t.next != null) t = t.next;
469       else t = t.next = token_source.getNextToken();
470     }
471     return t;
472   }
473
474   final private int jj_ntk() {
475     if ((jj_nt=token.next) == null)
476       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
477     else
478       return (jj_ntk = jj_nt.kind);
479   }
480
481   private java.util.Vector JavaDoc jj_expentries = new java.util.Vector JavaDoc();
482   private int[] jj_expentry;
483   private int jj_kind = -1;
484   private int[] jj_lasttokens = new int[100];
485   private int jj_endpos;
486
487   private void jj_add_error_token(int kind, int pos) {
488     if (pos >= 100) return;
489     if (pos == jj_endpos + 1) {
490       jj_lasttokens[jj_endpos++] = kind;
491     } else if (jj_endpos != 0) {
492       jj_expentry = new int[jj_endpos];
493       for (int i = 0; i < jj_endpos; i++) {
494         jj_expentry[i] = jj_lasttokens[i];
495       }
496       boolean exists = false;
497       for (java.util.Enumeration JavaDoc e = jj_expentries.elements(); e.hasMoreElements();) {
498         int[] oldentry = (int[])(e.nextElement());
499         if (oldentry.length == jj_expentry.length) {
500           exists = true;
501           for (int i = 0; i < jj_expentry.length; i++) {
502             if (oldentry[i] != jj_expentry[i]) {
503               exists = false;
504               break;
505             }
506           }
507           if (exists) break;
508         }
509       }
510       if (!exists) jj_expentries.addElement(jj_expentry);
511       if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
512     }
513   }
514
515   public ParseException generateParseException() {
516     jj_expentries.removeAllElements();
517     boolean[] la1tokens = new boolean[31];
518     for (int i = 0; i < 31; i++) {
519       la1tokens[i] = false;
520     }
521     if (jj_kind >= 0) {
522       la1tokens[jj_kind] = true;
523       jj_kind = -1;
524     }
525     for (int i = 0; i < 6; i++) {
526       if (jj_la1[i] == jj_gen) {
527         for (int j = 0; j < 32; j++) {
528           if ((jj_la1_0[i] & (1<<j)) != 0) {
529             la1tokens[j] = true;
530           }
531         }
532       }
533     }
534     for (int i = 0; i < 31; i++) {
535       if (la1tokens[i]) {
536         jj_expentry = new int[1];
537         jj_expentry[0] = i;
538         jj_expentries.addElement(jj_expentry);
539       }
540     }
541     jj_endpos = 0;
542     jj_rescan_token();
543     jj_add_error_token(0, 0);
544     int[][] exptokseq = new int[jj_expentries.size()][];
545     for (int i = 0; i < jj_expentries.size(); i++) {
546       exptokseq[i] = (int[])jj_expentries.elementAt(i);
547     }
548     return new ParseException(token, exptokseq, tokenImage);
549   }
550
551   final public void enable_tracing() {
552   }
553
554   final public void disable_tracing() {
555   }
556
557   final private void jj_rescan_token() {
558     jj_rescan = true;
559     for (int i = 0; i < 1; i++) {
560       JJCalls p = jj_2_rtns[i];
561       do {
562         if (p.gen > jj_gen) {
563           jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
564           switch (i) {
565             case 0: jj_3_1(); break;
566           }
567         }
568         p = p.next;
569       } while (p != null);
570     }
571     jj_rescan = false;
572   }
573
574   final private void jj_save(int index, int xla) {
575     JJCalls p = jj_2_rtns[index];
576     while (p.gen > jj_gen) {
577       if (p.next == null) { p = p.next = new JJCalls(); break; }
578       p = p.next;
579     }
580     p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
581   }
582
583   static final class JJCalls {
584     int gen;
585     Token first;
586     int arg;
587     JJCalls next;
588   }
589
590 }
591
Popular Tags