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