source: contrib/MailArchiver/sources/vendor/mime4j/apache-mime4j-0.7-SNAPSHOT-20110327.010440-17/dom/src/main/javacc/org/apache/james/mime4j/field/mimeversion/MimeVersionParser.jj @ 6785

Revision 6785, 4.6 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
1/****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one   *
3 * or more contributor license agreements.  See the NOTICE file *
4 * distributed with this work for additional information        *
5 * regarding copyright ownership.  The ASF licenses this file   *
6 * to you under the Apache License, Version 2.0 (the            *
7 * "License"); you may not use this file except in compliance   *
8 * with the License.  You may obtain a copy of the License at   *
9 *                                                              *
10 *   http://www.apache.org/licenses/LICENSE-2.0                 *
11 *                                                              *
12 * Unless required by applicable law or agreed to in writing,   *
13 * software distributed under the License is distributed on an  *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15 * KIND, either express or implied.  See the License for the    *
16 * specific language governing permissions and limitations      *
17 * under the License.                                           *
18 ****************************************************************/
19
20options {
21  static=false;
22  JDK_VERSION = "1.5";
23  OUTPUT_DIRECTORY = "../../../../../../../../../target/generated-sources/javacc";
24}
25
26PARSER_BEGIN(MimeVersionParser)
27/****************************************************************
28 * Licensed to the Apache Software Foundation (ASF) under one   *
29 * or more contributor license agreements.  See the NOTICE file *
30 * distributed with this work for additional information        *
31 * regarding copyright ownership.  The ASF licenses this file   *
32 * to you under the Apache License, Version 2.0 (the            *
33 * "License"); you may not use this file except in compliance   *
34 * with the License.  You may obtain a copy of the License at   *
35 *                                                              *
36 *   http://www.apache.org/licenses/LICENSE-2.0                 *
37 *                                                              *
38 * Unless required by applicable law or agreed to in writing,   *
39 * software distributed under the License is distributed on an  *
40 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
41 * KIND, either express or implied.  See the License for the    *
42 * specific language governing permissions and limitations      *
43 * under the License.                                           *
44 ****************************************************************/
45package org.apache.james.mime4j.field.mimeversion.parser;
46
47public class MimeVersionParser {
48        public static final int INITIAL_VERSION_VALUE = -1;
49        private int major=INITIAL_VERSION_VALUE;
50        private int minor=INITIAL_VERSION_VALUE;
51       
52        public int getMinorVersion() {
53                return minor;
54        }
55       
56        public int getMajorVersion() {
57                return major;
58        }
59}
60PARSER_END(MimeVersionParser)
61
62
63void parseLine() :
64{}
65{
66        parse() ["\r"] "\n"
67}
68
69void parseAll() :
70{}
71{
72        parse() <EOF>
73}
74
75void parse() :
76{
77        Token major;
78        Token minor;
79}
80{
81        major=<DIGITS> <DOT> minor=<DIGITS>
82        {
83                try {
84                        this.major = Integer.parseInt(major.image);
85                        this.minor = Integer.parseInt(minor.image);
86                } catch (NumberFormatException e) {
87                        throw new ParseException(e.getMessage());
88                }
89        }
90}
91
92SPECIAL_TOKEN :
93{
94        < WS: ( [" ", "\t", "\r", "\n"] )+ >
95}
96
97TOKEN_MGR_DECLS :
98{
99        // Keeps track of how many levels of comment nesting
100        // we've encountered.  This is only used when the 2nd
101        // level is reached, for example ((this)), not (this).
102        // This is because the outermost level must be treated
103        // specially anyway, because the outermost ")" has a
104        // different token type than inner ")" instances.
105        int commentNest;
106}
107
108
109MORE :
110{
111        // starts a comment
112        "(" : INCOMMENT
113}
114
115<INCOMMENT>
116SKIP :
117{
118        // ends a comment
119        < COMMENT: ")" > : DEFAULT
120        // if this is ever changed to not be a SKIP, need
121        // to make sure matchedToken.token = token.toString()
122        // is called.
123}
124
125<INCOMMENT>
126MORE :
127{
128        < <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
129|       "(" { commentNest = 1; } : NESTED_COMMENT
130|       < <ANY>>
131}
132
133<NESTED_COMMENT>
134MORE :
135{
136        < <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
137|       "(" { ++commentNest; }
138|       ")" { --commentNest; if (commentNest == 0) SwitchTo(INCOMMENT); }
139|       < <ANY>>
140}
141// QUOTED STRINGS
142
143MORE :
144{
145        "\"" { image.deleteCharAt(image.length() - 1); } : INQUOTEDSTRING
146}
147
148<INQUOTEDSTRING>
149MORE :
150{
151        < <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
152|       < (~["\"", "\\"])+ >
153}
154
155<INQUOTEDSTRING>
156TOKEN :
157{
158        < QUOTEDSTRING: "\"" > { matchedToken.image = image.substring(0, image.length() - 1); } : DEFAULT
159}
160
161TOKEN :
162{
163        < DIGITS: ( ["0"-"9"] )+ >
164}
165
166TOKEN :
167{
168        < DOT: "." >
169}
170
171<*>
172TOKEN :
173{
174        < #QUOTEDPAIR: "\\" <ANY> >
175|       < #ANY: ~[] >
176}
Note: See TracBrowser for help on using the repository browser.