KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > utils > parser > RangeProductionRules


1 package com.daffodilwoods.daffodildb.utils.parser;
2
3 public class RangeProductionRules extends ProductionRules{
4
5    RangeProductionRules(ClassLoader JavaDoc classLoader0){
6      super(classLoader0);
7      ruleKey = nameOfRule;
8    }
9
10    /**
11     * This function receives ParseElements as an argument.
12     * Loop starts from current position . If it is in range then it traverse
13     * through whole string till next element not in range. and accumulate everything in an
14     * StringBuffer && returns that result.
15     */

16    Object JavaDoc parsePart(ParseElements pe){
17       int position = pe.position;
18       char[] val = pe.queryArray;
19       int length = val.length;
20       Object JavaDoc ob = parseComments(pe);
21         if(ob instanceof ParseException )
22           return ob;
23         position = ((Integer JavaDoc)ob).intValue() ;
24
25
26 // case ---- :: AIOB caught & exception returned beacuse ; not found */
27
if(position >= val.length )
28          return pe.parseException ;
29       if( checkForDigit(val[position]) )
30          return pe.parseException;
31       StringBuffer JavaDoc stbfr = new StringBuffer JavaDoc(); // StringBuffer is used to buffer
32
while(position < length){
33         if(position < length && (checkForDigit(val[position]) || checkForAlphabet(val[position])) ){
34               stbfr.append(val[position]);
35            position ++;
36         }
37         else{
38            pe.position = position;
39            if ( stbfr.length() == 0 )
40               return pe.parseException;
41            return stbfr.toString();
42         }
43       }
44       if ( stbfr.length() != 0 ){
45            pe.position = position;
46            return stbfr.toString();
47       }
48       return pe.parseException;
49    }
50
51    private boolean checkForDigit(char c){
52       if ( c >= 48 && c <= 57 )
53         return true;
54       return false;
55    }
56
57    private boolean checkForAlphabet(char c){
58       if ( (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c == 95) /*|| c == 10*/)
59         return true;
60       return false;
61    }
62 }
63
Popular Tags