Home » openjdk-7 » net.bonzoun » cocodonkey » [javadoc | source]

    1   /* Generated By: CamlParser.jj,v 1.1 2002/08/21 21&JavaCC: Do not edit this line. CamlParser.java */
    2   package net.bonzoun.cocodonkey;
    3   
    4   import java.io;
    5   import java.util;
    6   
    7   public class CamlParser implements CamlParserConstants {
    8   
    9       public static CamlData parse(File file) {
   10           long t0 = System.currentTimeMillis();
   11           try {
   12               CamlParser parser = new CamlParser(new InputStreamReader(new FileInputStream(file), "ISO8859_1"));
   13               return parser.parse();
   14           } catch (Exception e) {
   15               e.printStackTrace();
   16               return null;
   17           } finally {
   18               long t = System.currentTimeMillis();
   19               //System.out.println("Parse " + file.getName() + " in " + (t-t0) + "ms");
   20           }
   21       }
   22   
   23     final public CamlData parse() throws ParseException {
   24       Map data;
   25       data = struct_content();
   26       jj_consume_token(0);
   27           {if (true) return new CamlData.Map(data);}
   28       throw new Error("Missing return statement in function");
   29     }
   30   
   31     final public Map struct_content() throws ParseException {
   32       HashMap map = new HashMap();
   33       String key;
   34       CamlData data;
   35       label_1:
   36       while (true) {
   37         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
   38         case SYMBOL:
   39           ;
   40           break;
   41         default:
   42           jj_la1[0] = jj_gen;
   43           break label_1;
   44         }
   45         jj_consume_token(SYMBOL);
   46                                                                   key = token.image;
   47         jj_consume_token(EQUALS);
   48         data = data();
   49                                                           map.put(key, data);
   50       }
   51           {if (true) return map;}
   52       throw new Error("Missing return statement in function");
   53     }
   54   
   55     final public CamlData data() throws ParseException {
   56       List list;
   57       Map map;
   58       CamlData data;
   59       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
   60       case LBRACE:
   61         map = struct();
   62                                                           data = new CamlData.Map(map);
   63         break;
   64       case LBRACKET:
   65         list = listSem();
   66                                                           data = new CamlData.List(list);
   67         break;
   68       case LPARENT:
   69         list = listCom();
   70                                                           data = new CamlData.List(list);
   71         break;
   72       case STRING:
   73         jj_consume_token(STRING);
   74                                                                   if (token.image.length()>2) {
   75                                               String s = token.image;
   76                                               int p;
   77                                               while( (p=s.indexOf("\\\\")) >= 0)
   78                                                   s = s.substring(0, p) + s.substring(p+1);
   79                                               data = new CamlData.Data(s.substring(1, s.length()-1));
   80                                           } else
   81                                               data = new CamlData.Data("");
   82         break;
   83       case SYMBOL:
   84         jj_consume_token(SYMBOL);
   85                                                                   data = new CamlData.Data(token.image);
   86         break;
   87       case INTEGER:
   88         jj_consume_token(INTEGER);
   89                                                                   data = new CamlData.Data(token.image);
   90         break;
   91       case FLOAT:
   92         jj_consume_token(FLOAT);
   93                                                                   data = new CamlData.Data(token.image);
   94         break;
   95       default:
   96         jj_la1[1] = jj_gen;
   97         jj_consume_token(-1);
   98         throw new ParseException();
   99       }
  100           {if (true) return data;}
  101       throw new Error("Missing return statement in function");
  102     }
  103   
  104     final public Map struct() throws ParseException {
  105       Map data;
  106       jj_consume_token(LBRACE);
  107       data = struct_content();
  108       jj_consume_token(RBRACE);
  109           {if (true) return data;}
  110       throw new Error("Missing return statement in function");
  111     }
  112   
  113     final public List listSem() throws ParseException {
  114       ArrayList list = new ArrayList();
  115       CamlData data;
  116       jj_consume_token(LBRACKET);
  117       label_2:
  118       while (true) {
  119         switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  120         case SYMBOL:
  121         case INTEGER:
  122         case FLOAT:
  123         case STRING:
  124         case LBRACE:
  125         case LBRACKET:
  126         case LPARENT:
  127           ;
  128           break;
  129         default:
  130           jj_la1[2] = jj_gen;
  131           break label_2;
  132         }
  133         data = data();
  134                                                           list.add(data);
  135         label_3:
  136         while (true) {
  137           switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  138           case SEMICOLON:
  139             ;
  140             break;
  141           default:
  142             jj_la1[3] = jj_gen;
  143             break label_3;
  144           }
  145           jj_consume_token(SEMICOLON);
  146           data = data();
  147                                                           list.add(data);
  148         }
  149       }
  150       jj_consume_token(RBRACKET);
  151           {if (true) return list;}
  152       throw new Error("Missing return statement in function");
  153     }
  154   
  155     final public List listCom() throws ParseException {
  156       ArrayList list = new ArrayList();
  157       CamlData data;
  158       jj_consume_token(LPARENT);
  159       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  160       case SYMBOL:
  161       case INTEGER:
  162       case FLOAT:
  163       case STRING:
  164       case LBRACE:
  165       case LBRACKET:
  166       case LPARENT:
  167         data = data();
  168                                                           list.add(data);
  169         label_4:
  170         while (true) {
  171           switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  172           case COMMA:
  173             ;
  174             break;
  175           default:
  176             jj_la1[4] = jj_gen;
  177             break label_4;
  178           }
  179           jj_consume_token(COMMA);
  180           data = data();
  181                                                           list.add(data);
  182         }
  183         break;
  184       default:
  185         jj_la1[5] = jj_gen;
  186         ;
  187       }
  188       jj_consume_token(RPARENT);
  189           {if (true) return list;}
  190       throw new Error("Missing return statement in function");
  191     }
  192   
  193     public CamlParserTokenManager token_source;
  194     ASCII_CharStream jj_input_stream;
  195     public Token token, jj_nt;
  196     private int jj_ntk;
  197     private int jj_gen;
  198     final private int[] jj_la1 = new int[6];
  199     final private int[] jj_la1_0 = {0x2,0x2be,0x2be,0x800,0x1000,0x2be,};
  200   
  201     public CamlParser(java.io.InputStream stream) {
  202       jj_input_stream = new ASCII_CharStream(stream, 1, 1);
  203       token_source = new CamlParserTokenManager(jj_input_stream);
  204       token = new Token();
  205       jj_ntk = -1;
  206       jj_gen = 0;
  207       for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  208     }
  209   
  210     public void ReInit(java.io.InputStream stream) {
  211       jj_input_stream.ReInit(stream, 1, 1);
  212       token_source.ReInit(jj_input_stream);
  213       token = new Token();
  214       jj_ntk = -1;
  215       jj_gen = 0;
  216       for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  217     }
  218   
  219     public CamlParser(java.io.Reader stream) {
  220       jj_input_stream = new ASCII_CharStream(stream, 1, 1);
  221       token_source = new CamlParserTokenManager(jj_input_stream);
  222       token = new Token();
  223       jj_ntk = -1;
  224       jj_gen = 0;
  225       for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  226     }
  227   
  228     public void ReInit(java.io.Reader stream) {
  229       jj_input_stream.ReInit(stream, 1, 1);
  230       token_source.ReInit(jj_input_stream);
  231       token = new Token();
  232       jj_ntk = -1;
  233       jj_gen = 0;
  234       for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  235     }
  236   
  237     public CamlParser(CamlParserTokenManager tm) {
  238       token_source = tm;
  239       token = new Token();
  240       jj_ntk = -1;
  241       jj_gen = 0;
  242       for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  243     }
  244   
  245     public void ReInit(CamlParserTokenManager tm) {
  246       token_source = tm;
  247       token = new Token();
  248       jj_ntk = -1;
  249       jj_gen = 0;
  250       for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  251     }
  252   
  253     final private Token jj_consume_token(int kind) throws ParseException {
  254       Token oldToken;
  255       if ((oldToken = token).next != null) token = token.next;
  256       else token = token.next = token_source.getNextToken();
  257       jj_ntk = -1;
  258       if (token.kind == kind) {
  259         jj_gen++;
  260         return token;
  261       }
  262       token = oldToken;
  263       jj_kind = kind;
  264       throw generateParseException();
  265     }
  266   
  267     final public Token getNextToken() {
  268       if (token.next != null) token = token.next;
  269       else token = token.next = token_source.getNextToken();
  270       jj_ntk = -1;
  271       jj_gen++;
  272       return token;
  273     }
  274   
  275     final public Token getToken(int index) {
  276       Token t = token;
  277       for (int i = 0; i < index; i++) {
  278         if (t.next != null) t = t.next;
  279         else t = t.next = token_source.getNextToken();
  280       }
  281       return t;
  282     }
  283   
  284     final private int jj_ntk() {
  285       if ((jj_nt=token.next) == null)
  286         return (jj_ntk = (token.next=token_source.getNextToken()).kind);
  287       else
  288         return (jj_ntk = jj_nt.kind);
  289     }
  290   
  291     private java.util.Vector jj_expentries = new java.util.Vector();
  292     private int[] jj_expentry;
  293     private int jj_kind = -1;
  294   
  295     final public ParseException generateParseException() {
  296       jj_expentries.removeAllElements();
  297       boolean[] la1tokens = new boolean[22];
  298       for (int i = 0; i < 22; i++) {
  299         la1tokens[i] = false;
  300       }
  301       if (jj_kind >= 0) {
  302         la1tokens[jj_kind] = true;
  303         jj_kind = -1;
  304       }
  305       for (int i = 0; i < 6; i++) {
  306         if (jj_la1[i] == jj_gen) {
  307           for (int j = 0; j < 32; j++) {
  308             if ((jj_la1_0[i] & (1<<j)) != 0) {
  309               la1tokens[j] = true;
  310             }
  311           }
  312         }
  313       }
  314       for (int i = 0; i < 22; i++) {
  315         if (la1tokens[i]) {
  316           jj_expentry = new int[1];
  317           jj_expentry[0] = i;
  318           jj_expentries.addElement(jj_expentry);
  319         }
  320       }
  321       int[][] exptokseq = new int[jj_expentries.size()][];
  322       for (int i = 0; i < jj_expentries.size(); i++) {
  323         exptokseq[i] = (int[])jj_expentries.elementAt(i);
  324       }
  325       return new ParseException(token, exptokseq, tokenImage);
  326     }
  327   
  328     final public void enable_tracing() {
  329     }
  330   
  331     final public void disable_tracing() {
  332     }
  333   
  334   }

Home » openjdk-7 » net.bonzoun » cocodonkey » [javadoc | source]