tokensToText method
Converts tokens to text.
Implementation
@override
String tokensToText(List<String> tokens) {
String tokenized = tokens.join(' '); // Joining tokens into a single string
// Replacing position tokens with 'x' separator
tokenized = tokenized.replaceAllMapped(RegExp(r'p(\d*) p(\d*)'),
(match) => '${match.group(1)}x${match.group(2)}');
// Replacing column and row tokens with simplified format
tokenized = tokenized.replaceAllMapped(RegExp(r'c(\d)\d? r(.)'),
(match) => '${match.group(1)}${match.group(2)}');
// Replacing single-digit columns with two-digit format
tokenized = tokenized.replaceAllMapped(
RegExp(r'c(\d)\d?'), (match) => '${match.group(1)} 0');
// Replacing single-digit rows with two-digit format
tokenized = tokenized.replaceAllMapped(
RegExp(r'r(.)'), (match) => '0${match.group(1)}');
// Removing spaces between digits and box symbols
tokenized = tokenized.replaceAll(' ', '');
tokenized = tokenized.replaceAllMapped(
RegExp(r'(\d)([MBLR])'),
(match) =>
'${match.group(1)} ${match.group(2)}'); // Adding space between digit and box symbol
return tokenized; // Returning the detokenized FSW string
}