]>
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.\r | |
21 | *\r | |
22 | * @author Curt Arnold\r | |
23 | */\r | |
24 | public final class LetterState\r | |
25 | extends AbstractParserState {\r | |
26 | /**\r | |
27 | * Next state if a match is found.\r | |
28 | */\r | |
29 | private final AbstractParserState nextState;\r | |
30 | \r | |
31 | /**\r | |
32 | * Next state if not match is found.\r | |
33 | */\r | |
34 | private final AbstractParserState noMatchState;\r | |
35 | \r | |
36 | /**\r | |
37 | * Character to match.\r | |
38 | */\r | |
39 | private final char thisLetter;\r | |
40 | \r | |
41 | /**\r | |
42 | * Constructor.\r | |
43 | *\r | |
44 | * @param parser\r | |
45 | * parser\r | |
46 | * @param matchLetter\r | |
47 | * letter to match\r | |
48 | * @param nextStateArg\r | |
49 | * next state if a match on the letter\r | |
50 | * @param noMatchStateArg\r | |
51 | * state if no match on letter\r | |
52 | */\r | |
53 | public LetterState(final AbstractParser parser,\r | |
54 | final char matchLetter,\r | |
55 | final AbstractParserState nextStateArg,\r | |
56 | final AbstractParserState noMatchStateArg) {\r | |
57 | super(parser);\r | |
58 | this.thisLetter = matchLetter;\r | |
59 | this.nextState = nextStateArg;\r | |
60 | this.noMatchState = noMatchStateArg;\r | |
61 | }\r | |
62 | \r | |
63 | /**\r | |
64 | * Consumes a character and returns the next state for the parser.\r | |
65 | *\r | |
66 | * @param ch\r | |
67 | * next character\r | |
68 | * @return the configured nextState if ch is the expected character or the\r | |
69 | * configure noMatchState otherwise.\r | |
70 | */\r | |
71 | public AbstractParserState consume(final char ch) {\r | |
72 | if (ch == thisLetter) {\r | |
73 | return nextState;\r | |
74 | }\r | |
75 | if (ch == '\n') {\r | |
76 | getParser().getNewLineState();\r | |
77 | }\r | |
78 | return noMatchState;\r | |
79 | }\r | |
80 | }\r |