package com.github.nstdio.libpgn.core.parser;

import com.github.nstdio.libpgn.core.Configuration;
import com.github.nstdio.libpgn.core.exception.PgnException;
import com.github.nstdio.libpgn.entity.Result;

import javax.annotation.Nullable;

import static com.github.nstdio.libpgn.core.TokenTypes.GAMETERM;

class ResultParser extends AbstractParser implements Parser<Result> {

    ResultParser(PgnLexer lexer, Configuration config) {
        super(lexer, config);
    }

    @Override
    public Result parse() {
        lastNotEqThrow(GAMETERM);
        String result = read();

        for (Result res : Result.values()) {
            if (result.equals(res.getTerm())) {
                return res;
            }
        }

        throw new PgnException("Bad game termination.");
    }

    @Nullable
    @Override
    public Result tryParse() {
        return null;
    }
}

@@ -40,16 +40,117 @@
 arser;%0A%0A
+import static com.github.nstdio.libpgn.core.TokenTypes.GAMETERM;%0A%0Aimport javax.annotation.Nullable;%0A%0A
 import c
@@ -306,109 +306,8 @@
 t;%0A%0A
-import javax.annotation.Nullable;%0A%0Aimport static com.github.nstdio.libpgn.core.TokenTypes.GAMETERM;%0A%0A
 clas
@@ -543,24 +543,25 @@
 ETERM);%0A
+%0A
         
 String r
@@ -556,28 +556,90 @@
     
-String
+// TODO: Skip reading and use token length.%0A        byte%5B%5D
  result
+Bytes
  = read
+Bytes
 ();%0A
@@ -651,119 +651,246 @@
     
-for (R
+switch (r
 esult
- res : Result.values()) %7B%0A            if (result.equals(res.getTerm())) %7B%0A                return res
+Bytes.length) %7B%0A            case 1:%0A                return Result.UNKNOWN;%0A            case 7:%0A                return Result.DRAW;%0A            case 3:%0A                return resultBytes%5B0%5D == 49 ? Result.WHITE : Result.BLACK
 ;%0A  
@@ -899,17 +899,24 @@
         
-%7D
+default:
 %0A       
@@ -912,27 +912,24 @@
 lt:%0A        
-%7D%0A%0A
         thro
@@ -972,12 +972,49 @@
 tion
-.%22);
+: %22 + new String(resultBytes));%0A        %7D
 %0A   

Replace String reading with byte array in ResultParser.