001    // $ANTLR 2.7.4: "distinguishedName.g" -> "AntlrDnParser.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.name;
023    
024    import java.io.StringReader;
025    import java.util.ArrayList;
026    import java.util.HashMap;
027    import java.util.List;
028    import java.util.Map;
029    
030    import javax.naming.InvalidNameException;
031    import javax.naming.NameParser;
032    import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
033    import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
034    import org.apache.directory.shared.ldap.schema.parsers.ParserMonitor;
035    import org.apache.directory.shared.ldap.util.StringTools;
036    
037    
038    import antlr.TokenBuffer;
039    import antlr.TokenStreamException;
040    import antlr.TokenStreamIOException;
041    import antlr.ANTLRException;
042    import antlr.LLkParser;
043    import antlr.Token;
044    import antlr.TokenStream;
045    import antlr.RecognitionException;
046    import antlr.NoViableAltException;
047    import antlr.MismatchedTokenException;
048    import antlr.SemanticException;
049    import antlr.ParserSharedInputState;
050    import antlr.collections.impl.BitSet;
051    
052    /**
053     * An antlr generated DN parser.
054     *
055     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
056     * @version $Rev$
057     */
058    public class AntlrDnParser extends antlr.LLkParser       implements AntlrDnTokenTypes
059     {
060    
061        private ParserMonitor monitor = null;
062        public void setParserMonitor( ParserMonitor monitor )
063        {
064            this.monitor = monitor;
065        }
066        private void matchedProduction( String msg )
067        {
068            if ( null != monitor )
069            {
070                monitor.matchedProduction( msg );
071            }
072        }
073        static class UpAndNormValue
074        {
075            Object value = "";
076            String rawValue = "";
077        }
078    
079    protected AntlrDnParser(TokenBuffer tokenBuf, int k) {
080      super(tokenBuf,k);
081      tokenNames = _tokenNames;
082    }
083    
084    public AntlrDnParser(TokenBuffer tokenBuf) {
085      this(tokenBuf,3);
086    }
087    
088    protected AntlrDnParser(TokenStream lexer, int k) {
089      super(lexer,k);
090      tokenNames = _tokenNames;
091    }
092    
093    public AntlrDnParser(TokenStream lexer) {
094      this(lexer,3);
095    }
096    
097    public AntlrDnParser(ParserSharedInputState state) {
098      super(state,3);
099      tokenNames = _tokenNames;
100    }
101    
102    /**
103         * Parses an DN string.
104         *
105         * RFC 4514, Section 3
106         * distinguishedName = [ relativeDistinguishedName
107         *     *( COMMA relativeDistinguishedName ) ]
108         *
109         * RFC 2253, Section 3
110         * distinguishedName = [name] 
111         * name       = name-component *("," name-component)
112         *
113         * RFC 1779, Section 2.3
114         * <name> ::= <name-component> ( <spaced-separator> )
115         *        | <name-component> <spaced-separator> <name>
116         * <spaced-separator> ::= <optional-space>
117         *             <separator>
118         *             <optional-space>
119         * <separator> ::=  "," | ";"
120         * <optional-space> ::= ( <CR> ) *( " " )
121         *
122         */
123            public final void distinguishedName(
124                    DN dn
125            ) throws RecognitionException, TokenStreamException {
126                    
127                    
128                    matchedProduction( "distinguishedName()" );
129                    RDN rdn = null;
130                    
131                    
132                    {
133                    switch ( LA(1)) {
134                    case SPACE:
135                    case NUMERICOID:
136                    case ALPHA:
137                    {
138                            rdn=relativeDistinguishedName(new RDN());
139                            dn.add( rdn ); rdn=null;
140                            {
141                            _loop1922:
142                            do {
143                                    if ((LA(1)==COMMA||LA(1)==SEMI)) {
144                                            {
145                                            switch ( LA(1)) {
146                                            case COMMA:
147                                            {
148                                                    match(COMMA);
149                                                    break;
150                                            }
151                                            case SEMI:
152                                            {
153                                                    match(SEMI);
154                                                    break;
155                                            }
156                                            default:
157                                            {
158                                                    throw new NoViableAltException(LT(1), getFilename());
159                                            }
160                                            }
161                                            }
162                                            rdn=relativeDistinguishedName(new RDN());
163                                            dn.add( rdn ); rdn=null;
164                                    }
165                                    else {
166                                            break _loop1922;
167                                    }
168                                    
169                            } while (true);
170                            }
171                            match(Token.EOF_TYPE);
172                            break;
173                    }
174                    case EOF:
175                    {
176                            break;
177                    }
178                    default:
179                    {
180                            throw new NoViableAltException(LT(1), getFilename());
181                    }
182                    }
183                    }
184            }
185            
186    /**
187         * Parses an RDN string.
188         *
189         * RFC 4514, Section 3
190         * relativeDistinguishedName = attributeTypeAndValue
191         *     *( PLUS attributeTypeAndValue )
192         *
193         * RFC 2253, Section 3
194         * name-component = attributeTypeAndValue *("+" attributeTypeAndValue)
195         *
196         * RFC 1779, Section 2.3
197         * <name-component> ::= <attribute>
198         *     | <attribute> <optional-space> "+"
199         *       <optional-space> <name-component>
200         *
201         */
202            public final RDN  relativeDistinguishedName(
203                    RDN initialRdn
204            ) throws RecognitionException, TokenStreamException {
205                    RDN rdn;
206                    
207                    
208                    matchedProduction( "relativeDistinguishedName()" );
209                    rdn = initialRdn;
210                    String tmp;
211                    String upName = "";
212                    
213                    
214                    {
215                    tmp=attributeTypeAndValue(rdn);
216                    
217                    upName += tmp;
218                    
219                    {
220                    _loop1931:
221                    do {
222                            if ((LA(1)==PLUS)) {
223                                    match(PLUS);
224                                    upName += "+";
225                                    tmp=attributeTypeAndValue(rdn);
226                                    
227                                    upName += tmp;
228                                    
229                            }
230                            else {
231                                    break _loop1931;
232                            }
233                            
234                    } while (true);
235                    }
236                    }
237                    
238                    rdn.normalize();
239                    rdn.setUpName( upName );
240                    
241                    return rdn;
242            }
243            
244    /**
245         * Parses an DN string.
246         *
247         * RFC 4514, Section 3
248         * distinguishedName = [ relativeDistinguishedName
249         *     *( COMMA relativeDistinguishedName ) ]
250         *
251         * RFC 2253, Section 3
252         * distinguishedName = [name] 
253         * name       = name-component *("," name-component)
254         *
255         * RFC 1779, Section 2.3
256         * <name> ::= <name-component> ( <spaced-separator> )
257         *        | <name-component> <spaced-separator> <name>
258         * <spaced-separator> ::= <optional-space>
259         *             <separator>
260         *             <optional-space>
261         * <separator> ::=  "," | ";"
262         * <optional-space> ::= ( <CR> ) *( " " )
263         *
264         */
265            public final void relativeDistinguishedNames(
266                    List<RDN> rdns
267            ) throws RecognitionException, TokenStreamException {
268                    
269                    
270                    matchedProduction( "relativeDistinguishedNames()" );
271                    RDN rdn = null;
272                    
273                    
274                    {
275                    switch ( LA(1)) {
276                    case SPACE:
277                    case NUMERICOID:
278                    case ALPHA:
279                    {
280                            rdn=relativeDistinguishedName(new RDN());
281                            rdns.add( rdn );
282                            {
283                            _loop1927:
284                            do {
285                                    if ((LA(1)==COMMA||LA(1)==SEMI)) {
286                                            {
287                                            switch ( LA(1)) {
288                                            case COMMA:
289                                            {
290                                                    match(COMMA);
291                                                    break;
292                                            }
293                                            case SEMI:
294                                            {
295                                                    match(SEMI);
296                                                    break;
297                                            }
298                                            default:
299                                            {
300                                                    throw new NoViableAltException(LT(1), getFilename());
301                                            }
302                                            }
303                                            }
304                                            rdn=relativeDistinguishedName(new RDN());
305                                            rdns.add( rdn );
306                                    }
307                                    else {
308                                            break _loop1927;
309                                    }
310                                    
311                            } while (true);
312                            }
313                            match(Token.EOF_TYPE);
314                            break;
315                    }
316                    case EOF:
317                    {
318                            break;
319                    }
320                    default:
321                    {
322                            throw new NoViableAltException(LT(1), getFilename());
323                    }
324                    }
325                    }
326            }
327            
328    /**
329         * RFC 4514, Section 3
330         * attributeTypeAndValue = attributeType EQUALS attributeValue
331         *
332         * RFC 2253, Section 3
333         * attributeTypeAndValue = attributeType "=" attributeValue
334         *
335         */
336            public final String  attributeTypeAndValue(
337                    RDN rdn
338            ) throws RecognitionException, TokenStreamException {
339                    String upName = "";
340                    
341                    
342                    matchedProduction( "attributeTypeAndValue()" );
343                    String type = null;
344                    UpAndNormValue value = new UpAndNormValue();
345                    
346                    
347                    {
348                    {
349                    _loop1935:
350                    do {
351                            if ((LA(1)==SPACE)) {
352                                    match(SPACE);
353                                    upName += " ";
354                            }
355                            else {
356                                    break _loop1935;
357                            }
358                            
359                    } while (true);
360                    }
361                    type=attributeType();
362                    upName += type;
363                    {
364                    _loop1937:
365                    do {
366                            if ((LA(1)==SPACE)) {
367                                    match(SPACE);
368                                    upName += " ";
369                            }
370                            else {
371                                    break _loop1937;
372                            }
373                            
374                    } while (true);
375                    }
376                    match(EQUALS);
377                    upName += "=";
378                    {
379                    _loop1939:
380                    do {
381                            if ((LA(1)==SPACE)) {
382                                    match(SPACE);
383                                    upName += " ";
384                            }
385                            else {
386                                    break _loop1939;
387                            }
388                            
389                    } while (true);
390                    }
391                    attributeValue(value);
392                    
393                    try
394                    {
395                    upName += value.rawValue;
396                    AVA ava = null;
397                    
398                    if ( value.value instanceof String )
399                    {
400                    ava = new AVA(
401                    type,
402                    type,
403                    new ClientStringValue( (String)value.value ), 
404                    new ClientStringValue( (String)value.value ),
405                    upName
406                    );
407                    }
408                    else
409                    {
410                    ava = new AVA(
411                    type,
412                    type,
413                    new ClientBinaryValue( (byte[])value.value ), 
414                    new ClientBinaryValue( (byte[])value.value ),
415                    upName
416                    );
417                    }
418                    
419                    rdn.addAttributeTypeAndValue( ava );
420                    }
421                    catch ( InvalidNameException e )
422                    {
423                    throw new SemanticException( e.getMessage() );
424                    } 
425                    
426                    }
427                    return upName;
428            }
429            
430    /**
431         * RFC 4514 Section 3
432         *
433         * attributeType = descr / numericoid
434         *
435         */
436            public final String  attributeType() throws RecognitionException, TokenStreamException {
437                    String attributeType;
438                    
439                    
440                    matchedProduction( "attributeType()" );
441                    
442                    
443                    {
444                    switch ( LA(1)) {
445                    case ALPHA:
446                    {
447                            attributeType=descr();
448                            break;
449                    }
450                    case NUMERICOID:
451                    {
452                            attributeType=numericoid();
453                            break;
454                    }
455                    default:
456                    {
457                            throw new NoViableAltException(LT(1), getFilename());
458                    }
459                    }
460                    }
461                    return attributeType;
462            }
463            
464    /**
465         * RFC 4514, Section 3
466         * attributeValue = string / hexstring
467         *
468         * RFC 2253, Section 3
469         * attributeValue = string
470         * string     = *( stringchar / pair )
471         *              / "#" hexstring
472         *              / QUOTATION *( quotechar / pair ) QUOTATION ; only from v2
473         * 
474         */
475            public final void attributeValue(
476                    UpAndNormValue value
477            ) throws RecognitionException, TokenStreamException {
478                    
479                    
480                    matchedProduction( "attributeValue()" );
481                    
482                    
483                    {
484                    switch ( LA(1)) {
485                    case DQUOTE:
486                    {
487                            {
488                            quotestring(value);
489                            {
490                            _loop1950:
491                            do {
492                                    if ((LA(1)==SPACE)) {
493                                            match(SPACE);
494                                            value.rawValue += " ";
495                                    }
496                                    else {
497                                            break _loop1950;
498                                    }
499                                    
500                            } while (true);
501                            }
502                            }
503                            break;
504                    }
505                    case EQUALS:
506                    case HYPHEN:
507                    case NUMERICOID:
508                    case DIGIT:
509                    case ALPHA:
510                    case HEXPAIR:
511                    case ESC:
512                    case ESCESC:
513                    case ESCSHARP:
514                    case UTFMB:
515                    case LUTF1_REST:
516                    {
517                            string(value);
518                            break;
519                    }
520                    case HEXVALUE:
521                    {
522                            {
523                            hexstring(value);
524                            {
525                            _loop1953:
526                            do {
527                                    if ((LA(1)==SPACE)) {
528                                            match(SPACE);
529                                            value.rawValue += " ";
530                                    }
531                                    else {
532                                            break _loop1953;
533                                    }
534                                    
535                            } while (true);
536                            }
537                            }
538                            break;
539                    }
540                    case EOF:
541                    case COMMA:
542                    case PLUS:
543                    case SEMI:
544                    {
545                            break;
546                    }
547                    default:
548                    {
549                            throw new NoViableAltException(LT(1), getFilename());
550                    }
551                    }
552                    }
553            }
554            
555    /**
556         * RFC 4512 Section 1.4
557         *
558         * descr = keystring
559         * keystring = leadkeychar *keychar
560         * leadkeychar = ALPHA
561         * keychar = ALPHA / DIGIT / HYPHEN
562         *
563         */
564            public final String  descr() throws RecognitionException, TokenStreamException {
565                    String descr;
566                    
567                    Token  leadkeychar = null;
568                    Token  alpha = null;
569                    Token  digit = null;
570                    Token  hyphen = null;
571                    
572                    matchedProduction( "descr()" );
573                    
574                    
575                    leadkeychar = LT(1);
576                    match(ALPHA);
577                    descr = leadkeychar.getText();
578                    {
579                    _loop1944:
580                    do {
581                            switch ( LA(1)) {
582                            case ALPHA:
583                            {
584                                    alpha = LT(1);
585                                    match(ALPHA);
586                                    descr += alpha.getText();
587                                    break;
588                            }
589                            case DIGIT:
590                            {
591                                    digit = LT(1);
592                                    match(DIGIT);
593                                    descr += digit.getText();
594                                    break;
595                            }
596                            case HYPHEN:
597                            {
598                                    hyphen = LT(1);
599                                    match(HYPHEN);
600                                    descr += hyphen.getText();
601                                    break;
602                            }
603                            default:
604                            {
605                                    break _loop1944;
606                            }
607                            }
608                    } while (true);
609                    }
610                    return descr;
611            }
612            
613    /**
614         * RFC 4512 Section 1.4
615         *
616         * numericoid = number 1*( DOT number )
617         * number  = DIGIT / ( LDIGIT 1*DIGIT )
618         * DIGIT   = %x30 / LDIGIT       ; "0"-"9"
619         * LDIGIT  = %x31-39             ; "1"-"9"
620         *
621         */
622            public final String  numericoid() throws RecognitionException, TokenStreamException {
623                    String numericoid = "";
624                    
625                    Token  noid = null;
626                    
627                    matchedProduction( "numericoid()" );
628                    
629                    
630                    noid = LT(1);
631                    match(NUMERICOID);
632                    numericoid += noid.getText();
633                    return numericoid;
634            }
635            
636    /**
637         * RFC 2253, Section 3
638         *              / QUOTATION *( quotechar / pair ) QUOTATION ; only from v2
639         * quotechar     = <any character except "\" or QUOTATION >
640         *
641         */
642            public final void quotestring(
643                    UpAndNormValue value
644            ) throws RecognitionException, TokenStreamException {
645                    
646                    Token  dq1 = null;
647                    Token  s = null;
648                    Token  dq2 = null;
649                    
650                    matchedProduction( "quotestring()" );
651                    org.apache.directory.shared.ldap.util.ByteBuffer bb = new org.apache.directory.shared.ldap.util.ByteBuffer();
652                    byte[] bytes;
653                    
654                    
655                    {
656                    dq1 = LT(1);
657                    match(DQUOTE);
658                    value.rawValue += dq1.getText();
659                    {
660                    _loop1959:
661                    do {
662                            switch ( LA(1)) {
663                            case COMMA:
664                            case EQUALS:
665                            case PLUS:
666                            case HYPHEN:
667                            case SEMI:
668                            case LANGLE:
669                            case RANGLE:
670                            case SPACE:
671                            case NUMERICOID_OR_ALPHA_OR_DIGIT:
672                            case NUMERICOID:
673                            case DOT:
674                            case NUMBER:
675                            case LDIGIT:
676                            case DIGIT:
677                            case ALPHA:
678                            case HEXPAIR_OR_ESCESC_ESCSHARP_OR_ESC:
679                            case HEX:
680                            case HEXVALUE_OR_SHARP:
681                            case HEXVALUE:
682                            case SHARP:
683                            case UTFMB:
684                            case LUTF1_REST:
685                            {
686                                    {
687                                    {
688                                    s = LT(1);
689                                    match(_tokenSet_0);
690                                    }
691                                    
692                                    value.rawValue += s.getText();
693                                    bb.append( StringTools.getBytesUtf8( s.getText() ) ); 
694                                    
695                                    }
696                                    break;
697                            }
698                            case HEXPAIR:
699                            case ESC:
700                            case ESCESC:
701                            case ESCSHARP:
702                            {
703                                    bytes=pair(value);
704                                    bb.append( bytes );
705                                    break;
706                            }
707                            default:
708                            {
709                                    break _loop1959;
710                            }
711                            }
712                    } while (true);
713                    }
714                    dq2 = LT(1);
715                    match(DQUOTE);
716                    value.rawValue += dq2.getText();
717                    }
718                    
719                    String string = StringTools.utf8ToString( bb.copyOfUsedBytes() );
720                    value.value = string;
721                    
722            }
723            
724    /**
725         * RFC 4514 Section 3
726         *
727         * ; The following characters are to be escaped when they appear
728         * ; in the value to be encoded: ESC, one of <escaped>, leading
729         * ; SHARP or SPACE, trailing SPACE, and NULL.
730         * string =   [ ( leadchar / pair ) [ *( stringchar / pair )
731         *    ( trailchar / pair ) ] ]
732         *
733         */
734            public final void string(
735                    UpAndNormValue value
736            ) throws RecognitionException, TokenStreamException {
737                    
738                    
739                    matchedProduction( "string()" );
740                    org.apache.directory.shared.ldap.util.ByteBuffer bb = new org.apache.directory.shared.ldap.util.ByteBuffer();
741                    String tmp;
742                    byte[] bytes;
743                    
744                    
745                    {
746                    {
747                    switch ( LA(1)) {
748                    case EQUALS:
749                    case HYPHEN:
750                    case NUMERICOID:
751                    case DIGIT:
752                    case ALPHA:
753                    case LUTF1_REST:
754                    {
755                            tmp=lutf1();
756                            
757                            value.rawValue += tmp;
758                            bb.append( StringTools.getBytesUtf8( tmp ) ); 
759                            
760                            break;
761                    }
762                    case UTFMB:
763                    {
764                            tmp=utfmb();
765                            
766                            value.rawValue += tmp;
767                            bb.append( StringTools.getBytesUtf8( tmp ) );
768                            
769                            break;
770                    }
771                    case HEXPAIR:
772                    case ESC:
773                    case ESCESC:
774                    case ESCSHARP:
775                    {
776                            bytes=pair(value);
777                            bb.append( bytes );
778                            break;
779                    }
780                    default:
781                    {
782                            throw new NoViableAltException(LT(1), getFilename());
783                    }
784                    }
785                    }
786                    {
787                    _loop1965:
788                    do {
789                            switch ( LA(1)) {
790                            case EQUALS:
791                            case HYPHEN:
792                            case SPACE:
793                            case NUMERICOID:
794                            case DIGIT:
795                            case ALPHA:
796                            case SHARP:
797                            case LUTF1_REST:
798                            {
799                                    tmp=sutf1();
800                                    
801                                    value.rawValue += tmp;
802                                    bb.append( StringTools.getBytesUtf8( tmp ) ); 
803                                    
804                                    break;
805                            }
806                            case UTFMB:
807                            {
808                                    tmp=utfmb();
809                                    
810                                    value.rawValue += tmp;
811                                    bb.append( StringTools.getBytesUtf8( tmp ) ); 
812                                    
813                                    break;
814                            }
815                            case HEXPAIR:
816                            case ESC:
817                            case ESCESC:
818                            case ESCSHARP:
819                            {
820                                    bytes=pair(value);
821                                    bb.append( bytes );
822                                    break;
823                            }
824                            default:
825                            {
826                                    break _loop1965;
827                            }
828                            }
829                    } while (true);
830                    }
831                    }
832                    
833                    String string = StringTools.utf8ToString( bb.copyOfUsedBytes() );
834                    
835                    // trim trailing space characters manually
836                    // don't know how to tell antlr that the last char mustn't be a space.
837                    int rawIndex = value.rawValue.length();
838                    while ( string.length() > 0 && rawIndex > 1 
839                    && value.rawValue.charAt( rawIndex - 1 ) == ' ' 
840                    && value.rawValue.charAt( rawIndex - 2 ) != '\\' )
841                    {
842                    string = string.substring( 0, string.length() - 1 );
843                    rawIndex--;
844                    }
845                    
846                    value.value = string;
847                    
848            }
849            
850    /**
851         * RFC 4514 Section 3
852         *
853         * hexstring = SHARP 1*hexpair
854         *
855         * If in <hexstring> form, a BER representation can be obtained from
856         * converting each <hexpair> of the <hexstring> to the octet indicated
857         * by the <hexpair>.
858         *
859         */
860            public final void hexstring(
861                    UpAndNormValue value
862            ) throws RecognitionException, TokenStreamException {
863                    
864                    Token  hexValue = null;
865                    
866                    matchedProduction( "hexstring()" );
867                    
868                    
869                    hexValue = LT(1);
870                    match(HEXVALUE);
871                    
872                    // convert to byte[]
873                    value.rawValue = "#" + hexValue.getText();
874                    value.value = StringTools.toByteArray( hexValue.getText() ); 
875                    
876            }
877            
878    /**
879         * RFC 4514, Section 3
880         * pair = ESC ( ESC / special / hexpair )
881         * special = escaped / SPACE / SHARP / EQUALS
882         * escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE
883         * hexpair = HEX HEX
884         *
885         * If in <string> form, a LDAP string representation asserted value can
886         * be obtained by replacing (left to right, non-recursively) each <pair>
887         * appearing in the <string> as follows:
888         *   replace <ESC><ESC> with <ESC>;
889         *   replace <ESC><special> with <special>;
890         *   replace <ESC><hexpair> with the octet indicated by the <hexpair>.
891         * 
892         * RFC 2253, Section 3
893         * pair       = "\" ( special / "\" / QUOTATION / hexpair )
894         * special    = "," / "=" / "+" / "<" /  ">" / "#" / ";"
895         * 
896         * RFC 1779, Section 2.3
897         * <pair> ::= "\" ( <special> | "\" | '"')
898         * <special> ::= "," | "=" | <CR> | "+" | "<" |  ">"
899         *           | "#" | ";"
900         * 
901         */
902            public final byte[]  pair(
903                    UpAndNormValue value
904            ) throws RecognitionException, TokenStreamException {
905                    byte[] pair;
906                    
907                    Token  hexpair = null;
908                    
909                    matchedProduction( "pair()" );
910                    String tmp;
911                    
912                    
913                    switch ( LA(1)) {
914                    case ESCESC:
915                    {
916                            {
917                            match(ESCESC);
918                            
919                            value.rawValue += "\\\\";
920                            pair = StringTools.getBytesUtf8( "\\" );
921                            
922                            }
923                            break;
924                    }
925                    case ESCSHARP:
926                    {
927                            {
928                            match(ESCSHARP);
929                            
930                            value.rawValue += "\\#";
931                            pair = StringTools.getBytesUtf8( "#" );
932                            
933                            }
934                            break;
935                    }
936                    case ESC:
937                    {
938                            {
939                            match(ESC);
940                            tmp=special();
941                            
942                            value.rawValue += "\\" + tmp;
943                            pair = StringTools.getBytesUtf8( tmp ); 
944                            
945                            }
946                            break;
947                    }
948                    case HEXPAIR:
949                    {
950                            {
951                            hexpair = LT(1);
952                            match(HEXPAIR);
953                            
954                            value.rawValue += "\\" + hexpair.getText();
955                            pair = StringTools.toByteArray( hexpair.getText() ); 
956                            
957                            }
958                            break;
959                    }
960                    default:
961                    {
962                            throw new NoViableAltException(LT(1), getFilename());
963                    }
964                    }
965                    return pair;
966            }
967            
968    /**
969     * RFC 4514, Section 3:
970     * LUTF1 = %x01-1F / %x21 / %x24-2A / %x2D-3A /
971     *    %x3D / %x3F-5B / %x5D-7F
972     *
973     * The rule LUTF1_REST doesn't contain the following charcters,
974     * so we must check them additionally
975     *   EQUALS (0x3D) 
976     *   HYPHEN (0x2D)  
977     *   DIGIT (0x30-0x39)
978     *   ALPHA (0x41-0x5A and 0x61-0x7A)
979     */
980            public final String  lutf1() throws RecognitionException, TokenStreamException {
981                    String lutf1="";
982                    
983                    Token  rest = null;
984                    Token  equals = null;
985                    Token  hyphen = null;
986                    Token  digit = null;
987                    Token  alpha = null;
988                    Token  numericoid = null;
989                    
990                    matchedProduction( "lutf1()" );
991                    
992                    
993                    switch ( LA(1)) {
994                    case LUTF1_REST:
995                    {
996                            rest = LT(1);
997                            match(LUTF1_REST);
998                            lutf1 = rest.getText();
999                            break;
1000                    }
1001                    case EQUALS:
1002                    {
1003                            equals = LT(1);
1004                            match(EQUALS);
1005                            lutf1 = equals.getText();
1006                            break;
1007                    }
1008                    case HYPHEN:
1009                    {
1010                            hyphen = LT(1);
1011                            match(HYPHEN);
1012                            lutf1 = hyphen.getText();
1013                            break;
1014                    }
1015                    case DIGIT:
1016                    {
1017                            digit = LT(1);
1018                            match(DIGIT);
1019                            lutf1 = digit.getText();
1020                            break;
1021                    }
1022                    case ALPHA:
1023                    {
1024                            alpha = LT(1);
1025                            match(ALPHA);
1026                            lutf1 = alpha.getText();
1027                            break;
1028                    }
1029                    case NUMERICOID:
1030                    {
1031                            numericoid = LT(1);
1032                            match(NUMERICOID);
1033                            lutf1 = numericoid.getText();
1034                            break;
1035                    }
1036                    default:
1037                    {
1038                            throw new NoViableAltException(LT(1), getFilename());
1039                    }
1040                    }
1041                    return lutf1;
1042            }
1043            
1044            public final String  utfmb() throws RecognitionException, TokenStreamException {
1045                    String utfmb;
1046                    
1047                    Token  s = null;
1048                    
1049                    matchedProduction( "utfmb()" );
1050                    
1051                    
1052                    s = LT(1);
1053                    match(UTFMB);
1054                    utfmb = s.getText();
1055                    return utfmb;
1056            }
1057            
1058    /**
1059     * RFC 4514, Section 3:
1060     * SUTF1 = %x01-21 / %x23-2A / %x2D-3A /
1061     *    %x3D / %x3F-5B / %x5D-7F
1062     *
1063     * The rule LUTF1_REST doesn't contain the following charcters,
1064     * so we must check them additionally
1065     *   EQUALS (0x3D) 
1066     *   HYPHEN (0x2D)  
1067     *   DIGIT (0x30-0x39)
1068     *   ALPHA (0x41-0x5A and 0x61-0x7A)
1069     *   SHARP
1070     *   SPACE
1071     */
1072            public final String  sutf1() throws RecognitionException, TokenStreamException {
1073                    String sutf1="";
1074                    
1075                    Token  rest = null;
1076                    Token  equals = null;
1077                    Token  hyphen = null;
1078                    Token  digit = null;
1079                    Token  alpha = null;
1080                    Token  sharp = null;
1081                    Token  space = null;
1082                    Token  numericoid = null;
1083                    
1084                    matchedProduction( "sutf1()" );
1085                    
1086                    
1087                    switch ( LA(1)) {
1088                    case LUTF1_REST:
1089                    {
1090                            rest = LT(1);
1091                            match(LUTF1_REST);
1092                            sutf1 = rest.getText();
1093                            break;
1094                    }
1095                    case EQUALS:
1096                    {
1097                            equals = LT(1);
1098                            match(EQUALS);
1099                            sutf1 = equals.getText();
1100                            break;
1101                    }
1102                    case HYPHEN:
1103                    {
1104                            hyphen = LT(1);
1105                            match(HYPHEN);
1106                            sutf1 = hyphen.getText();
1107                            break;
1108                    }
1109                    case DIGIT:
1110                    {
1111                            digit = LT(1);
1112                            match(DIGIT);
1113                            sutf1 = digit.getText();
1114                            break;
1115                    }
1116                    case ALPHA:
1117                    {
1118                            alpha = LT(1);
1119                            match(ALPHA);
1120                            sutf1 = alpha.getText();
1121                            break;
1122                    }
1123                    case SHARP:
1124                    {
1125                            sharp = LT(1);
1126                            match(SHARP);
1127                            sutf1 = sharp.getText();
1128                            break;
1129                    }
1130                    case SPACE:
1131                    {
1132                            space = LT(1);
1133                            match(SPACE);
1134                            sutf1 = space.getText();
1135                            break;
1136                    }
1137                    case NUMERICOID:
1138                    {
1139                            numericoid = LT(1);
1140                            match(NUMERICOID);
1141                            sutf1 = numericoid.getText();
1142                            break;
1143                    }
1144                    default:
1145                    {
1146                            throw new NoViableAltException(LT(1), getFilename());
1147                    }
1148                    }
1149                    return sutf1;
1150            }
1151            
1152    /**
1153         * RFC 4514 Section 3
1154         * 
1155         * special = escaped / SPACE / SHARP / EQUALS
1156         * escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE
1157         *
1158         */
1159            public final String  special() throws RecognitionException, TokenStreamException {
1160                    String special;
1161                    
1162                    Token  dquote = null;
1163                    Token  plus = null;
1164                    Token  comma = null;
1165                    Token  semi = null;
1166                    Token  langle = null;
1167                    Token  rangle = null;
1168                    Token  space = null;
1169                    Token  sharp = null;
1170                    Token  equals = null;
1171                    
1172                    matchedProduction( "special()" );
1173                    
1174                    
1175                    {
1176                    switch ( LA(1)) {
1177                    case DQUOTE:
1178                    {
1179                            dquote = LT(1);
1180                            match(DQUOTE);
1181                            special = dquote.getText();
1182                            break;
1183                    }
1184                    case PLUS:
1185                    {
1186                            plus = LT(1);
1187                            match(PLUS);
1188                            special = plus.getText();
1189                            break;
1190                    }
1191                    case COMMA:
1192                    {
1193                            comma = LT(1);
1194                            match(COMMA);
1195                            special = comma.getText();
1196                            break;
1197                    }
1198                    case SEMI:
1199                    {
1200                            semi = LT(1);
1201                            match(SEMI);
1202                            special = semi.getText();
1203                            break;
1204                    }
1205                    case LANGLE:
1206                    {
1207                            langle = LT(1);
1208                            match(LANGLE);
1209                            special = langle.getText();
1210                            break;
1211                    }
1212                    case RANGLE:
1213                    {
1214                            rangle = LT(1);
1215                            match(RANGLE);
1216                            special = rangle.getText();
1217                            break;
1218                    }
1219                    case SPACE:
1220                    {
1221                            space = LT(1);
1222                            match(SPACE);
1223                            special = space.getText();
1224                            break;
1225                    }
1226                    case SHARP:
1227                    {
1228                            sharp = LT(1);
1229                            match(SHARP);
1230                            special = sharp.getText();
1231                            break;
1232                    }
1233                    case EQUALS:
1234                    {
1235                            equals = LT(1);
1236                            match(EQUALS);
1237                            special = equals.getText();
1238                            break;
1239                    }
1240                    default:
1241                    {
1242                            throw new NoViableAltException(LT(1), getFilename());
1243                    }
1244                    }
1245                    }
1246                    return special;
1247            }
1248            
1249            
1250            public static final String[] _tokenNames = {
1251                    "<0>",
1252                    "EOF",
1253                    "<2>",
1254                    "NULL_TREE_LOOKAHEAD",
1255                    "COMMA",
1256                    "EQUALS",
1257                    "PLUS",
1258                    "HYPHEN",
1259                    "DQUOTE",
1260                    "SEMI",
1261                    "LANGLE",
1262                    "RANGLE",
1263                    "SPACE",
1264                    "NUMERICOID_OR_ALPHA_OR_DIGIT",
1265                    "NUMERICOID",
1266                    "DOT",
1267                    "NUMBER",
1268                    "LDIGIT",
1269                    "DIGIT",
1270                    "ALPHA",
1271                    "HEXPAIR_OR_ESCESC_ESCSHARP_OR_ESC",
1272                    "HEXPAIR",
1273                    "ESC",
1274                    "ESCESC",
1275                    "ESCSHARP",
1276                    "HEX",
1277                    "HEXVALUE_OR_SHARP",
1278                    "HEXVALUE",
1279                    "SHARP",
1280                    "UTFMB",
1281                    "LUTF1_REST"
1282            };
1283            
1284            private static final long[] mk_tokenSet_0() {
1285                    long[] data = { 2116026096L, 0L, 0L, 0L};
1286                    return data;
1287            }
1288            public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
1289            
1290            }