Permalink
Browse files

Show which game type caused parse error (eg ladybug, mosquito, pillbug)

  • Loading branch information...
1 parent 3b40b92 commit a6cee50c7f0243dd45e37253dfe931706969bd57 @chellmuth committed Jan 12, 2014
Showing with 18 additions and 2 deletions.
  1. +15 −1 lib/parser.dart
  2. +3 −1 web/hive.dart
View
16 lib/parser.dart
@@ -12,6 +12,7 @@ class ParsedGame {
List<GameEvent> gameEvents = [];
bool valid = true;
+ List<String> errors = [];
}
class SGF {
@@ -34,8 +35,21 @@ class SGF {
var gameTypeExp = new RegExp(r'^SU\[hive(-\w+)\]');
var gameTypeMatch = gameTypeExp.firstMatch(line);
if (gameTypeMatch != null) {
- print("Invalid game: ${line}");
game.valid = false;
+ var gameType = gameTypeMatch.group(1);
+ if (gameType.contains("ultimate")) {
+ game.errors.add("Ultimate");
+ } else {
+ if (gameType.contains("l")) {
+ game.errors.add("Ladybug");
+ }
+ if (gameType.contains("m")) {
+ game.errors.add("Mosquito");
+ }
+ if (gameType.contains("p")) {
+ game.errors.add("Pillbug");
+ }
+ }
}
var playerNameExp = new RegExp(r'P([01])\[id "([^"]+)"\]');
View
4 web/hive.dart
@@ -133,7 +133,9 @@ void handleCanvasClick(MouseEvent event, GameState gamestate) {
void setupSGF(String sgf, GameState gamestate) {
ParsedGame parsedGame = SGF.parseSGF(sgf);
if (!parsedGame.valid) {
- window.alert("Game type not supported");
+ var gameType = parsedGame.errors.join(", ");
+ var plural = parsedGame.errors.length > 1 ? "s" : "";
+ window.alert("Game type${plural} not supported: ${gameType}");
return;
}
bench = new Bench(parsedGame.player1, parsedGame.player2);

0 comments on commit a6cee50

Please sign in to comment.