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 *
10
* http://www.apache.org/licenses/LICENSE-2.0 *
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
****************************************************************/
23
OUTPUT_DIRECTORY = "../../../../../../../../../target/generated-sources/javacc";
26
PARSER_BEGIN(ContentLanguageParser)
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 *
36
* http://www.apache.org/licenses/LICENSE-2.0 *
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
****************************************************************/
45
package org.apache.james.mime4j.field.language.parser;
47
import java.util.ArrayList;
48
import java.util.List;
50
public class ContentLanguageParser {
51
private List<String> languages = new ArrayList<String>();
54
* Parses the input into a list of language tags.
55
* @return list of language tag Strings
57
public List<String> parse() throws ParseException {
60
} catch (TokenMgrError e) {
61
// An issue with the TOKENiser
62
// but it's not polite to throw an Error
63
// when executing on a server
64
throw new ParseException(e);
68
PARSER_END(ContentLanguageParser)
70
private List<String> doParse() :
74
language() ( "," language() )*
81
StringBuffer languageTag = new StringBuffer();
87
languageTag.append(token.image);
91
// This keeps TOKENising simple
94
languageTag.append('-');
95
languageTag.append(token.image);
100
languageTag.append('-');
101
languageTag.append(token.image);
106
result = languageTag.toString();
107
languages.add(result);
117
< WS: ( [" ", "\t", "\r", "\n"] )+ >
122
// Keeps track of how many levels of comment nesting
123
// we've encountered. This is only used when the 2nd
124
// level is reached, for example ((this)), not (this).
125
// This is because the outermost level must be treated
126
// specially anyway, because the outermost ")" has a
127
// different token type than inner ")" instances.
142
< COMMENT: ")" > : DEFAULT
143
// if this is ever changed to not be a SKIP, need
144
// to make sure matchedToken.token = token.toString()
151
< <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
152
| "(" { commentNest = 1; } : NESTED_COMMENT
159
< <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
160
| "(" { ++commentNest; }
161
| ")" { --commentNest; if (commentNest == 0) SwitchTo(INCOMMENT); }
168
"\"" { image.deleteCharAt(image.length() - 1); } : INQUOTEDSTRING
174
< <QUOTEDPAIR>> { image.deleteCharAt(image.length() - 2); }
175
| < (~["\"", "\\"])+ >
181
< QUOTEDSTRING: "\"" > { matchedToken.image = image.substring(0, image.length() - 1); } : DEFAULT
186
< DIGITS: ( ["0"-"9"] )+ >
191
< ALPHA: ( ["a"-"z"] | ["A"-"Z"] )+ >
196
<ALPHANUM : ( ["0"-"9"] | ["a"-"z"] | ["A"-"Z"] )+>
207
< #QUOTEDPAIR: "\\" <ANY> >
b'\\ No newline at end of file'