001// $ANTLR 2.7.7 (20060906): "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 */
022package org.apache.directory.api.ldap.model.schema.syntaxes;
023
024import java.util.ArrayList;
025import java.util.List;
026
027import org.apache.directory.api.ldap.model.schema.parsers.ParserMonitor;
028
029
030import antlr.TokenBuffer;
031import antlr.TokenStreamException;
032import antlr.TokenStreamIOException;
033import antlr.ANTLRException;
034import antlr.LLkParser;
035import antlr.Token;
036import antlr.TokenStream;
037import antlr.RecognitionException;
038import antlr.NoViableAltException;
039import antlr.MismatchedTokenException;
040import antlr.SemanticException;
041import antlr.ParserSharedInputState;
042import 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 */
050public class AntlrSchemaQdstringParser extends antlr.LLkParser       implements AntlrSchemaQdstringTokenTypes
051 {
052
053    private ParserMonitor monitor = null;
054    public void setParserMonitor( ParserMonitor monitor )
055    {
056        this.monitor = monitor;
057    }
058    private void matchedProduction( String msg )
059    {
060        if ( null != monitor )
061        {
062            monitor.matchedProduction( msg );
063        }
064    }
065
066protected AntlrSchemaQdstringParser(TokenBuffer tokenBuf, int k) {
067  super(tokenBuf,k);
068  tokenNames = _tokenNames;
069}
070
071public AntlrSchemaQdstringParser(TokenBuffer tokenBuf) {
072  this(tokenBuf,3);
073}
074
075protected AntlrSchemaQdstringParser(TokenStream lexer, int k) {
076  super(lexer,k);
077  tokenNames = _tokenNames;
078}
079
080public AntlrSchemaQdstringParser(TokenStream lexer) {
081  this(lexer,3);
082}
083
084public AntlrSchemaQdstringParser(ParserSharedInputState state) {
085  super(state,3);
086  tokenNames = _tokenNames;
087}
088
089/**
090     * qdstrings = qdstring / ( LPAREN WSP qdstringlist WSP RPAREN )
091     * qdstringlist = [ qdstring *( SP qdstring ) ]
092     */
093        public final List<String>  qdstrings() throws RecognitionException, TokenStreamException {
094                List<String> qdstrings;
095                
096                Token  q = null;
097                
098                matchedProduction( "AntlrSchemaQdstringParser.qdstrings()" );
099                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        }