001 // $ANTLR 2.7.4: "schema-qdstring.g" -> "AntlrSchemaQdstringParser.java"$
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 *
021 */
022 package org.apache.directory.shared.ldap.schema.syntax;
023
024 import java.util.ArrayList;
025 import java.util.List;
026
027 import org.apache.directory.shared.ldap.schema.parsers.ParserMonitor;
028
029
030 import antlr.TokenBuffer;
031 import antlr.TokenStreamException;
032 import antlr.TokenStreamIOException;
033 import antlr.ANTLRException;
034 import antlr.LLkParser;
035 import antlr.Token;
036 import antlr.TokenStream;
037 import antlr.RecognitionException;
038 import antlr.NoViableAltException;
039 import antlr.MismatchedTokenException;
040 import antlr.SemanticException;
041 import antlr.ParserSharedInputState;
042 import antlr.collections.impl.BitSet;
043
044 /**
045 * An antlr generated schema parser. This is a sub-parser used to parse
046 * qdstring and qdstrings according to RFC4512.
047 *
048 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
049 * @version $Rev$
050 */
051 public class AntlrSchemaQdstringParser extends antlr.LLkParser implements AntlrSchemaQdstringTokenTypes
052 {
053
054 private ParserMonitor monitor = null;
055 public void setParserMonitor( ParserMonitor monitor )
056 {
057 this.monitor = monitor;
058 }
059 private void matchedProduction( String msg )
060 {
061 if ( null != monitor )
062 {
063 monitor.matchedProduction( msg );
064 }
065 }
066
067 protected AntlrSchemaQdstringParser(TokenBuffer tokenBuf, int k) {
068 super(tokenBuf,k);
069 tokenNames = _tokenNames;
070 }
071
072 public AntlrSchemaQdstringParser(TokenBuffer tokenBuf) {
073 this(tokenBuf,3);
074 }
075
076 protected AntlrSchemaQdstringParser(TokenStream lexer, int k) {
077 super(lexer,k);
078 tokenNames = _tokenNames;
079 }
080
081 public AntlrSchemaQdstringParser(TokenStream lexer) {
082 this(lexer,3);
083 }
084
085 public AntlrSchemaQdstringParser(ParserSharedInputState state) {
086 super(state,3);
087 tokenNames = _tokenNames;
088 }
089
090 /**
091 * qdstrings = qdstring / ( LPAREN WSP qdstringlist WSP RPAREN )
092 * qdstringlist = [ qdstring *( SP qdstring ) ]
093 */
094 public final List<String> qdstrings() throws RecognitionException, TokenStreamException {
095 List<String> qdstrings;
096
097 Token q = null;
098
099 matchedProduction( "AntlrSchemaQdstringParser.qdstrings()" );
100 qdstrings = new ArrayList<String>();
101 String qdstring = null;
102
103
104 {
105 switch ( LA(1)) {
106 case QDSTRING:
107 {
108 {
109 q = LT(1);
110 match(QDSTRING);
111
112 qdstring = q.getText();
113 if(qdstring.startsWith("'")) {
114 qdstring = qdstring.substring(1, qdstring.length());
115 }
116 if(qdstring.endsWith("'")) {
117 qdstring = qdstring.substring(0, qdstring.length()-1);
118 }
119 qdstring = qdstring.replaceAll("\\\\5C", "\\\\");
120 qdstring = qdstring.replaceAll("\\\\5c", "\\\\");
121 qdstring = qdstring.replaceAll("\\\\27", "'");
122 qdstrings.add(qdstring);
123
124 }
125 break;
126 }
127 case LPAR:
128 {
129 {
130 match(LPAR);
131 qdstring=qdstring();
132 qdstrings.add(qdstring);
133 {
134 _loop963:
135 do {
136 if ((LA(1)==QDSTRING)) {
137 qdstring=qdstring();
138 qdstrings.add(qdstring);
139 }
140 else {
141 break _loop963;
142 }
143
144 } while (true);
145 }
146 match(RPAR);
147 }
148 break;
149 }
150 default:
151 {
152 throw new NoViableAltException(LT(1), getFilename());
153 }
154 }
155 }
156 return qdstrings;
157 }
158
159 /**
160 * qdstring = SQUOTE dstring SQUOTE
161 * dstring = 1*( QS / QQ / QUTF8 ) ; escaped UTF-8 string
162 *
163 * QQ = ESC %x32 %x37 ; "\27"
164 * QS = ESC %x35 ( %x43 / %x63 ) ; "\5C" / "\5c"
165 *
166 * ; Any UTF-8 encoded Unicode character
167 * ; except %x27 ("\'") and %x5C ("\")
168 * QUTF8 = QUTF1 / UTFMB
169 *
170 * ; Any ASCII character except %x27 ("\'") and %x5C ("\")
171 * QUTF1 = %x00-26 / %x28-5B / %x5D-7F
172 */
173 public final String qdstring() throws RecognitionException, TokenStreamException {
174 String qdstring=null;
175
176 Token q = null;
177
178 matchedProduction( "AntlrSchemaQdstringParser.qdstring()" );
179
180
181 {
182 q = LT(1);
183 match(QDSTRING);
184
185 qdstring = q.getText();
186 if(qdstring.startsWith("'")) {
187 qdstring = qdstring.substring(1, qdstring.length());
188 }
189 if(qdstring.endsWith("'")) {
190 qdstring = qdstring.substring(0, qdstring.length()-1);
191 }
192 qdstring = qdstring.replaceAll("\\\\5C", "\\\\");
193 qdstring = qdstring.replaceAll("\\\\5c", "\\\\");
194 qdstring = qdstring.replaceAll("\\\\27", "'");
195
196 }
197 return qdstring;
198 }
199
200
201 public static final String[] _tokenNames = {
202 "<0>",
203 "EOF",
204 "<2>",
205 "NULL_TREE_LOOKAHEAD",
206 "WHSP",
207 "LPAR",
208 "RPAR",
209 "QUOTE",
210 "QDSTRING"
211 };
212
213
214 }