View Javadoc
1   // $ANTLR 2.7.7 (20060906): "schema-qdstring.g" -> "AntlrSchemaQdstringParser.java"$
2   
3   /*
4    *  Licensed to the Apache Software Foundation (ASF) under one
5    *  or more contributor license agreements.  See the NOTICE file
6    *  distributed with this work for additional information
7    *  regarding copyright ownership.  The ASF licenses this file
8    *  to you under the Apache License, Version 2.0 (the
9    *  "License"); you may not use this file except in compliance
10   *  with the License.  You may obtain a copy of the License at
11   *  
12   *    http://www.apache.org/licenses/LICENSE-2.0
13   *  
14   *  Unless required by applicable law or agreed to in writing,
15   *  software distributed under the License is distributed on an
16   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   *  KIND, either express or implied.  See the License for the
18   *  specific language governing permissions and limitations
19   *  under the License. 
20   *  
21   */
22  package org.apache.directory.api.ldap.model.schema.syntaxes;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import org.apache.directory.api.ldap.model.schema.parsers.ParserMonitor;
28  
29  
30  import antlr.TokenBuffer;
31  import antlr.TokenStreamException;
32  import antlr.TokenStreamIOException;
33  import antlr.ANTLRException;
34  import antlr.LLkParser;
35  import antlr.Token;
36  import antlr.TokenStream;
37  import antlr.RecognitionException;
38  import antlr.NoViableAltException;
39  import antlr.MismatchedTokenException;
40  import antlr.SemanticException;
41  import antlr.ParserSharedInputState;
42  import antlr.collections.impl.BitSet;
43  
44  /**
45   * An antlr generated schema parser. This is a sub-parser used to parse
46   * qdstring and qdstrings according to RFC4512.
47   *
48   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
49   */
50  public class AntlrSchemaQdstringParser extends antlr.LLkParser       implements AntlrSchemaQdstringTokenTypes
51   {
52  
53      private ParserMonitor monitor = null;
54      public void setParserMonitor( ParserMonitor monitor )
55      {
56          this.monitor = monitor;
57      }
58      private void matchedProduction( String msg )
59      {
60          if ( null != monitor )
61          {
62              monitor.matchedProduction( msg );
63          }
64      }
65  
66  protected AntlrSchemaQdstringParser(TokenBuffer tokenBuf, int k) {
67    super(tokenBuf,k);
68    tokenNames = _tokenNames;
69  }
70  
71  public AntlrSchemaQdstringParser(TokenBuffer tokenBuf) {
72    this(tokenBuf,3);
73  }
74  
75  protected AntlrSchemaQdstringParser(TokenStream lexer, int k) {
76    super(lexer,k);
77    tokenNames = _tokenNames;
78  }
79  
80  public AntlrSchemaQdstringParser(TokenStream lexer) {
81    this(lexer,3);
82  }
83  
84  public AntlrSchemaQdstringParser(ParserSharedInputState state) {
85    super(state,3);
86    tokenNames = _tokenNames;
87  }
88  
89  /**
90       * qdstrings = qdstring / ( LPAREN WSP qdstringlist WSP RPAREN )
91       * qdstringlist = [ qdstring *( SP qdstring ) ]
92       */
93  	public final List<String>  qdstrings() throws RecognitionException, TokenStreamException {
94  		List<String> qdstrings;
95  		
96  		Token  q = null;
97  		
98  		matchedProduction( "AntlrSchemaQdstringParser.qdstrings()" );
99  		qdstrings = new ArrayList<String>();
100 		String qdstring = null;
101 		
102 		
103 		{
104 		switch ( LA(1)) {
105 		case QDSTRING:
106 		{
107 			{
108 			q = LT(1);
109 			match(QDSTRING);
110 			
111 			qdstring = q.getText(); 
112 			if(qdstring.startsWith("'")) {
113 			qdstring = qdstring.substring(1, qdstring.length());
114 			}
115 			if(qdstring.endsWith("'")) {
116 			qdstring = qdstring.substring(0, qdstring.length()-1);
117 			}
118 			qdstring = qdstring.replaceAll("\\\\5C", "\\\\");
119 			qdstring = qdstring.replaceAll("\\\\5c", "\\\\");
120 			qdstring = qdstring.replaceAll("\\\\27", "'");
121 			qdstrings.add(qdstring);
122 			
123 			}
124 			break;
125 		}
126 		case LPAR:
127 		{
128 			{
129 			match(LPAR);
130 			qdstring=qdstring();
131 			qdstrings.add(qdstring);
132 			{
133 			_loop17:
134 			do {
135 				if ((LA(1)==QDSTRING)) {
136 					qdstring=qdstring();
137 					qdstrings.add(qdstring);
138 				}
139 				else {
140 					break _loop17;
141 				}
142 				
143 			} while (true);
144 			}
145 			match(RPAR);
146 			}
147 			break;
148 		}
149 		default:
150 		{
151 			throw new NoViableAltException(LT(1), getFilename());
152 		}
153 		}
154 		}
155 		return qdstrings;
156 	}
157 	
158 /**
159      * qdstring = SQUOTE dstring SQUOTE
160      * dstring = 1*( QS / QQ / QUTF8 )   ; escaped UTF-8 string
161      *
162      * QQ =  ESC %x32 %x37 ; "\27"
163      * QS =  ESC %x35 ( %x43 / %x63 ) ; "\5C" / "\5c"
164      *
165      * ; Any UTF-8 encoded Unicode character
166      * ; except %x27 ("\'") and %x5C ("\")
167      * QUTF8    = QUTF1 / UTFMB
168      *
169      * ; Any ASCII character except %x27 ("\'") and %x5C ("\")
170      * QUTF1    = %x00-26 / %x28-5B / %x5D-7F
171      */
172 	public final String  qdstring() throws RecognitionException, TokenStreamException {
173 		String qdstring=null;
174 		
175 		Token  q = null;
176 		
177 		matchedProduction( "AntlrSchemaQdstringParser.qdstring()" );
178 		
179 		
180 		{
181 		q = LT(1);
182 		match(QDSTRING);
183 		
184 		qdstring = q.getText(); 
185 		if(qdstring.startsWith("'")) {
186 		qdstring = qdstring.substring(1, qdstring.length());
187 		}
188 		if(qdstring.endsWith("'")) {
189 		qdstring = qdstring.substring(0, qdstring.length()-1);
190 		}
191 		qdstring = qdstring.replaceAll("\\\\5C", "\\\\");
192 		qdstring = qdstring.replaceAll("\\\\5c", "\\\\");
193 		qdstring = qdstring.replaceAll("\\\\27", "'");
194 		
195 		}
196 		return qdstring;
197 	}
198 	
199 	
200 	public static final String[] _tokenNames = {
201 		"<0>",
202 		"EOF",
203 		"<2>",
204 		"NULL_TREE_LOOKAHEAD",
205 		"WHSP",
206 		"LPAR",
207 		"RPAR",
208 		"QUOTE",
209 		"QDSTRING"
210 	};
211 	
212 	
213 	}