MCPcopy Create free account
hub / github.com/atas76/openengine / parseStatement

Method parseStatement

src/main/java/org/ttn/parser/ParserUtil.java:189–244  ·  view source on GitHub ↗
(List<String> tokens)

Source from the content-addressed store, hash-verified

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 {

Callers 15

testDribbleActionMethod · 0.95
testHighPassActionMethod · 0.95
testClearanceActionMethod · 0.95
testRunActionMethod · 0.95
testOneTwoPassActionMethod · 0.95
testTurningActionMethod · 0.95
testLowCrossActionMethod · 0.95

Calls 9

checkMissingTokensMethod · 0.95
parseTimeMethod · 0.95
getPitchPositionMethod · 0.95
getActionContextMethod · 0.95
parseActionOutcomeMethod · 0.95
parseActionMethod · 0.95
setRestingOutcomeMethod · 0.95
setActionContextMethod · 0.95
equalsMethod · 0.45

Tested by 15

testDribbleActionMethod · 0.76
testHighPassActionMethod · 0.76
testClearanceActionMethod · 0.76
testRunActionMethod · 0.76
testOneTwoPassActionMethod · 0.76
testTurningActionMethod · 0.76
testLowCrossActionMethod · 0.76