001    // $ANTLR 2.7.4: "schema-extension.g" -> "AntlrSchemaExtensionParser.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.io.StringReader;
025    import java.util.List;
026    
027    
028    import antlr.TokenBuffer;
029    import antlr.TokenStreamException;
030    import antlr.TokenStreamIOException;
031    import antlr.ANTLRException;
032    import antlr.LLkParser;
033    import antlr.Token;
034    import antlr.TokenStream;
035    import antlr.RecognitionException;
036    import antlr.NoViableAltException;
037    import antlr.MismatchedTokenException;
038    import antlr.SemanticException;
039    import antlr.ParserSharedInputState;
040    import antlr.collections.impl.BitSet;
041    
042    /**
043     * An antlr generated schema parser. This is a sub-parser used to parse
044     * extensions according to RFC4512.
045     *
046     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
047     * @version $Rev$
048     */
049    public class AntlrSchemaExtensionParser extends antlr.LLkParser       implements AntlrSchemaExtensionTokenTypes
050     {
051    
052    protected AntlrSchemaExtensionParser(TokenBuffer tokenBuf, int k) {
053      super(tokenBuf,k);
054      tokenNames = _tokenNames;
055    }
056    
057    public AntlrSchemaExtensionParser(TokenBuffer tokenBuf) {
058      this(tokenBuf,3);
059    }
060    
061    protected AntlrSchemaExtensionParser(TokenStream lexer, int k) {
062      super(lexer,k);
063      tokenNames = _tokenNames;
064    }
065    
066    public AntlrSchemaExtensionParser(TokenStream lexer) {
067      this(lexer,3);
068    }
069    
070    public AntlrSchemaExtensionParser(ParserSharedInputState state) {
071      super(state,3);
072      tokenNames = _tokenNames;
073    }
074    
075    /**
076         * extensions = *( SP xstring SP qdstrings )
077         * xstring = "X" HYPHEN 1*( ALPHA / HYPHEN / USCORE )
078         */
079            public final AntlrSchemaParser.Extension  extension() throws RecognitionException, TokenStreamException {
080                    AntlrSchemaParser.Extension extension = new AntlrSchemaParser.Extension();
081                    
082                    Token  xkey = null;
083                    Token  xvalues = null;
084                    
085                    {
086                    xkey = LT(1);
087                    match(XKEY);
088                    extension.key = xkey.getText();
089                    }
090                    {
091                    xvalues = LT(1);
092                    match(XVALUES);
093                    extension.values = qdstrings(xvalues.getText());
094                    }
095                    return extension;
096            }
097            
098            public final List<String>  qdstrings(
099                    String s
100            ) throws RecognitionException, TokenStreamException {
101                    List<String> qdstrings;
102                    
103                    
104                    try 
105                    {
106                    AntlrSchemaQdstringLexer lexer = new AntlrSchemaQdstringLexer(new StringReader(s));
107                    AntlrSchemaQdstringParser parser = new AntlrSchemaQdstringParser(lexer);
108                    qdstrings = parser.qdstrings();
109                    }
110                    catch (RecognitionException re) {
111                    re.printStackTrace();
112                    throw re;
113                    }
114                    catch (TokenStreamException tse) {
115                    tse.printStackTrace();
116                    throw tse;
117                    }
118                    
119                    
120                    return qdstrings;
121            }
122            
123            
124            public static final String[] _tokenNames = {
125                    "<0>",
126                    "EOF",
127                    "<2>",
128                    "NULL_TREE_LOOKAHEAD",
129                    "WHSP",
130                    "QUOTE",
131                    "XKEY",
132                    "XVALUES",
133                    "XSTRING",
134                    "VALUES",
135                    "VALUE",
136                    "QUOTED_STRING"
137            };
138            
139            
140            }