Coverage Report - org.apache.commons.flatfile.dsl.EntityTreeParser
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityTreeParser
92%
500/538
62%
139/221
9.55
 
 1  
 // $ANTLR 2.7.7 (20060906): "EntityTreeParser.g" -> "EntityTreeParser.java"$
 2  
 
 3  
 package org.apache.commons.flatfile.dsl;
 4  
 
 5  
 import java.io.IOException;
 6  
 
 7  
 import java.util.List;
 8  
 import java.util.Stack;
 9  
 import java.util.Iterator;
 10  
 import java.util.ArrayList;
 11  
 import java.util.HashMap;
 12  
 
 13  
 import org.apache.commons.flatfile.*;
 14  
 import org.apache.commons.flatfile.util.ApplyOptions;
 15  
 
 16  
 import antlr.TreeParser;
 17  
 import antlr.Token;
 18  
 import antlr.collections.AST;
 19  
 import antlr.RecognitionException;
 20  
 import antlr.ANTLRException;
 21  
 import antlr.NoViableAltException;
 22  
 import antlr.MismatchedTokenException;
 23  
 import antlr.SemanticException;
 24  
 import antlr.collections.impl.BitSet;
 25  
 import antlr.ASTPair;
 26  
 import antlr.collections.impl.ASTArray;
 27  
 
 28  
 
 29  
 public class EntityTreeParser extends antlr.TreeParser       implements EntityTreeParserTokenTypes
 30  
  {
 31  
 
 32  
         private java.lang.ref.WeakReference<ParserEntityFactory> entityFactoryRef;
 33  222
         private Stack<String> stk = new Stack<String>();
 34  
 
 35  
         public synchronized Entity createEntity(EntityDefinition def) {
 36  426
                 String name = def.getName();
 37  426
                 if (stk.contains(def.getName())) {
 38  0
                         throw new IllegalStateException("Circular reference detected for entity type " + name);
 39  
                 }
 40  426
                 stk.push(def.getName());
 41  
                 try {
 42  426
                         Entity result = entity(def.getAst());
 43  420
                         runChecks(def, result);
 44  621
                         return result;
 45  0
                 } catch (ANTLRException e) {
 46  0
                         throw new RuntimeException(e);
 47  6
                 } finally {
 48  426
                         String x = stk.pop();
 49  426
                         if (!x.equals(def.getName())) {
 50  0
                                 throw new IllegalStateException("Stack out of balance; encountered " + x);
 51  
                         }
 52  219
                 }
 53  
         }
 54  
 
 55  
         public void setEntityFactory(ParserEntityFactory entityFactory) {
 56  222
                 this.entityFactoryRef = new java.lang.ref.WeakReference<ParserEntityFactory>(entityFactory);
 57  222
         }
 58  
 
 59  
         private void runChecks(EntityDefinition def, Entity e) {
 60  657
                 for (AST check : def.getChecks()) {
 61  60
                         switch (check.getType()) {
 62  
                                 case LENGTH :
 63  60
                                         int expected = Integer.parseInt(check.getText());
 64  60
                                         int actual = e.length();
 65  60
                                         if (expected != actual) {
 66  9
                                                 throw new IllegalStateException(
 67  3
                                                                 "expected entity " + def.getName() + " length=" + expected + "; actually " + actual);
 68  
                                         }
 69  
                                         break;
 70  
                                 default :
 71  0
                                         throw new IllegalArgumentException("Unknown check: " + check);
 72  
                         }
 73  27
                 }
 74  414
         }
 75  
 
 76  
         private byte[] getBytes(String s) {
 77  
                 try {
 78  474
                         return s.getBytes("UTF-8");
 79  0
                 } catch (IOException e) {
 80  0
                         throw new RuntimeException(e);
 81  
                 }
 82  
         }
 83  
 
 84  
         private ParserEntityFactory getEntityFactory() {
 85  2538
                 return entityFactoryRef.get();
 86  
         }
 87  222
 public EntityTreeParser() {
 88  222
         tokenNames = _tokenNames;
 89  222
 }
 90  
 
 91  
         public final void load(AST _t) throws RecognitionException {
 92  
                 
 93  192
                 AST load_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 94  192
                 AST e = null;
 95  192
                 AST c = null;
 96  192
                 List<AST> checks = new ArrayList<AST>(); String name = null;
 97  
                 
 98  192
                 AST __t2 = _t;
 99  192
                 AST tmp1_AST_in = (AST)_t;
 100  192
                 match(_t,ROOT);
 101  192
                 _t = _t.getFirstChild();
 102  
                 {
 103  
                 _loop4:
 104  
                 do {
 105  210
                         if (_t==null) _t=ASTNULL;
 106  210
                         if ((_t.getType()==OPTIONS)) {
 107  18
                                 defaultOptions(_t);
 108  18
                                 _t = _retTree;
 109  
                         }
 110  
                         else {
 111  
                                 break _loop4;
 112  
                         }
 113  
                         
 114  9
                 } while (true);
 115  
                 }
 116  
                 {
 117  192
                 int _cnt9=0;
 118  
                 _loop9:
 119  
                 do {
 120  1830
                         if (_t==null) _t=ASTNULL;
 121  1830
                         if ((_t.getType()==ASSIGN)) {
 122  1638
                                 AST __t6 = _t;
 123  1638
                                 AST tmp2_AST_in = (AST)_t;
 124  1638
                                 match(_t,ASSIGN);
 125  1638
                                 _t = _t.getFirstChild();
 126  1638
                                 name=name(_t);
 127  1638
                                 _t = _retTree;
 128  1638
                                 e = (AST)_t;
 129  1638
                                 if ( _t==null ) throw new MismatchedTokenException();
 130  1638
                                 _t = _t.getNextSibling();
 131  1638
                                 _t = __t6;
 132  1638
                                 _t = _t.getNextSibling();
 133  
                                 {
 134  
                                 _loop8:
 135  
                                 do {
 136  1698
                                         if (_t==null) _t=ASTNULL;
 137  1698
                                         if ((_t.getType()==CHECK)) {
 138  60
                                                 AST tmp3_AST_in = (AST)_t;
 139  60
                                                 match(_t,CHECK);
 140  60
                                                 _t = _t.getNextSibling();
 141  60
                                                 c = (AST)_t;
 142  60
                                                 if ( _t==null ) throw new MismatchedTokenException();
 143  60
                                                 _t = _t.getNextSibling();
 144  
                                                 
 145  60
                                                                                                 checks.add(c);
 146  
                                                                                         
 147  30
                                         }
 148  
                                         else {
 149  
                                                 break _loop8;
 150  
                                         }
 151  
                                         
 152  30
                                 } while (true);
 153  
                                 }
 154  
                                 
 155  1638
                                                                         EntityDefinition ed = new EntityDefinition(name, e);
 156  1638
                                                                         if (!checks.isEmpty()) {
 157  60
                                                                                 ed.setChecks(new ArrayList<AST>(checks));
 158  60
                                                                                 checks.clear();
 159  
                                                                         }
 160  1638
                                                                         getEntityFactory().add(name, ed);
 161  
                                                                 
 162  1638
                         }
 163  
                         else {
 164  192
                                 if ( _cnt9>=1 ) { break _loop9; } else {throw new NoViableAltException(_t);}
 165  
                         }
 166  
                         
 167  1638
                         _cnt9++;
 168  1638
                 } while (true);
 169  
                 }
 170  192
                 _t = __t2;
 171  192
                 _t = _t.getNextSibling();
 172  192
                 _retTree = _t;
 173  192
         }
 174  
         
 175  
         protected final void defaultOptions(AST _t) throws RecognitionException {
 176  
                 
 177  18
                 AST defaultOptions_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 178  18
                 AST o = null;
 179  18
                 HashMap<String, String> m = new HashMap<String, String>(); String key = null, value = null;
 180  
                 
 181  18
                 AST __t11 = _t;
 182  18
                 o = _t==ASTNULL ? null :(AST)_t;
 183  18
                 match(_t,OPTIONS);
 184  18
                 _t = _t.getFirstChild();
 185  
                 {
 186  18
                 int _cnt14=0;
 187  
                 _loop14:
 188  
                 do {
 189  42
                         if (_t==null) _t=ASTNULL;
 190  42
                         if ((_t.getType()==ASSIGN)) {
 191  24
                                 AST __t13 = _t;
 192  24
                                 AST tmp4_AST_in = (AST)_t;
 193  24
                                 match(_t,ASSIGN);
 194  24
                                 _t = _t.getFirstChild();
 195  24
                                 key=optionKV(_t);
 196  24
                                 _t = _retTree;
 197  24
                                 value=optionKV(_t);
 198  24
                                 _t = _retTree;
 199  24
                                 m.put(key, value);
 200  24
                                 _t = __t13;
 201  24
                                 _t = _t.getNextSibling();
 202  24
                         }
 203  
                         else {
 204  18
                                 if ( _cnt14>=1 ) { break _loop14; } else {throw new NoViableAltException(_t);}
 205  
                         }
 206  
                         
 207  24
                         _cnt14++;
 208  24
                 } while (true);
 209  
                 }
 210  18
                 _t = __t11;
 211  18
                 _t = _t.getNextSibling();
 212  18
                 getEntityFactory().setDefaultOptions(o.getText(), m);
 213  18
                 _retTree = _t;
 214  18
         }
 215  
         
 216  
         protected final String  name(AST _t) throws RecognitionException {
 217  2268
                 String s = null;
 218  
                 
 219  2268
                 AST name_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 220  2268
                 AST i = null;
 221  
                 
 222  2268
                 if (_t==null) _t=ASTNULL;
 223  2268
                 switch ( _t.getType()) {
 224  
                 case IDENT:
 225  
                 {
 226  2184
                         i = (AST)_t;
 227  2184
                         match(_t,IDENT);
 228  2184
                         _t = _t.getNextSibling();
 229  2184
                         s = i.getText();
 230  2184
                         break;
 231  
                 }
 232  
                 case ANON:
 233  
                 {
 234  84
                         AST tmp5_AST_in = (AST)_t;
 235  84
                         match(_t,ANON);
 236  84
                         _t = _t.getNextSibling();
 237  84
                         break;
 238  
                 }
 239  
                 default:
 240  
                 {
 241  0
                         throw new NoViableAltException(_t);
 242  
                 }
 243  
                 }
 244  2268
                 _retTree = _t;
 245  2268
                 return s;
 246  
         }
 247  
         
 248  
         protected final String  optionKV(AST _t) throws RecognitionException {
 249  684
                 String result = null;
 250  
                 
 251  684
                 AST optionKV_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 252  684
                 AST c = null;
 253  684
                 AST s = null;
 254  684
                 AST n = null;
 255  684
                 AST i = null;
 256  
                 
 257  684
                 if (_t==null) _t=ASTNULL;
 258  684
                 switch ( _t.getType()) {
 259  
                 case CHAR_LITERAL:
 260  
                 {
 261  84
                         c = (AST)_t;
 262  84
                         match(_t,CHAR_LITERAL);
 263  84
                         _t = _t.getNextSibling();
 264  84
                         result = c.getText();
 265  84
                         break;
 266  
                 }
 267  
                 case STRING_LITERAL:
 268  
                 {
 269  72
                         s = (AST)_t;
 270  72
                         match(_t,STRING_LITERAL);
 271  72
                         _t = _t.getNextSibling();
 272  72
                         result = s.getText();
 273  72
                         break;
 274  
                 }
 275  
                 case NUMBER:
 276  
                 {
 277  0
                         n = (AST)_t;
 278  0
                         match(_t,NUMBER);
 279  0
                         _t = _t.getNextSibling();
 280  0
                         result = n.getText();
 281  0
                         break;
 282  
                 }
 283  
                 case IDENT:
 284  
                 {
 285  528
                         i = (AST)_t;
 286  528
                         match(_t,IDENT);
 287  528
                         _t = _t.getNextSibling();
 288  528
                         result = i.getText();
 289  528
                         break;
 290  
                 }
 291  
                 default:
 292  
                 {
 293  0
                         throw new NoViableAltException(_t);
 294  
                 }
 295  
                 }
 296  684
                 _retTree = _t;
 297  684
                 return result;
 298  
         }
 299  
         
 300  
         protected final Entity  entity(AST _t) throws RecognitionException {
 301  1284
                 Entity e = null;
 302  
                 
 303  1284
                 AST entity_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 304  
                 
 305  1284
                 if (_t==null) _t=ASTNULL;
 306  1284
                 switch ( _t.getType()) {
 307  
                 case ARRAY:
 308  
                 {
 309  228
                         e=array(_t);
 310  228
                         _t = _retTree;
 311  228
                         break;
 312  
                 }
 313  
                 case FIELD:
 314  
                 {
 315  768
                         e=field(_t);
 316  762
                         _t = _retTree;
 317  762
                         break;
 318  
                 }
 319  
                 case MAP:
 320  
                 {
 321  174
                         e=map(_t);
 322  174
                         _t = _retTree;
 323  174
                         break;
 324  
                 }
 325  
                 case TYPEREF:
 326  
                 {
 327  114
                         e=typeRef(_t);
 328  114
                         _t = _retTree;
 329  114
                         break;
 330  
                 }
 331  
                 default:
 332  
                 {
 333  0
                         throw new NoViableAltException(_t);
 334  
                 }
 335  
                 }
 336  1278
                 _retTree = _t;
 337  1278
                 return e;
 338  
         }
 339  
         
 340  
         protected final IndexedEntityCollection  array(AST _t) throws RecognitionException {
 341  228
                 IndexedEntityCollection a = null;
 342  
                 
 343  228
                 AST array_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 344  228
                 AST l = null;
 345  228
                 AST m = null;
 346  228
                 AST n = null;
 347  228
                 Entity prototype = null, e = null; Integer len = null, min = null, max = null;
 348  
                 
 349  228
                 AST __t22 = _t;
 350  228
                 AST tmp6_AST_in = (AST)_t;
 351  228
                 match(_t,ARRAY);
 352  228
                 _t = _t.getFirstChild();
 353  
                 {
 354  228
                 if (_t==null) _t=ASTNULL;
 355  228
                 switch ( _t.getType()) {
 356  
                 case LENGTH:
 357  
                 {
 358  186
                         l = (AST)_t;
 359  186
                         match(_t,LENGTH);
 360  186
                         _t = _t.getNextSibling();
 361  186
                         len = Integer.valueOf(l.getText());
 362  186
                         break;
 363  
                 }
 364  
                 case RANGE:
 365  
                 {
 366  24
                         AST __t24 = _t;
 367  24
                         AST tmp7_AST_in = (AST)_t;
 368  24
                         match(_t,RANGE);
 369  24
                         _t = _t.getFirstChild();
 370  
                         {
 371  24
                         if (_t==null) _t=ASTNULL;
 372  24
                         switch ( _t.getType()) {
 373  
                         case MIN:
 374  
                         {
 375  18
                                 m = (AST)_t;
 376  18
                                 match(_t,MIN);
 377  18
                                 _t = _t.getNextSibling();
 378  18
                                 min = Integer.valueOf(m.getText());
 379  18
                                 break;
 380  
                         }
 381  
                         case 3:
 382  
                         case MAX:
 383  
                         {
 384  6
                                 break;
 385  
                         }
 386  
                         default:
 387  
                         {
 388  0
                                 throw new NoViableAltException(_t);
 389  
                         }
 390  
                         }
 391  
                         }
 392  
                         {
 393  24
                         if (_t==null) _t=ASTNULL;
 394  24
                         switch ( _t.getType()) {
 395  
                         case MAX:
 396  
                         {
 397  18
                                 n = (AST)_t;
 398  18
                                 match(_t,MAX);
 399  18
                                 _t = _t.getNextSibling();
 400  18
                                 max = Integer.valueOf(n.getText());
 401  18
                                 break;
 402  
                         }
 403  
                         case 3:
 404  
                         {
 405  6
                                 break;
 406  
                         }
 407  
                         default:
 408  
                         {
 409  0
                                 throw new NoViableAltException(_t);
 410  
                         }
 411  
                         }
 412  
                         }
 413  24
                         _t = __t24;
 414  24
                         _t = _t.getNextSibling();
 415  24
                         break;
 416  
                 }
 417  
                 case PROTOTYPE:
 418  
                 {
 419  18
                         break;
 420  
                 }
 421  
                 default:
 422  
                 {
 423  0
                         throw new NoViableAltException(_t);
 424  
                 }
 425  
                 }
 426  
                 }
 427  228
                 AST __t27 = _t;
 428  228
                 AST tmp8_AST_in = (AST)_t;
 429  228
                 match(_t,PROTOTYPE);
 430  228
                 _t = _t.getFirstChild();
 431  228
                 prototype=entity(_t);
 432  228
                 _t = _retTree;
 433  228
                 _t = __t27;
 434  228
                 _t = _t.getNextSibling();
 435  228
                         a = new EntityArray(prototype);
 436  228
                                                 if (len != null) {
 437  186
                                                         ((EntityArray) a).setSize(len.intValue());
 438  93
                                                 } else {
 439  42
                                                         if (min != null) {
 440  18
                                                                 ((EntityArray) a).setMinimumSize(min.intValue());
 441  
                                                         }
 442  42
                                                         if (max != null) {
 443  18
                                                                 ((EntityArray) a).setMaximumSize(max.intValue());
 444  
                                                         }
 445  
                                                 }
 446  
                                         
 447  
                 {
 448  228
                 if (_t==null) _t=ASTNULL;
 449  228
                 switch ( _t.getType()) {
 450  
                 case OPTIONS:
 451  
                 {
 452  48
                         entityOptions(_t,a);
 453  48
                         _t = _retTree;
 454  48
                         break;
 455  
                 }
 456  
                 case 3:
 457  
                 case VALUE:
 458  
                 case ALL:
 459  
                 {
 460  180
                         break;
 461  
                 }
 462  
                 default:
 463  
                 {
 464  0
                         throw new NoViableAltException(_t);
 465  
                 }
 466  
                 }
 467  
                 }
 468  
                 {
 469  228
                 if (_t==null) _t=ASTNULL;
 470  228
                 switch ( _t.getType()) {
 471  
                 case VALUE:
 472  
                 case ALL:
 473  
                 {
 474  24
                         e=value(_t,a);
 475  24
                         _t = _retTree;
 476  24
                         a = (IndexedEntityCollection) e;
 477  24
                         break;
 478  
                 }
 479  
                 case 3:
 480  
                 {
 481  204
                         break;
 482  
                 }
 483  
                 default:
 484  
                 {
 485  0
                         throw new NoViableAltException(_t);
 486  
                 }
 487  
                 }
 488  
                 }
 489  228
                 _t = __t22;
 490  228
                 _t = _t.getNextSibling();
 491  228
                 _retTree = _t;
 492  228
                 return a;
 493  
         }
 494  
         
 495  
         protected final Entity  field(AST _t) throws RecognitionException {
 496  768
                 Entity e = null;
 497  
                 
 498  768
                 AST field_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 499  
                 
 500  768
                 AST __t34 = _t;
 501  768
                 AST tmp9_AST_in = (AST)_t;
 502  768
                 match(_t,FIELD);
 503  768
                 _t = _t.getFirstChild();
 504  768
                 e=fieldDef(_t);
 505  762
                 _t = _retTree;
 506  762
                 _t = __t34;
 507  762
                 _t = _t.getNextSibling();
 508  762
                 _retTree = _t;
 509  762
                 return e;
 510  
         }
 511  
         
 512  
         protected final NamedEntityCollection  map(AST _t) throws RecognitionException {
 513  174
                 NamedEntityCollection m = new EntityMap();
 514  
                 
 515  174
                 AST map_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 516  174
                 String name = null; Entity temp = null;
 517  
                 
 518  174
                 AST __t45 = _t;
 519  174
                 AST tmp10_AST_in = (AST)_t;
 520  174
                 match(_t,MAP);
 521  174
                 _t = _t.getFirstChild();
 522  
                 {
 523  174
                 int _cnt48=0;
 524  
                 _loop48:
 525  
                 do {
 526  804
                         if (_t==null) _t=ASTNULL;
 527  804
                         if ((_t.getType()==ASSIGN)) {
 528  630
                                 AST __t47 = _t;
 529  630
                                 AST tmp11_AST_in = (AST)_t;
 530  630
                                 match(_t,ASSIGN);
 531  630
                                 _t = _t.getFirstChild();
 532  630
                                 name=name(_t);
 533  630
                                 _t = _retTree;
 534  630
                                 temp=entity(_t);
 535  630
                                 _t = _retTree;
 536  630
                                 ((EntityMap) m).add(name, temp);
 537  630
                                 _t = __t47;
 538  630
                                 _t = _t.getNextSibling();
 539  630
                         }
 540  
                         else {
 541  174
                                 if ( _cnt48>=1 ) { break _loop48; } else {throw new NoViableAltException(_t);}
 542  
                         }
 543  
                         
 544  630
                         _cnt48++;
 545  630
                 } while (true);
 546  
                 }
 547  
                 {
 548  174
                 if (_t==null) _t=ASTNULL;
 549  174
                 switch ( _t.getType()) {
 550  
                 case OPTIONS:
 551  
                 {
 552  42
                         entityOptions(_t,m);
 553  42
                         _t = _retTree;
 554  42
                         break;
 555  
                 }
 556  
                 case 3:
 557  
                 case VALUE:
 558  
                 case ALL:
 559  
                 {
 560  132
                         break;
 561  
                 }
 562  
                 default:
 563  
                 {
 564  0
                         throw new NoViableAltException(_t);
 565  
                 }
 566  
                 }
 567  
                 }
 568  
                 {
 569  174
                 if (_t==null) _t=ASTNULL;
 570  174
                 switch ( _t.getType()) {
 571  
                 case VALUE:
 572  
                 case ALL:
 573  
                 {
 574  36
                         temp=value(_t,m);
 575  36
                         _t = _retTree;
 576  36
                         m = (NamedEntityCollection) temp;
 577  36
                         break;
 578  
                 }
 579  
                 case 3:
 580  
                 {
 581  138
                         break;
 582  
                 }
 583  
                 default:
 584  
                 {
 585  0
                         throw new NoViableAltException(_t);
 586  
                 }
 587  
                 }
 588  
                 }
 589  174
                 _t = __t45;
 590  174
                 _t = _t.getNextSibling();
 591  174
                 _retTree = _t;
 592  174
                 return m;
 593  
         }
 594  
         
 595  
         protected final Entity  typeRef(AST _t) throws RecognitionException {
 596  114
                 Entity e = null;
 597  
                 
 598  114
                 AST typeRef_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 599  114
                 AST t = null;
 600  
                 
 601  114
                 AST __t18 = _t;
 602  114
                 t = _t==ASTNULL ? null :(AST)_t;
 603  114
                 match(_t,TYPEREF);
 604  114
                 _t = _t.getFirstChild();
 605  114
                 e = getEntityFactory().getEntity(t.getText());
 606  
                 {
 607  114
                 if (_t==null) _t=ASTNULL;
 608  114
                 switch ( _t.getType()) {
 609  
                 case OPTIONS:
 610  
                 {
 611  0
                         entityOptions(_t,e);
 612  0
                         _t = _retTree;
 613  0
                         break;
 614  
                 }
 615  
                 case 3:
 616  
                 case VALUE:
 617  
                 case ALL:
 618  
                 {
 619  114
                         break;
 620  
                 }
 621  
                 default:
 622  
                 {
 623  0
                         throw new NoViableAltException(_t);
 624  
                 }
 625  
                 }
 626  
                 }
 627  
                 {
 628  114
                 if (_t==null) _t=ASTNULL;
 629  114
                 switch ( _t.getType()) {
 630  
                 case VALUE:
 631  
                 case ALL:
 632  
                 {
 633  12
                         e=value(_t,e);
 634  12
                         _t = _retTree;
 635  12
                         break;
 636  
                 }
 637  
                 case 3:
 638  
                 {
 639  102
                         break;
 640  
                 }
 641  
                 default:
 642  
                 {
 643  0
                         throw new NoViableAltException(_t);
 644  
                 }
 645  
                 }
 646  
                 }
 647  114
                 _t = __t18;
 648  114
                 _t = _t.getNextSibling();
 649  114
                 _retTree = _t;
 650  114
                 return e;
 651  
         }
 652  
         
 653  
         protected final void entityOptions(AST _t,
 654  
                 Entity e
 655  
         ) throws RecognitionException {
 656  
                 
 657  192
                 AST entityOptions_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 658  
                 
 659  192
                 AST __t53 = _t;
 660  192
                 AST tmp12_AST_in = (AST)_t;
 661  192
                 match(_t,OPTIONS);
 662  192
                 _t = _t.getFirstChild();
 663  
                 {
 664  192
                 int _cnt55=0;
 665  
                 _loop55:
 666  
                 do {
 667  510
                         if (_t==null) _t=ASTNULL;
 668  510
                         if ((_t.getType()==ASSIGN)) {
 669  318
                                 entityOption(_t,e);
 670  318
                                 _t = _retTree;
 671  159
                         }
 672  
                         else {
 673  192
                                 if ( _cnt55>=1 ) { break _loop55; } else {throw new NoViableAltException(_t);}
 674  
                         }
 675  
                         
 676  318
                         _cnt55++;
 677  318
                 } while (true);
 678  
                 }
 679  192
                 _t = __t53;
 680  192
                 _t = _t.getNextSibling();
 681  192
                 _retTree = _t;
 682  192
         }
 683  
         
 684  
         protected final Entity  value(AST _t,
 685  
                 Entity e
 686  
         ) throws RecognitionException {
 687  240
                 Entity result = e;
 688  
                 
 689  240
                 AST value_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 690  240
                 AST a = null;
 691  240
                 AST v = null;
 692  
                 
 693  
                 try {      // for error handling
 694  
                         {
 695  240
                         if (_t==null) _t=ASTNULL;
 696  240
                         switch ( _t.getType()) {
 697  
                         case ALL:
 698  
                         {
 699  42
                                 a = (AST)_t;
 700  42
                                 match(_t,ALL);
 701  42
                                 _t = _t.getNextSibling();
 702  42
                                 e.fill(getBytes(a.getText())[0]);
 703  42
                                 break;
 704  
                         }
 705  
                         case VALUE:
 706  
                         {
 707  198
                                 v = (AST)_t;
 708  198
                                 match(_t,VALUE);
 709  198
                                 _t = _t.getNextSibling();
 710  198
                                 e.setValue(getBytes(v.getText()));
 711  192
                                 break;
 712  
                         }
 713  
                         default:
 714  
                         {
 715  0
                                 throw new NoViableAltException(_t);
 716  
                         }
 717  
                         }
 718  
                         }
 719  
                         {
 720  234
                         if (_t==null) _t=ASTNULL;
 721  234
                         switch ( _t.getType()) {
 722  
                         case IMMUTABLE:
 723  
                         {
 724  12
                                 result=immutable(_t,e);
 725  12
                                 _t = _retTree;
 726  12
                                 break;
 727  
                         }
 728  
                         case 3:
 729  
                         {
 730  222
                                 break;
 731  
                         }
 732  
                         default:
 733  
                         {
 734  0
                                 throw new NoViableAltException(_t);
 735  
                         }
 736  
                         }
 737  
                         }
 738  
                 }
 739  0
                 catch (IOException exc) {
 740  
                         
 741  0
                                         throw new RuntimeException(exc);
 742  
                                 
 743  117
                 }
 744  234
                 _retTree = _t;
 745  234
                 return result;
 746  
         }
 747  
         
 748  
         protected final Entity  immutable(AST _t,
 749  
                 Entity e
 750  
         ) throws RecognitionException {
 751  66
                 Entity result = null;
 752  
                 
 753  66
                 AST immutable_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 754  
                 
 755  66
                 AST tmp13_AST_in = (AST)_t;
 756  66
                 match(_t,IMMUTABLE);
 757  66
                 _t = _t.getNextSibling();
 758  66
                 result = ImmutableEntity.of(e);
 759  66
                 _retTree = _t;
 760  66
                 return result;
 761  
         }
 762  
         
 763  
         protected final Entity  fieldDef(AST _t) throws RecognitionException {
 764  768
                 Entity e = null;
 765  
                 
 766  768
                 AST fieldDef_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 767  768
                 AST l = null;
 768  768
                 AST v = null;
 769  768
                 AST n = null;
 770  768
                 AST x = null;
 771  768
                 AST v2 = null;
 772  
                 
 773  
                 {
 774  768
                 if (_t==null) _t=ASTNULL;
 775  768
                 switch ( _t.getType()) {
 776  
                 case LENGTH:
 777  
                 {
 778  456
                         l = (AST)_t;
 779  456
                         match(_t,LENGTH);
 780  456
                         _t = _t.getNextSibling();
 781  456
                         e = getEntityFactory().createField(Integer.parseInt(l.getText()));
 782  
                         {
 783  456
                         if (_t==null) _t=ASTNULL;
 784  456
                         switch ( _t.getType()) {
 785  
                         case OPTIONS:
 786  
                         {
 787  102
                                 entityOptions(_t,e);
 788  102
                                 _t = _retTree;
 789  102
                                 break;
 790  
                         }
 791  
                         case 3:
 792  
                         case VALUE:
 793  
                         case ALL:
 794  
                         {
 795  354
                                 break;
 796  
                         }
 797  
                         default:
 798  
                         {
 799  0
                                 throw new NoViableAltException(_t);
 800  
                         }
 801  
                         }
 802  
                         }
 803  
                         {
 804  456
                         if (_t==null) _t=ASTNULL;
 805  456
                         switch ( _t.getType()) {
 806  
                         case VALUE:
 807  
                         case ALL:
 808  
                         {
 809  168
                                 e=value(_t,e);
 810  162
                                 _t = _retTree;
 811  162
                                 break;
 812  
                         }
 813  
                         case 3:
 814  
                         {
 815  288
                                 break;
 816  
                         }
 817  
                         default:
 818  
                         {
 819  0
                                 throw new NoViableAltException(_t);
 820  
                         }
 821  
                         }
 822  
                         }
 823  
                         break;
 824  
                 }
 825  
                 case VALUE:
 826  
                 {
 827  228
                         v = (AST)_t;
 828  228
                         match(_t,VALUE);
 829  228
                         _t = _t.getNextSibling();
 830  228
                         e = getEntityFactory().createField(getBytes(v.getText()));
 831  
                         {
 832  228
                         if (_t==null) _t=ASTNULL;
 833  228
                         switch ( _t.getType()) {
 834  
                         case IMMUTABLE:
 835  
                         {
 836  54
                                 e=immutable(_t,e);
 837  54
                                 _t = _retTree;
 838  54
                                 break;
 839  
                         }
 840  
                         case 3:
 841  
                         {
 842  174
                                 break;
 843  
                         }
 844  
                         default:
 845  
                         {
 846  0
                                 throw new NoViableAltException(_t);
 847  
                         }
 848  
                         }
 849  
                         }
 850  
                         break;
 851  
                 }
 852  
                 case RANGE:
 853  
                 {
 854  84
                         AST __t40 = _t;
 855  84
                         AST tmp14_AST_in = (AST)_t;
 856  84
                         match(_t,RANGE);
 857  84
                         _t = _t.getFirstChild();
 858  84
                         e = getEntityFactory().createDynamicField();
 859  
                         {
 860  84
                         if (_t==null) _t=ASTNULL;
 861  84
                         switch ( _t.getType()) {
 862  
                         case MIN:
 863  
                         {
 864  42
                                 n = (AST)_t;
 865  42
                                 match(_t,MIN);
 866  42
                                 _t = _t.getNextSibling();
 867  42
                                 ((DynamicField) e).getBounds().setMinimum(Integer.parseInt(n.getText()));
 868  42
                                 break;
 869  
                         }
 870  
                         case 3:
 871  
                         case MAX:
 872  
                         {
 873  42
                                 break;
 874  
                         }
 875  
                         default:
 876  
                         {
 877  0
                                 throw new NoViableAltException(_t);
 878  
                         }
 879  
                         }
 880  
                         }
 881  
                         {
 882  84
                         if (_t==null) _t=ASTNULL;
 883  84
                         switch ( _t.getType()) {
 884  
                         case MAX:
 885  
                         {
 886  48
                                 x = (AST)_t;
 887  48
                                 match(_t,MAX);
 888  48
                                 _t = _t.getNextSibling();
 889  48
                                 ((DynamicField) e).getBounds().setMaximum(Integer.parseInt(x.getText()));
 890  48
                                 break;
 891  
                         }
 892  
                         case 3:
 893  
                         {
 894  36
                                 break;
 895  
                         }
 896  
                         default:
 897  
                         {
 898  0
                                 throw new NoViableAltException(_t);
 899  
                         }
 900  
                         }
 901  
                         }
 902  84
                         _t = __t40;
 903  84
                         _t = _t.getNextSibling();
 904  
                         {
 905  84
                         if (_t==null) _t=ASTNULL;
 906  84
                         switch ( _t.getType()) {
 907  
                         case VALUE:
 908  
                         {
 909  6
                                 v2 = (AST)_t;
 910  6
                                 match(_t,VALUE);
 911  6
                                 _t = _t.getNextSibling();
 912  6
                                 e.setValue(getBytes(v2.getText()));
 913  6
                                 break;
 914  
                         }
 915  
                         case 3:
 916  
                         {
 917  78
                                 break;
 918  
                         }
 919  
                         default:
 920  
                         {
 921  0
                                 throw new NoViableAltException(_t);
 922  
                         }
 923  
                         }
 924  
                         }
 925  
                         break;
 926  
                 }
 927  
                 default:
 928  
                 {
 929  0
                         throw new NoViableAltException(_t);
 930  
                 }
 931  
                 }
 932  
                 }
 933  762
                 _retTree = _t;
 934  762
                 return e;
 935  
         }
 936  
         
 937  
         protected final void entityOption(AST _t,
 938  
                 Entity e
 939  
         ) throws RecognitionException {
 940  
                 
 941  318
                 AST entityOption_AST_in = (_t == ASTNULL) ? null : (AST)_t;
 942  318
                 String key = null, value = null;
 943  
                 
 944  318
                 AST __t57 = _t;
 945  318
                 AST tmp15_AST_in = (AST)_t;
 946  318
                 match(_t,ASSIGN);
 947  318
                 _t = _t.getFirstChild();
 948  318
                 key=optionKV(_t);
 949  318
                 _t = _retTree;
 950  318
                 value=optionKV(_t);
 951  318
                 _t = _retTree;
 952  318
                 ApplyOptions.apply(e, key, value);
 953  318
                 _t = __t57;
 954  318
                 _t = _t.getNextSibling();
 955  318
                 _retTree = _t;
 956  318
         }
 957  
         
 958  
         
 959  9
         public static final String[] _tokenNames = {
 960  3
                 "<0>",
 961  3
                 "EOF",
 962  3
                 "<2>",
 963  3
                 "NULL_TREE_LOOKAHEAD",
 964  3
                 "ROOT",
 965  3
                 "CHECK",
 966  3
                 "VALUE",
 967  3
                 "ALL",
 968  3
                 "FIELD",
 969  3
                 "LENGTH",
 970  3
                 "ARRAY",
 971  3
                 "IMMUTABLE",
 972  3
                 "MAP",
 973  3
                 "PROTOTYPE",
 974  3
                 "OPTIONS",
 975  3
                 "MIN",
 976  3
                 "MAX",
 977  3
                 "OPTION_BLOCK",
 978  3
                 "SEMI",
 979  3
                 "IDENT",
 980  3
                 "ANON",
 981  3
                 "COLON",
 982  3
                 "TYPEREF",
 983  3
                 "LBRACK",
 984  3
                 "RBRACK",
 985  3
                 "CHAR_LITERAL",
 986  3
                 "STAR",
 987  3
                 "STRING_LITERAL",
 988  3
                 "BANG",
 989  3
                 "LPAREN",
 990  3
                 "RPAREN",
 991  3
                 "LCURLY",
 992  3
                 "COMMA",
 993  3
                 "RCURLY",
 994  3
                 "NUMBER",
 995  3
                 "RANGE",
 996  3
                 "ASSIGN",
 997  3
                 "WS",
 998  3
                 "SL_COMMENT",
 999  3
                 "ML_COMMENT",
 1000  3
                 "NL",
 1001  3
                 "PTIDENT",
 1002  3
                 "CHAR_BODY",
 1003  3
                 "STRING_BODY",
 1004  3
                 "ESC",
 1005  3
                 "UNICODE",
 1006  3
                 "OCTAL",
 1007  3
                 "HEX_DIGIT"
 1008  3
         };
 1009  
         
 1010  
         }
 1011