]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*\r |
2 | *\r | |
3 | * Copyright 2002-2004 The Ant-Contrib project\r | |
4 | *\r | |
5 | * Licensed under the Apache License, Version 2.0 (the "License");\r | |
6 | * you may not use this file except in compliance with the License.\r | |
7 | * You may obtain a copy of the License at\r | |
8 | *\r | |
9 | * http://www.apache.org/licenses/LICENSE-2.0\r | |
10 | *\r | |
11 | * Unless required by applicable law or agreed to in writing, software\r | |
12 | * distributed under the License is distributed on an "AS IS" BASIS,\r | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r | |
14 | * See the License for the specific language governing permissions and\r | |
15 | * limitations under the License.\r | |
16 | */\r | |
17 | package net.sf.antcontrib.cpptasks.parser;\r | |
18 | \r | |
19 | /**\r | |
20 | * This parser state checks consumed characters against a specific character or\r | |
21 | * whitespace.\r | |
22 | *\r | |
23 | * @author Curt Arnold\r | |
24 | */\r | |
25 | public final class WhitespaceOrLetterState\r | |
26 | extends AbstractParserState {\r | |
27 | /**\r | |
28 | * Next state if the character is found.\r | |
29 | */\r | |
30 | private final AbstractParserState nextState;\r | |
31 | \r | |
32 | /**\r | |
33 | * Character to match.\r | |
34 | */\r | |
35 | private final char thisLetter;\r | |
36 | \r | |
37 | /**\r | |
38 | * Constructor.\r | |
39 | *\r | |
40 | * @param parser\r | |
41 | * parser\r | |
42 | * @param matchLetter\r | |
43 | * letter to match\r | |
44 | * @param nextStateArg\r | |
45 | * next state if a match on the letter\r | |
46 | */\r | |
47 | public WhitespaceOrLetterState(final AbstractParser parser,\r | |
48 | final char matchLetter,\r | |
49 | final AbstractParserState nextStateArg) {\r | |
50 | super(parser);\r | |
51 | this.thisLetter = matchLetter;\r | |
52 | this.nextState = nextStateArg;\r | |
53 | }\r | |
54 | \r | |
55 | /**\r | |
56 | * Consumes a character and returns the next state for the parser.\r | |
57 | *\r | |
58 | * @param ch\r | |
59 | * next character @returns the configured nextState if ch is the\r | |
60 | * expected character or the configure noMatchState otherwise.\r | |
61 | * @return next state\r | |
62 | */\r | |
63 | public AbstractParserState consume(final char ch) {\r | |
64 | if (ch == thisLetter) {\r | |
65 | return nextState;\r | |
66 | }\r | |
67 | if (ch == ' ' || ch == '\t') {\r | |
68 | return this;\r | |
69 | }\r | |
70 | if (ch == '\n') {\r | |
71 | getParser().getNewLineState();\r | |
72 | }\r | |
73 | return null;\r | |
74 | }\r | |
75 | }\r |