I've written an algebraic notation to use for moves in a game and I'm currently writing code to parse the information from the notation. I'm doing this using regExes. This is coded in HaXe.
For example, two functions in the parser would look like this:
public function getMoveType(gameText:String):String
{
var moveTypeRegEx:EReg = ~/MatchThis/;
moveTypeRegEx.match(gameText);
var moveType:String = moveTypeRegEx.matched(0); //this returns entire string that was matched.
return moveType;
}
public function getPlayerName(gameText:String):String
{
var playerNameRegEx:EReg = ~/MatchThis/;
playerNameRegEx.match(gameText);
var playerName:String = playerNameRegEx.matched(0);
return playerName;
}
- How could this be written better to make it more readable or more organized?
- Would it be better to have a class file GameRegExes, which contains all the regexes I need with getter functions to those regexes?
Please let me know if I'm being too vague.