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

com/ohrasys/cad/bnf/validator/RuleValidator.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 RuleValidator
00006   extends BNFRequiredTest {
00007   public RuleValidator()
00008     throws BNFTestException {super(createTests());}
00009 
00010   private static BNFTestImplementor[] createTests()
00011     throws BNFTestException {
00012     BNFTestImplementor result[] = new BNFTestImplementor[] {
00013         new IdentifierValidator(), new AssignmentValidator(),
00014         new BNFOneOrMoreRequiredTest(
00015           new BNFTestImplementor[] {new TermValidator()}
00016           ), new BNFNoFallthruTest(';')
00017       };
00018     return result;
00019   }
00020 
00021   public Object collect(){
00022     if(formatting){
00023       return format(ValidatorUtils.flattenList((List)super.collect()));
00024     } else { 
00025       return ValidatorUtils.flattenList((List)super.collect());
00026     }
00027   }
00028   
00029   private Object format(Object tokens){
00030     if(!(tokens instanceof List)) return tokens;    
00031     ValidatorFormattingRules rules = null;
00032     StringBuffer result = new StringBuffer(((List)tokens).size());
00033     List tokenList = (List)tokens;
00034     for(int i = 0; i < tokenList.size(); i++){
00035       result.append(tokenList.get(i));
00036       result.append(" ");
00037     }
00038     StringBuffer newResult = new StringBuffer(result.toString().trim());
00039     newResult.deleteCharAt(newResult.lastIndexOf(" "));
00040     for(int i = 0; i < rules.terminatorLeadingWhitespace; i++)
00041       newResult.insert(newResult.lastIndexOf(";"), " ");
00042     return newResult.toString();
00043   }
00044 }

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