system/src/sc/parser/IndexedChoice.java
public void put(String key, Parselet parselet) {
      // Adding the same parselet against more than one key is ok but don't add that twice to the global list.
      int slotIx = parselets.indexOf(parselet);
      if (slotIx == -1) {
         slotIx = parselets.size();
         parselets.add(parselet);
      }

      OrderedChoice.MatchResult l;

      if ((l = indexedParselets.get(key)) == null) {
         indexedKeys.add(key);
         l = new OrderedChoice.MatchResult();
         l.add(parselet);
         // TODO: performance.  This is not always the case - if we register for 'break' default parselet is identifier which matches 'breakfast' it should be added.
         // But if we register for a key like %> which does not match the extra parselet, we should not add it here.  Can we match the key against the parselet and do this conditionally?
         l.addAll(defaultParselets); // Sometimes need to check the default parselets if the indexed choice fails
         l.addSlotIndex(slotIx, 0);
         for (int i = 0; i < defaultParselets.size(); i++)
            l.addSlotIndex(defaultParselets.slotIndexes[i], 0);
         indexedParselets.put(key, l);
      }
      else {
         // Put this just before the first default parselet so we preserve the
         // original "put" order in the testing.
         if (defaultParselets.size() == 0)
            l.add(parselet);
         else {
            int i;
            for (i = 0; i < l.size(); i++)
               if (l.get(i) == defaultParselets.get(0))
                  break;
            l.add(i, parselet);
         }
         l.resetSlotIndexes(this);
      }
   }
/**
    *  Adds an entry for an indexed parselet.  You can use this if you have
    *  a long list of choices where the first token in each choice is a simple string.
    *  Instead of testing each rule (and doing a string compare for each rule), this will do an 
    *  indexed lookup to select the proper rule.  Internally we use the efficient SymbolChoice
    *  to peek ahead into the stream to see if we have a token which matches the input stream.
    *
    *  If you call this more than once, the order in which you register parselets for the given key
    *  is used to determine the order in which they are tested.  internally, for each key, we build
    *  a list of the parselet indexes required so we can rapidly select the right choices.
    */
Adds an entry for an indexed parselet.  You can use this if you have
a long list of choices where the first token in each choice is a simple string.
Instead of testing each rule (and doing a string compare for each rule), this will do an
indexed lookup to select the proper rule.  Internally we use the efficient SymbolChoice
to peek ahead into the stream to see if we have a token which matches the input stream.

If you call this more than once, the order in which you register parselets for the given key
is used to determine the order in which they are tested.  internally, for each key, we build
a list of the parselet indexes required so we can rapidly select the right choices.
Adds an entry for an indexed parselet . You can use this if you have a long list of choices where the first token in each choice is a simple string . Instead of testing each rule ( and doing a string compare for each rule ) this will do an indexed lookup to select the proper rule . Internally we use the efficient SymbolChoice to peek ahead into the stream to see if we have a token which matches the input stream . If you call this more than once the order in which you register parselets for the given key is used to determine the order in which they are tested . internally for each key we build a list of the parselet indexes required so we can rapidly select the right choices .
public void put(String key, Parselet parselet) {
      int slotIx = parselets.indexOf(parselet);
      if (slotIx == -1) {
         slotIx = parselets.size();
         parselets.add(parselet);
      }
      OrderedChoice.MatchResult l;
      if ((l = indexedParselets.get(key)) == null) {
         indexedKeys.add(key);
         l = new OrderedChoice.MatchResult();
         l.add(parselet);
         l.addAll(defaultParselets); 
         l.addSlotIndex(slotIx, 0);
         for (int i = 0; i < defaultParselets.size(); i++)
            l.addSlotIndex(defaultParselets.slotIndexes[i], 0);
         indexedParselets.put(key, l);
      }
      else {
         if (defaultParselets.size() == 0)
            l.add(parselet);
         else {
            int i;
            for (i = 0; i < l.size(); i++)
               if (l.get(i) == defaultParselets.get(0))
                  break;
            l.add(i, parselet);
         }
         l.resetSlotIndexes(this);
      }
   }
public void put ( String key , Parselet parselet ) { int slotIx = parselets . indexOf ( parselet ) ; if ( slotIx == - 1 ) { slotIx = parselets . size ( ) ; parselets . add ( parselet ) ; } OrderedChoice . MatchResult l ; if ( ( l = indexedParselets . get ( key ) ) == null ) { indexedKeys . add ( key ) ; l = new OrderedChoice . MatchResult ( ) ; l . add ( parselet ) ; l . addAll ( defaultParselets ) ; l . addSlotIndex ( slotIx , 0 ) ; for ( int i = 0 ; i < defaultParselets . size ( ) ; i ++ ) l . addSlotIndex ( defaultParselets . slotIndexes [ i ] , 0 ) ; indexedParselets . put ( key , l ) ; } else { if ( defaultParselets . size ( ) == 0 ) l . add ( parselet ) ; else { int i ; for ( i = 0 ; i < l . size ( ) ; i ++ ) if ( l . get ( i ) == defaultParselets . get ( 0 ) ) break ; l . add ( i , parselet ) ; } l . resetSlotIndexes ( this ) ; } }
Adds an entry for an indexed parselet.
Adds an entry for an indexed parselet .
// Adding the same parselet against more than one key is ok but don't add that twice to the global list. // TODO: performance.  This is not always the case - if we register for 'break' default parselet is identifier which matches 'breakfast' it should be added. // But if we register for a key like %> which does not match the extra parselet, we should not add it here.  Can we match the key against the parselet and do this conditionally? // Sometimes need to check the default parselets if the indexed choice fails // Put this just before the first default parselet so we preserve the // original "put" order in the testing.