All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.parse.GrammarIndexer Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.parse;

import java.util.ArrayList;
import java.util.List;

public class GrammarIndexer {
   
   private final List literals;
   private final List values;

   public GrammarIndexer() {
      this.literals = new ArrayList();
      this.values = new ArrayList();
   }
   
   public List list(){
      return literals;
   }
   
   public String literal(String value) {
      int index = literals.indexOf(value);
      
      if (index == -1) {
         literals.add(value);
         return value;
      }
      return literals.get(index);
   }

   public String resolve(int index) {
      return literals.get(index);
   }

   public int index(String value) {
      int index = values.indexOf(value);
      int size = values.size();
      
      if (index == -1) {
         values.add(value);
         return size;
      }
      return index;
   }

   public String value(int index) {
      return values.get(index);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy