Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

com/ohrasys/cad/bnf/validator/BracketedTermValidator.java

Go to the documentation of this file.
00001 package com.ohrasys.cad.bnf.validator;
00002 import com.ohrasys.cad.bnf.*;
00003 import java.util.*;
00004 
00005 public class BracketedTermValidator
00006   extends BNFRequiredTest {
00007   public BracketedTermValidator()
00008     throws BNFTestException {super(createTests());}
00009 
00010   private static BNFTestImplementor[] createTests()
00011     throws BNFTestException {
00012     BNFTestImplementor result[] = new BNFTestImplementor[] {
00013         new WhitespaceValidator(), new BNFNoFallthruTest('['),
00014         new FactorsValidator(), new BNFNoFallthruTest(']'),
00015         new WhitespaceValidator()
00016       };
00017     return result;
00018   }
00019   public Object collect(){
00020     if(formatting){
00021       return format(ValidatorUtils.flattenList((List)super.collect()));
00022     } else { 
00023       return ValidatorUtils.flattenList((List)super.collect());
00024     }
00025   }
00026   
00027   private Object format(Object tokens){
00028     if(!(tokens instanceof List)) return tokens;    
00029     ValidatorFormattingRules rules = null;
00030     StringBuffer result = new StringBuffer(((List)tokens).size());
00031     List tokenList = (List)tokens;
00032     for(int i = 0; i < tokenList.size(); i++){
00033       result.append(tokenList.get(i));
00034         result.append(" ");
00035     }
00036     StringBuffer newResult = new StringBuffer(result.toString().trim());
00037     newResult.deleteCharAt(newResult.indexOf(" "));
00038     newResult.deleteCharAt(newResult.lastIndexOf(" "));
00039     for(int i = 0; i < rules.groupingSymbolInteriorWhitespace; i++) {
00040       newResult.insert(newResult.indexOf("[")+1," ");
00041       newResult.insert(newResult.indexOf("]")," ");
00042     }
00043     return newResult.toString().trim();
00044   }}

Generated on Sun Nov 13 10:13:03 2005 for JavaBackus-NaurTestAPI(JBNT) by  doxygen 1.4.2