| 187 | } |
| 188 | |
| 189 | public static Statement parseStatement(List<String> tokens) throws ParserException { |
| 190 | checkMissingTokens(tokens.size(), 2, "time"); |
| 191 | int time = parseTime(tokens.subList(0, 3)); |
| 192 | checkMissingTokens(tokens.size(), 3, "pitch position"); |
| 193 | PitchPosition pitchPosition = getPitchPosition(tokens.get(3)); |
| 194 | int currentIndex = 4; |
| 195 | ActionContext actionContext = null; |
| 196 | checkMissingTokens(tokens.size(), 4, "action definition"); |
| 197 | if (":".equals(tokens.get(4))) { |
| 198 | checkMissingTokens(tokens.size(), 5, "action context"); |
| 199 | actionContext = getActionContext(tokens.get(5)); |
| 200 | currentIndex = 6; |
| 201 | } |
| 202 | final String actionDelimiter = tokens.get(currentIndex++); |
| 203 | int outcomeDelimiterIndex; |
| 204 | MatchDataElement.StatementType statementType; |
| 205 | if (tokens.contains(">>>")) { |
| 206 | statementType = INDIRECT_OUTCOME; |
| 207 | outcomeDelimiterIndex = tokens.indexOf("=>"); |
| 208 | } else if (tokens.contains("=>")) { |
| 209 | statementType = STANDARD; |
| 210 | outcomeDelimiterIndex = tokens.indexOf("=>"); |
| 211 | } else if (tokens.contains("->")) { |
| 212 | statementType = TRIVIAL_POSSESSION_CHAIN; |
| 213 | outcomeDelimiterIndex = tokens.indexOf("->"); |
| 214 | } else { |
| 215 | throw new ParserException("Outcome delimiter expected"); |
| 216 | } |
| 217 | ActionOutcome actionOutcome; |
| 218 | Statement statement; |
| 219 | int actionOutcomeBound = tokens.size(); |
| 220 | if (tokens.contains(">>")) { |
| 221 | actionOutcomeBound = tokens.indexOf(">>"); |
| 222 | } |
| 223 | else if (tokens.contains(">>>")) { |
| 224 | actionOutcomeBound = tokens.indexOf(">>>"); |
| 225 | } |
| 226 | if ("=>".equals(actionDelimiter)) { |
| 227 | actionOutcome = parseActionOutcome(tokens.subList(currentIndex, actionOutcomeBound)); |
| 228 | statement = new Statement(time, pitchPosition, actionOutcome); |
| 229 | } else if ("->".equals(actionDelimiter)) { |
| 230 | Action action = TRIVIAL_POSSESSION_CHAIN.equals(statementType) ? |
| 231 | new Action(Implicit) : |
| 232 | parseAction(tokens.subList(currentIndex, outcomeDelimiterIndex)); |
| 233 | actionOutcome = parseActionOutcome(tokens.subList(outcomeDelimiterIndex + 1, actionOutcomeBound)); |
| 234 | statement = new Statement(time, pitchPosition, action, actionOutcome, statementType); |
| 235 | } else { |
| 236 | throw new ParserException("Action delimiter expected"); |
| 237 | } |
| 238 | if (actionOutcomeBound < tokens.size()) { |
| 239 | statement.setRestingOutcome(parseActionOutcome(tokens.subList(actionOutcomeBound + 1, tokens.size()))); |
| 240 | } |
| 241 | statement.setActionContext(actionContext); |
| 242 | |
| 243 | return statement; |
| 244 | } |
| 245 | |
| 246 | public static Directive parseDirective(List<String> tokens) throws ParserException { |