"use strict" ; function peg$subclass ( child , parent ) { function ctor ( ) { this . constructor = child ; } ctor . prototype = parent . prototype ; child . prototype = new ctor ( ) ; } function peg$SyntaxError ( message , expected , found , location ) { this . message = message ; this . expected = expected ; this . found = found ; this . location = location ; this . name = "SyntaxError" ; if ( typeof Error . captureStackTrace === "function" ) { Error . captureStackTrace ( this , peg$SyntaxError ) ; } } peg$subclass ( peg$SyntaxError , Error ) ; peg$SyntaxError . buildMessage = function ( expected , found ) { var DESCRIBE_EXPECTATION_FNS = { literal : function ( expectation ) { return "\"" + literalEscape ( expectation . text ) + "\"" ; } , "class" : function ( expectation ) { var escapedParts = "" , i ; for ( i = 0 ; i < expectation . parts . length ; i ++ ) { escapedParts += expectation . parts [ i ] instanceof Array ? classEscape ( expectation . parts [ i ] [ 0 ] ) + "-" + classEscape ( expectation . parts [ i ] [ 1 ] ) : classEscape ( expectation . parts [ i ] ) ; } return "[" + ( expectation . inverted ? "^" : "" ) + escapedParts + "]" ; } , any : function ( expectation ) { return "any character" ; } , end : function ( expectation ) { return "end of input" ; } , other : function ( expectation ) { return expectation . description ; } } ; function hex ( ch ) { return ch . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) ; } function literalEscape ( s ) { return s . replace ( /\\/g , '\\\\' ) . replace ( /"/g , '\\"' ) . replace ( /\0/g , '\\0' ) . replace ( /\t/g , '\\t' ) . replace ( /\n/g , '\\n' ) . replace ( /\r/g , '\\r' ) . replace ( /[\x00-\x0F]/g , function ( ch ) { return '\\x0' + hex ( ch ) ; } ) . replace ( /[\x10-\x1F\x7F-\x9F]/g , function ( ch ) { return '\\x' + hex ( ch ) ; } ) ; } function classEscape ( s ) { return s . replace ( /\\/g , '\\\\' ) . replace ( /\]/g , '\\]' ) . replace ( /\^/g , '\\^' ) . replace ( /-/g , '\\-' ) . replace ( /\0/g , '\\0' ) . replace ( /\t/g , '\\t' ) . replace ( /\n/g , '\\n' ) . replace ( /\r/g , '\\r' ) . replace ( /[\x00-\x0F]/g , function ( ch ) { return '\\x0' + hex ( ch ) ; } ) . replace ( /[\x10-\x1F\x7F-\x9F]/g , function ( ch ) { return '\\x' + hex ( ch ) ; } ) ; } function describeExpectation ( expectation ) { return DESCRIBE_EXPECTATION_FNS [ expectation . type ] ( expectation ) ; } function describeExpected ( expected ) { var descriptions = new Array ( expected . length ) , i , j ; for ( i = 0 ; i < expected . length ; i ++ ) { descriptions [ i ] = describeExpectation ( expected [ i ] ) ; } descriptions . sort ( ) ; if ( descriptions . length > 0 ) { for ( i = 1 , j = 1 ; i < descriptions . length ; i ++ ) { if ( descriptions [ i - 1 ] !== descriptions [ i ] ) { descriptions [ j ] = descriptions [ i ] ; j ++ ; } } descriptions . length = j ; } switch ( descriptions . length ) { case 1 : return descriptions [ 0 ] ; case 2 : return descriptions [ 0 ] + " or " + descriptions [ 1 ] ; default : return descriptions . slice ( 0 , - 1 ) . join ( ", " ) + ", or " + descriptions [ descriptions . length - 1 ] ; } } function describeFound ( found ) { return found ? "\"" + literalEscape ( found ) + "\"" : "end of input" ; } return "Expected " + describeExpected ( expected ) + " but " + describeFound ( found ) + " found." ; } ; function peg$parse ( input , options ) { options = options !== void 0 ? options : { } ; var peg$FAILED = { } , peg$startRuleFunctions = { start : peg$parsestart } , peg$startRuleFunction = peg$parsestart , peg$c0 = function ( gs ) { return gs . map ( function ( g ) { return g [ 0 ] ; } ) ; } , peg$c1 = function ( h , c , r ) { return [ null , r ] ; } , peg$c2 = function ( h , c , m , r ) { return [ m , r ] ; } , peg$c3 = function ( h , c , m ) { return [ m , null ] ; } , peg$c4 = function ( h , c , mr ) { return make_game ( h , c , mr [ 0 ] , mr [ 1 ] ) ; } , peg$c5 = peg$anyExpectation ( ) , peg$c6 = "\"" , peg$c7 = peg$literalExpectation ( "\"" , false ) , peg$c8 = /^[^"]/ , peg$c9 = peg$classExpectation ( [ "\"" ] , true , false ) , peg$c10 = function ( str ) { return str . join ( '' ) ; } , peg$c11 = /^[1-9]/ , peg$c12 = peg$classExpectation ( [ [ "1" , "9" ] ] , false , false ) , peg$c13 = /^[0-9]/ , peg$c14 = peg$classExpectation ( [ [ "0" , "9" ] ] , false , false ) , peg$c15 = function ( a , b ) { return parseInt ( a + b . join ( '' ) , 10 ) ; } , peg$c16 = /^[A-Za-z0-9_\-]/ , peg$c17 = peg$classExpectation ( [ [ "A" , "Z" ] , [ "a" , "z" ] , [ "0" , "9" ] , "_" , "-" ] , false , false ) , peg$c18 = function ( chars ) { return chars . join ( '' ) ; } , peg$c19 = " " , peg$c20 = peg$literalExpectation ( " " , false ) , peg$c21 = "\f" , peg$c22 = peg$literalExpectation ( "\f" , false ) , peg$c23 = "\t" , peg$c24 = peg$literalExpectation ( "\t" , false ) , peg$c25 = "\n" , peg$c26 = peg$literalExpectation ( "\n" , false ) , peg$c27 = "[" , peg$c28 = peg$literalExpectation ( "[" , false ) , peg$c29 = "]" , peg$c30 = peg$literalExpectation ( "]" , false ) , peg$c31 = function ( hn , hv ) { return make_header ( hn , hv ) ; } , peg$c32 = function ( hs ) { return hs ; } , peg$c33 = /^[NKQRB]/ , peg$c34 = peg$classExpectation ( [ "N" , "K" , "Q" , "R" , "B" ] , false , false ) , peg$c35 = /^[a-h]/ , peg$c36 = peg$classExpectation ( [ [ "a" , "h" ] ] , false , false ) , peg$c37 = /^[1-8]/ , peg$c38 = peg$classExpectation ( [ [ "1" , "8" ] ] , false , false ) , peg$c39 = "+" , peg$c40 = peg$literalExpectation ( "+" , false ) , peg$c41 = "#" , peg$c42 = peg$literalExpectation ( "#" , false ) , peg$c43 = "x" , peg$c44 = peg$literalExpectation ( "x" , false ) , peg$c45 = "." , peg$c46 = peg$literalExpectation ( "." , false ) , peg$c47 = "1-0" , peg$c48 = peg$literalExpectation ( "1-0" , false ) , peg$c49 = "0-1" , peg$c50 = peg$literalExpectation ( "0-1" , false ) , peg$c51 = "*" , peg$c52 = peg$literalExpectation ( "*" , false ) , peg$c53 = "1/2-1/2" , peg$c54 = peg$literalExpectation ( "1/2-1/2" , false ) , peg$c55 = function ( mn ) { return mn ; } , peg$c56 = function ( r , f ) { return r + f ; } , peg$c57 = "=" , peg$c58 = peg$literalExpectation ( "=" , false ) , peg$c59 = /^[QRBN]/ , peg$c60 = peg$classExpectation ( [ "Q" , "R" , "B" , "N" ] , false , false ) , peg$c61 = "$" , peg$c62 = peg$literalExpectation ( "$" , false ) , peg$c63 = "!!" , peg$c64 = peg$literalExpectation ( "!!" , false ) , peg$c65 = "??" , peg$c66 = peg$literalExpectation ( "??" , false ) , peg$c67 = "!?" , peg$c68 = peg$literalExpectation ( "!?" , false ) , peg$c69 = "?!" , peg$c70 = peg$literalExpectation ( "?!" , false ) , peg$c71 = "!" , peg$c72 = peg$literalExpectation ( "!" , false ) , peg$c73 = "?" , peg$c74 = peg$literalExpectation ( "?" , false ) , peg$c75 = /^[^{}]/ , peg$c76 = peg$classExpectation ( [ "{" , "}" ] , true , false ) , peg$c77 = "{" , peg$c78 = peg$literalExpectation ( "{" , false ) , peg$c79 = "}" , peg$c80 = peg$literalExpectation ( "}" , false ) , peg$c81 = function ( cc ) { return cc . join ( '' ) ; } , peg$c82 = "O-O-O" , peg$c83 = peg$literalExpectation ( "O-O-O" , false ) , peg$c84 = "O-O" , peg$c85 = peg$literalExpectation ( "O-O" , false ) , peg$c86 = function ( m ) { return flatten ( m ) . join ( '' ) ; } , peg$c87 = function ( mn , m , n ) { return n ; } , peg$c88 = function ( mn , m , nags , c2 ) { return c2 ; } , peg$c89 = function ( mn , m , nags , com , r ) { return r ; } , peg$c90 = function ( mn , m , nags , com , ravs ) { return make_move ( mn , m , nags , ravs , com ) ; } , peg$c91 = function ( first , rest ) { return first ? [ first ] . concat ( rest . map ( function ( m ) { return m [ 1 ] ; } ) ) : [ ] ; } , peg$c92 = "(" , peg$c93 = peg$literalExpectation ( "(" , false ) , peg$c94 = ")" , peg$c95 = peg$literalExpectation ( ")" , false ) , peg$c96 = function ( m , r ) { return make_rav ( m , r ) ; } , peg$currPos = 0 , peg$savedPos = 0 , peg$posDetailsCache = [ { line : 1 , column : 1 } ] , peg$maxFailPos = 0 , peg$maxFailExpected = [ ] , peg$silentFails = 0 , peg$result ; if ( "startRule" in options ) { if ( ! ( options . startRule in peg$startRuleFunctions ) ) { throw new Error ( "Can't start parsing from rule \"" + options . startRule + "\"." ) ; } peg$startRuleFunction = peg$startRuleFunctions [ options . startRule ] ; } function text ( ) { return input . substring ( peg$savedPos , peg$currPos ) ; } function location ( ) { return peg$computeLocation ( peg$savedPos , peg$currPos ) ; } function expected ( description , location ) { location = location !== void 0 ? location : peg$computeLocation ( peg$savedPos , peg$currPos ) ; throw peg$buildStructuredError ( [ peg$otherExpectation ( description ) ] , input . substring ( peg$savedPos , peg$currPos ) , location ) ; } function error ( message , location ) { location = location !== void 0 ? location : peg$computeLocation ( peg$savedPos , peg$currPos ) ; throw peg$buildSimpleError ( message , location ) ; } function peg$literalExpectation ( text , ignoreCase ) { return { type : "literal" , text : text , ignoreCase : ignoreCase } ; } function peg$classExpectation ( parts , inverted , ignoreCase ) { return { type : "class" , parts : parts , inverted : inverted , ignoreCase : ignoreCase } ; } function peg$anyExpectation ( ) { return { type : "any" } ; } function peg$endExpectation ( ) { return { type : "end" } ; } function peg$otherExpectation ( description ) { return { type : "other" , description : description } ; } function peg$computePosDetails ( pos ) { var details = peg$posDetailsCache [ pos ] , p ; if ( details ) { return details ; } else { p = pos - 1 ; while ( ! peg$posDetailsCache [ p ] ) { p -- ; } details = peg$posDetailsCache [ p ] ; details = { line : details . line , column : details . column } ; while ( p < pos ) { if ( input . charCodeAt ( p ) === 10 ) { details . line ++ ; details . column = 1 ; } else { details . column ++ ; } p ++ ; } peg$posDetailsCache [ pos ] = details ; return details ; } } function peg$computeLocation ( startPos , endPos ) { var startPosDetails = peg$computePosDetails ( startPos ) , endPosDetails = peg$computePosDetails ( endPos ) ; return { start : { offset : startPos , line : startPosDetails . line , column : startPosDetails . column } , end : { offset : endPos , line : endPosDetails . line , column : endPosDetails . column } } ; } function peg$fail ( expected ) { if ( peg$currPos < peg$maxFailPos ) { return ; } if ( peg$currPos > peg$maxFailPos ) { peg$maxFailPos = peg$currPos ; peg$maxFailExpected = [ ] ; } peg$maxFailExpected . push ( expected ) ; } function peg$buildSimpleError ( message , location ) { return new peg$SyntaxError ( message , null , null , location ) ; } function peg$buildStructuredError ( expected , found , location ) { return new peg$SyntaxError ( peg$SyntaxError . buildMessage ( expected , found ) , expected , found , location ) ; } function peg$parsestart ( ) { var s0 , s1 , s2 , s3 , s4 , s5 ; s0 = peg$currPos ; s1 = [ ] ; s2 = peg$currPos ; s3 = peg$parsegame ( ) ; if ( s3 !== peg$FAILED ) { s4 = [ ] ; s5 = peg$parsenewline ( ) ; while ( s5 !== peg$FAILED ) { s4 . push ( s5 ) ; s5 = peg$parsenewline ( ) ; } if ( s4 !== peg$FAILED ) { s3 = [ s3 , s4 ] ; s2 = s3 ; } else { peg$currPos = s2 ; s2 = peg$FAILED ; } } else { peg$currPos = s2 ; s2 = peg$FAILED ; } while ( s2 !== peg$FAILED ) { s1 . push ( s2 ) ; s2 = peg$currPos ; s3 = peg$parsegame ( ) ; if ( s3 !== peg$FAILED ) { s4 = [ ] ; s5 = peg$parsenewline ( ) ; while ( s5 !== peg$FAILED ) { s4 . push ( s5 ) ; s5 = peg$parsenewline ( ) ; } if ( s4 !== peg$FAILED ) { s3 = [ s3 , s4 ] ; s2 = s3 ; } else { peg$currPos = s2 ; s2 = peg$FAILED ; } } else { peg$currPos = s2 ; s2 = peg$FAILED ; } } if ( s1 !== peg$FAILED ) { s2 = peg$parseEOF ( ) ; if ( s2 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c0 ( s1 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsegame ( ) { var s0 , s1 , s2 , s3 , s4 , s5 , s6 , s7 ; s0 = peg$currPos ; s1 = peg$parseheaders ( ) ; if ( s1 === peg$FAILED ) { s1 = null ; } if ( s1 !== peg$FAILED ) { s2 = [ ] ; s3 = peg$currPos ; s4 = [ ] ; s5 = peg$parsewhitespace ( ) ; while ( s5 !== peg$FAILED ) { s4 . push ( s5 ) ; s5 = peg$parsewhitespace ( ) ; } if ( s4 !== peg$FAILED ) { s5 = peg$parsecomment ( ) ; if ( s5 !== peg$FAILED ) { s4 = [ s4 , s5 ] ; s3 = s4 ; } else { peg$currPos = s3 ; s3 = peg$FAILED ; } } else { peg$currPos = s3 ; s3 = peg$FAILED ; } while ( s3 !== peg$FAILED ) { s2 . push ( s3 ) ; s3 = peg$currPos ; s4 = [ ] ; s5 = peg$parsewhitespace ( ) ; while ( s5 !== peg$FAILED ) { s4 . push ( s5 ) ; s5 = peg$parsewhitespace ( ) ; } if ( s4 !== peg$FAILED ) { s5 = peg$parsecomment ( ) ; if ( s5 !== peg$FAILED ) { s4 = [ s4 , s5 ] ; s3 = s4 ; } else { peg$currPos = s3 ; s3 = peg$FAILED ; } } else { peg$currPos = s3 ; s3 = peg$FAILED ; } } if ( s2 !== peg$FAILED ) { s3 = [ ] ; s4 = peg$parsewhitespace ( ) ; while ( s4 !== peg$FAILED ) { s3 . push ( s4 ) ; s4 = peg$parsewhitespace ( ) ; } if ( s3 !== peg$FAILED ) { s4 = peg$currPos ; s5 = peg$parseresult ( ) ; if ( s5 !== peg$FAILED ) { peg$savedPos = s4 ; s5 = peg$c1 ( s1 , s2 , s5 ) ; } s4 = s5 ; if ( s4 === peg$FAILED ) { s4 = peg$currPos ; s5 = peg$parsemovetext ( ) ; if ( s5 !== peg$FAILED ) { s6 = [ ] ; s7 = peg$parsewhitespace ( ) ; if ( s7 !== peg$FAILED ) { while ( s7 !== peg$FAILED ) { s6 . push ( s7 ) ; s7 = peg$parsewhitespace ( ) ; } } else { s6 = peg$FAILED ; } if ( s6 !== peg$FAILED ) { s7 = peg$parseresult ( ) ; if ( s7 !== peg$FAILED ) { peg$savedPos = s4 ; s5 = peg$c2 ( s1 , s2 , s5 , s7 ) ; s4 = s5 ; } else { peg$currPos = s4 ; s4 = peg$FAILED ; } } else { peg$currPos = s4 ; s4 = peg$FAILED ; } } else { peg$currPos = s4 ; s4 = peg$FAILED ; } if ( s4 === peg$FAILED ) { s4 = peg$currPos ; s5 = peg$parsemovetext ( ) ; if ( s5 !== peg$FAILED ) { peg$savedPos = s4 ; s5 = peg$c3 ( s1 , s2 , s5 ) ; } s4 = s5 ; } } if ( s4 !== peg$FAILED ) { s5 = [ ] ; s6 = peg$parsewhitespace ( ) ; while ( s6 !== peg$FAILED ) { s5 . push ( s6 ) ; s6 = peg$parsewhitespace ( ) ; } if ( s5 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c4 ( s1 , s2 , s4 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parseEOF ( ) { var s0 , s1 ; s0 = peg$currPos ; peg$silentFails ++ ; if ( input . length > peg$currPos ) { s1 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s1 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c5 ) ; } } peg$silentFails -- ; if ( s1 === peg$FAILED ) { s0 = void 0 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsedouble_quote ( ) { var s0 ; if ( input . charCodeAt ( peg$currPos ) === 34 ) { s0 = peg$c6 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c7 ) ; } } return s0 ; } function peg$parsestring ( ) { var s0 , s1 , s2 , s3 ; s0 = peg$currPos ; s1 = peg$parsedouble_quote ( ) ; if ( s1 !== peg$FAILED ) { s2 = [ ] ; if ( peg$c8 . test ( input . charAt ( peg$currPos ) ) ) { s3 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s3 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c9 ) ; } } while ( s3 !== peg$FAILED ) { s2 . push ( s3 ) ; if ( peg$c8 . test ( input . charAt ( peg$currPos ) ) ) { s3 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s3 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c9 ) ; } } } if ( s2 !== peg$FAILED ) { s3 = peg$parsedouble_quote ( ) ; if ( s3 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c10 ( s2 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parseinteger ( ) { var s0 , s1 , s2 , s3 ; s0 = peg$currPos ; if ( peg$c11 . test ( input . charAt ( peg$currPos ) ) ) { s1 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s1 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c12 ) ; } } if ( s1 !== peg$FAILED ) { s2 = [ ] ; if ( peg$c13 . test ( input . charAt ( peg$currPos ) ) ) { s3 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s3 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c14 ) ; } } while ( s3 !== peg$FAILED ) { s2 . push ( s3 ) ; if ( peg$c13 . test ( input . charAt ( peg$currPos ) ) ) { s3 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s3 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c14 ) ; } } } if ( s2 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c15 ( s1 , s2 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsesymbol ( ) { var s0 , s1 , s2 ; s0 = peg$currPos ; s1 = [ ] ; if ( peg$c16 . test ( input . charAt ( peg$currPos ) ) ) { s2 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s2 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c17 ) ; } } if ( s2 !== peg$FAILED ) { while ( s2 !== peg$FAILED ) { s1 . push ( s2 ) ; if ( peg$c16 . test ( input . charAt ( peg$currPos ) ) ) { s2 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s2 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c17 ) ; } } } } else { s1 = peg$FAILED ; } if ( s1 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c18 ( s1 ) ; } s0 = s1 ; return s0 ; } function peg$parsews ( ) { var s0 ; if ( input . charCodeAt ( peg$currPos ) === 32 ) { s0 = peg$c19 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c20 ) ; } } if ( s0 === peg$FAILED ) { if ( input . charCodeAt ( peg$currPos ) === 12 ) { s0 = peg$c21 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c22 ) ; } } if ( s0 === peg$FAILED ) { if ( input . charCodeAt ( peg$currPos ) === 9 ) { s0 = peg$c23 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c24 ) ; } } } } return s0 ; } function peg$parsewhitespace ( ) { var s0 ; s0 = peg$parsews ( ) ; if ( s0 === peg$FAILED ) { s0 = peg$parsenewline ( ) ; } return s0 ; } function peg$parsenewline ( ) { var s0 ; if ( input . charCodeAt ( peg$currPos ) === 10 ) { s0 = peg$c25 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c26 ) ; } } return s0 ; } function peg$parseheader ( ) { var s0 , s1 , s2 , s3 , s4 , s5 , s6 , s7 ; s0 = peg$currPos ; if ( input . charCodeAt ( peg$currPos ) === 91 ) { s1 = peg$c27 ; peg$currPos ++ ; } else { s1 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c28 ) ; } } if ( s1 !== peg$FAILED ) { s2 = peg$parsesymbol ( ) ; if ( s2 !== peg$FAILED ) { s3 = [ ] ; s4 = peg$parsews ( ) ; if ( s4 !== peg$FAILED ) { while ( s4 !== peg$FAILED ) { s3 . push ( s4 ) ; s4 = peg$parsews ( ) ; } } else { s3 = peg$FAILED ; } if ( s3 !== peg$FAILED ) { s4 = peg$parsestring ( ) ; if ( s4 !== peg$FAILED ) { if ( input . charCodeAt ( peg$currPos ) === 93 ) { s5 = peg$c29 ; peg$currPos ++ ; } else { s5 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c30 ) ; } } if ( s5 !== peg$FAILED ) { s6 = [ ] ; s7 = peg$parsewhitespace ( ) ; while ( s7 !== peg$FAILED ) { s6 . push ( s7 ) ; s7 = peg$parsewhitespace ( ) ; } if ( s6 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c31 ( s2 , s4 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parseheaders ( ) { var s0 , s1 , s2 ; s0 = peg$currPos ; s1 = [ ] ; s2 = peg$parseheader ( ) ; if ( s2 !== peg$FAILED ) { while ( s2 !== peg$FAILED ) { s1 . push ( s2 ) ; s2 = peg$parseheader ( ) ; } } else { s1 = peg$FAILED ; } if ( s1 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c32 ( s1 ) ; } s0 = s1 ; return s0 ; } function peg$parsepiece ( ) { var s0 ; if ( peg$c33 . test ( input . charAt ( peg$currPos ) ) ) { s0 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c34 ) ; } } return s0 ; } function peg$parserank ( ) { var s0 ; if ( peg$c35 . test ( input . charAt ( peg$currPos ) ) ) { s0 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c36 ) ; } } return s0 ; } function peg$parsefile ( ) { var s0 ; if ( peg$c37 . test ( input . charAt ( peg$currPos ) ) ) { s0 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c38 ) ; } } return s0 ; } function peg$parsecheck ( ) { var s0 ; if ( input . charCodeAt ( peg$currPos ) === 43 ) { s0 = peg$c39 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c40 ) ; } } return s0 ; } function peg$parsecheckmate ( ) { var s0 ; if ( input . charCodeAt ( peg$currPos ) === 35 ) { s0 = peg$c41 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c42 ) ; } } return s0 ; } function peg$parsecapture ( ) { var s0 ; if ( input . charCodeAt ( peg$currPos ) === 120 ) { s0 = peg$c43 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c44 ) ; } } return s0 ; } function peg$parseperiod ( ) { var s0 ; if ( input . charCodeAt ( peg$currPos ) === 46 ) { s0 = peg$c45 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c46 ) ; } } return s0 ; } function peg$parseresult ( ) { var s0 ; if ( input . substr ( peg$currPos , 3 ) === peg$c47 ) { s0 = peg$c47 ; peg$currPos += 3 ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c48 ) ; } } if ( s0 === peg$FAILED ) { if ( input . substr ( peg$currPos , 3 ) === peg$c49 ) { s0 = peg$c49 ; peg$currPos += 3 ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c50 ) ; } } if ( s0 === peg$FAILED ) { if ( input . charCodeAt ( peg$currPos ) === 42 ) { s0 = peg$c51 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c52 ) ; } } if ( s0 === peg$FAILED ) { if ( input . substr ( peg$currPos , 7 ) === peg$c53 ) { s0 = peg$c53 ; peg$currPos += 7 ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c54 ) ; } } } } } return s0 ; } function peg$parsemove_number ( ) { var s0 , s1 , s2 , s3 , s4 , s5 ; s0 = peg$currPos ; s1 = peg$parseinteger ( ) ; if ( s1 !== peg$FAILED ) { s2 = peg$parseperiod ( ) ; if ( s2 === peg$FAILED ) { s2 = null ; } if ( s2 !== peg$FAILED ) { s3 = peg$currPos ; s4 = peg$parseperiod ( ) ; if ( s4 !== peg$FAILED ) { s5 = peg$parseperiod ( ) ; if ( s5 !== peg$FAILED ) { s4 = [ s4 , s5 ] ; s3 = s4 ; } else { peg$currPos = s3 ; s3 = peg$FAILED ; } } else { peg$currPos = s3 ; s3 = peg$FAILED ; } if ( s3 === peg$FAILED ) { s3 = null ; } if ( s3 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c55 ( s1 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsesquare ( ) { var s0 , s1 , s2 ; s0 = peg$currPos ; s1 = peg$parserank ( ) ; if ( s1 !== peg$FAILED ) { s2 = peg$parsefile ( ) ; if ( s2 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c56 ( s1 , s2 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsepromotion ( ) { var s0 , s1 , s2 ; s0 = peg$currPos ; if ( input . charCodeAt ( peg$currPos ) === 61 ) { s1 = peg$c57 ; peg$currPos ++ ; } else { s1 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c58 ) ; } } if ( s1 !== peg$FAILED ) { if ( peg$c59 . test ( input . charAt ( peg$currPos ) ) ) { s2 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s2 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c60 ) ; } } if ( s2 !== peg$FAILED ) { s1 = [ s1 , s2 ] ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsenag ( ) { var s0 , s1 , s2 , s3 ; s0 = peg$currPos ; s1 = peg$currPos ; if ( input . charCodeAt ( peg$currPos ) === 36 ) { s2 = peg$c61 ; peg$currPos ++ ; } else { s2 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c62 ) ; } } if ( s2 !== peg$FAILED ) { s3 = peg$parseinteger ( ) ; if ( s3 !== peg$FAILED ) { s2 = [ s2 , s3 ] ; s1 = s2 ; } else { peg$currPos = s1 ; s1 = peg$FAILED ; } } else { peg$currPos = s1 ; s1 = peg$FAILED ; } if ( s1 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c18 ( s1 ) ; } s0 = s1 ; return s0 ; } function peg$parsenag_alts ( ) { var s0 ; if ( input . substr ( peg$currPos , 2 ) === peg$c63 ) { s0 = peg$c63 ; peg$currPos += 2 ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c64 ) ; } } if ( s0 === peg$FAILED ) { if ( input . substr ( peg$currPos , 2 ) === peg$c65 ) { s0 = peg$c65 ; peg$currPos += 2 ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c66 ) ; } } if ( s0 === peg$FAILED ) { if ( input . substr ( peg$currPos , 2 ) === peg$c67 ) { s0 = peg$c67 ; peg$currPos += 2 ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c68 ) ; } } if ( s0 === peg$FAILED ) { if ( input . substr ( peg$currPos , 2 ) === peg$c69 ) { s0 = peg$c69 ; peg$currPos += 2 ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c70 ) ; } } if ( s0 === peg$FAILED ) { if ( input . charCodeAt ( peg$currPos ) === 33 ) { s0 = peg$c71 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c72 ) ; } } if ( s0 === peg$FAILED ) { if ( input . charCodeAt ( peg$currPos ) === 63 ) { s0 = peg$c73 ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c74 ) ; } } } } } } } return s0 ; } function peg$parsecontinuation ( ) { var s0 , s1 , s2 , s3 ; s0 = peg$currPos ; s1 = peg$parseperiod ( ) ; if ( s1 !== peg$FAILED ) { s2 = peg$parseperiod ( ) ; if ( s2 !== peg$FAILED ) { s3 = peg$parseperiod ( ) ; if ( s3 !== peg$FAILED ) { s1 = [ s1 , s2 , s3 ] ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsecomment_chars ( ) { var s0 ; if ( peg$c75 . test ( input . charAt ( peg$currPos ) ) ) { s0 = input . charAt ( peg$currPos ) ; peg$currPos ++ ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c76 ) ; } } return s0 ; } function peg$parsecomment ( ) { var s0 , s1 , s2 , s3 ; s0 = peg$currPos ; if ( input . charCodeAt ( peg$currPos ) === 123 ) { s1 = peg$c77 ; peg$currPos ++ ; } else { s1 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c78 ) ; } } if ( s1 !== peg$FAILED ) { s2 = [ ] ; s3 = peg$parsecomment_chars ( ) ; while ( s3 !== peg$FAILED ) { s2 . push ( s3 ) ; s3 = peg$parsecomment_chars ( ) ; } if ( s2 !== peg$FAILED ) { if ( input . charCodeAt ( peg$currPos ) === 125 ) { s3 = peg$c79 ; peg$currPos ++ ; } else { s3 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c80 ) ; } } if ( s3 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c81 ( s2 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsepawn_half_move ( ) { var s0 , s1 , s2 , s3 ; s0 = peg$currPos ; s1 = peg$currPos ; s2 = peg$parserank ( ) ; if ( s2 !== peg$FAILED ) { s3 = peg$parsecapture ( ) ; if ( s3 !== peg$FAILED ) { s2 = [ s2 , s3 ] ; s1 = s2 ; } else { peg$currPos = s1 ; s1 = peg$FAILED ; } } else { peg$currPos = s1 ; s1 = peg$FAILED ; } if ( s1 === peg$FAILED ) { s1 = null ; } if ( s1 !== peg$FAILED ) { s2 = peg$parsesquare ( ) ; if ( s2 !== peg$FAILED ) { s3 = peg$parsepromotion ( ) ; if ( s3 === peg$FAILED ) { s3 = null ; } if ( s3 !== peg$FAILED ) { s1 = [ s1 , s2 , s3 ] ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsepiece_half_move ( ) { var s0 , s1 , s2 , s3 ; s0 = peg$currPos ; s1 = peg$parsepiece ( ) ; if ( s1 !== peg$FAILED ) { s2 = peg$parsecapture ( ) ; if ( s2 === peg$FAILED ) { s2 = null ; } if ( s2 !== peg$FAILED ) { s3 = peg$parsesquare ( ) ; if ( s3 !== peg$FAILED ) { s1 = [ s1 , s2 , s3 ] ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsepiece_disambiguation_half_move ( ) { var s0 , s1 , s2 , s3 , s4 ; s0 = peg$currPos ; s1 = peg$parsepiece ( ) ; if ( s1 !== peg$FAILED ) { s2 = peg$parserank ( ) ; if ( s2 === peg$FAILED ) { s2 = peg$parsefile ( ) ; } if ( s2 !== peg$FAILED ) { s3 = peg$parsecapture ( ) ; if ( s3 === peg$FAILED ) { s3 = null ; } if ( s3 !== peg$FAILED ) { s4 = peg$parsesquare ( ) ; if ( s4 !== peg$FAILED ) { s1 = [ s1 , s2 , s3 , s4 ] ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsecastle_half_move ( ) { var s0 ; if ( input . substr ( peg$currPos , 5 ) === peg$c82 ) { s0 = peg$c82 ; peg$currPos += 5 ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c83 ) ; } } if ( s0 === peg$FAILED ) { if ( input . substr ( peg$currPos , 3 ) === peg$c84 ) { s0 = peg$c84 ; peg$currPos += 3 ; } else { s0 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c85 ) ; } } } return s0 ; } function peg$parsehalf_move ( ) { var s0 , s1 , s2 , s3 , s4 , s5 ; s0 = peg$currPos ; s1 = peg$currPos ; s2 = peg$parsecontinuation ( ) ; if ( s2 === peg$FAILED ) { s2 = null ; } if ( s2 !== peg$FAILED ) { s3 = peg$parsecastle_half_move ( ) ; if ( s3 === peg$FAILED ) { s3 = peg$parsepiece_disambiguation_half_move ( ) ; if ( s3 === peg$FAILED ) { s3 = peg$parsepiece_half_move ( ) ; if ( s3 === peg$FAILED ) { s3 = peg$parsepawn_half_move ( ) ; } } } if ( s3 !== peg$FAILED ) { s4 = peg$parsecheck ( ) ; if ( s4 === peg$FAILED ) { s4 = peg$parsecheckmate ( ) ; } if ( s4 === peg$FAILED ) { s4 = null ; } if ( s4 !== peg$FAILED ) { s5 = peg$parsenag_alts ( ) ; if ( s5 === peg$FAILED ) { s5 = null ; } if ( s5 !== peg$FAILED ) { s2 = [ s2 , s3 , s4 , s5 ] ; s1 = s2 ; } else { peg$currPos = s1 ; s1 = peg$FAILED ; } } else { peg$currPos = s1 ; s1 = peg$FAILED ; } } else { peg$currPos = s1 ; s1 = peg$FAILED ; } } else { peg$currPos = s1 ; s1 = peg$FAILED ; } if ( s1 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c86 ( s1 ) ; } s0 = s1 ; return s0 ; } function peg$parsemove ( ) { var s0 , s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 ; s0 = peg$currPos ; s1 = peg$parsemove_number ( ) ; if ( s1 === peg$FAILED ) { s1 = null ; } if ( s1 !== peg$FAILED ) { s2 = [ ] ; s3 = peg$parsewhitespace ( ) ; while ( s3 !== peg$FAILED ) { s2 . push ( s3 ) ; s3 = peg$parsewhitespace ( ) ; } if ( s2 !== peg$FAILED ) { s3 = peg$parsehalf_move ( ) ; if ( s3 !== peg$FAILED ) { s4 = [ ] ; s5 = peg$currPos ; s6 = [ ] ; s7 = peg$parsewhitespace ( ) ; if ( s7 !== peg$FAILED ) { while ( s7 !== peg$FAILED ) { s6 . push ( s7 ) ; s7 = peg$parsewhitespace ( ) ; } } else { s6 = peg$FAILED ; } if ( s6 !== peg$FAILED ) { s7 = peg$parsenag ( ) ; if ( s7 !== peg$FAILED ) { peg$savedPos = s5 ; s6 = peg$c87 ( s1 , s3 , s7 ) ; s5 = s6 ; } else { peg$currPos = s5 ; s5 = peg$FAILED ; } } else { peg$currPos = s5 ; s5 = peg$FAILED ; } while ( s5 !== peg$FAILED ) { s4 . push ( s5 ) ; s5 = peg$currPos ; s6 = [ ] ; s7 = peg$parsewhitespace ( ) ; if ( s7 !== peg$FAILED ) { while ( s7 !== peg$FAILED ) { s6 . push ( s7 ) ; s7 = peg$parsewhitespace ( ) ; } } else { s6 = peg$FAILED ; } if ( s6 !== peg$FAILED ) { s7 = peg$parsenag ( ) ; if ( s7 !== peg$FAILED ) { peg$savedPos = s5 ; s6 = peg$c87 ( s1 , s3 , s7 ) ; s5 = s6 ; } else { peg$currPos = s5 ; s5 = peg$FAILED ; } } else { peg$currPos = s5 ; s5 = peg$FAILED ; } } if ( s4 !== peg$FAILED ) { s5 = [ ] ; s6 = peg$currPos ; s7 = [ ] ; s8 = peg$parsewhitespace ( ) ; while ( s8 !== peg$FAILED ) { s7 . push ( s8 ) ; s8 = peg$parsewhitespace ( ) ; } if ( s7 !== peg$FAILED ) { s8 = peg$parsecomment ( ) ; if ( s8 !== peg$FAILED ) { peg$savedPos = s6 ; s7 = peg$c88 ( s1 , s3 , s4 , s8 ) ; s6 = s7 ; } else { peg$currPos = s6 ; s6 = peg$FAILED ; } } else { peg$currPos = s6 ; s6 = peg$FAILED ; } while ( s6 !== peg$FAILED ) { s5 . push ( s6 ) ; s6 = peg$currPos ; s7 = [ ] ; s8 = peg$parsewhitespace ( ) ; while ( s8 !== peg$FAILED ) { s7 . push ( s8 ) ; s8 = peg$parsewhitespace ( ) ; } if ( s7 !== peg$FAILED ) { s8 = peg$parsecomment ( ) ; if ( s8 !== peg$FAILED ) { peg$savedPos = s6 ; s7 = peg$c88 ( s1 , s3 , s4 , s8 ) ; s6 = s7 ; } else { peg$currPos = s6 ; s6 = peg$FAILED ; } } else { peg$currPos = s6 ; s6 = peg$FAILED ; } } if ( s5 !== peg$FAILED ) { s6 = [ ] ; s7 = peg$currPos ; s8 = [ ] ; s9 = peg$parsewhitespace ( ) ; if ( s9 !== peg$FAILED ) { while ( s9 !== peg$FAILED ) { s8 . push ( s9 ) ; s9 = peg$parsewhitespace ( ) ; } } else { s8 = peg$FAILED ; } if ( s8 !== peg$FAILED ) { s9 = peg$parserav ( ) ; if ( s9 !== peg$FAILED ) { peg$savedPos = s7 ; s8 = peg$c89 ( s1 , s3 , s4 , s5 , s9 ) ; s7 = s8 ; } else { peg$currPos = s7 ; s7 = peg$FAILED ; } } else { peg$currPos = s7 ; s7 = peg$FAILED ; } while ( s7 !== peg$FAILED ) { s6 . push ( s7 ) ; s7 = peg$currPos ; s8 = [ ] ; s9 = peg$parsewhitespace ( ) ; if ( s9 !== peg$FAILED ) { while ( s9 !== peg$FAILED ) { s8 . push ( s9 ) ; s9 = peg$parsewhitespace ( ) ; } } else { s8 = peg$FAILED ; } if ( s8 !== peg$FAILED ) { s9 = peg$parserav ( ) ; if ( s9 !== peg$FAILED ) { peg$savedPos = s7 ; s8 = peg$c89 ( s1 , s3 , s4 , s5 , s9 ) ; s7 = s8 ; } else { peg$currPos = s7 ; s7 = peg$FAILED ; } } else { peg$currPos = s7 ; s7 = peg$FAILED ; } } if ( s6 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c90 ( s1 , s3 , s4 , s5 , s6 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parsemovetext ( ) { var s0 , s1 , s2 , s3 , s4 , s5 ; s0 = peg$currPos ; s1 = peg$parsemove ( ) ; if ( s1 !== peg$FAILED ) { s2 = [ ] ; s3 = peg$currPos ; s4 = [ ] ; s5 = peg$parsewhitespace ( ) ; if ( s5 !== peg$FAILED ) { while ( s5 !== peg$FAILED ) { s4 . push ( s5 ) ; s5 = peg$parsewhitespace ( ) ; } } else { s4 = peg$FAILED ; } if ( s4 !== peg$FAILED ) { s5 = peg$parsemove ( ) ; if ( s5 !== peg$FAILED ) { s4 = [ s4 , s5 ] ; s3 = s4 ; } else { peg$currPos = s3 ; s3 = peg$FAILED ; } } else { peg$currPos = s3 ; s3 = peg$FAILED ; } while ( s3 !== peg$FAILED ) { s2 . push ( s3 ) ; s3 = peg$currPos ; s4 = [ ] ; s5 = peg$parsewhitespace ( ) ; if ( s5 !== peg$FAILED ) { while ( s5 !== peg$FAILED ) { s4 . push ( s5 ) ; s5 = peg$parsewhitespace ( ) ; } } else { s4 = peg$FAILED ; } if ( s4 !== peg$FAILED ) { s5 = peg$parsemove ( ) ; if ( s5 !== peg$FAILED ) { s4 = [ s4 , s5 ] ; s3 = s4 ; } else { peg$currPos = s3 ; s3 = peg$FAILED ; } } else { peg$currPos = s3 ; s3 = peg$FAILED ; } } if ( s2 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c91 ( s1 , s2 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function peg$parserav ( ) { var s0 , s1 , s2 , s3 , s4 , s5 , s6 , s7 ; s0 = peg$currPos ; if ( input . charCodeAt ( peg$currPos ) === 40 ) { s1 = peg$c92 ; peg$currPos ++ ; } else { s1 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c93 ) ; } } if ( s1 !== peg$FAILED ) { s2 = [ ] ; s3 = peg$parsewhitespace ( ) ; while ( s3 !== peg$FAILED ) { s2 . push ( s3 ) ; s3 = peg$parsewhitespace ( ) ; } if ( s2 !== peg$FAILED ) { s3 = peg$parsemovetext ( ) ; if ( s3 !== peg$FAILED ) { s4 = [ ] ; s5 = peg$parsewhitespace ( ) ; while ( s5 !== peg$FAILED ) { s4 . push ( s5 ) ; s5 = peg$parsewhitespace ( ) ; } if ( s4 !== peg$FAILED ) { s5 = peg$parseresult ( ) ; if ( s5 === peg$FAILED ) { s5 = null ; } if ( s5 !== peg$FAILED ) { s6 = [ ] ; s7 = peg$parsewhitespace ( ) ; while ( s7 !== peg$FAILED ) { s6 . push ( s7 ) ; s7 = peg$parsewhitespace ( ) ; } if ( s6 !== peg$FAILED ) { if ( input . charCodeAt ( peg$currPos ) === 41 ) { s7 = peg$c94 ; peg$currPos ++ ; } else { s7 = peg$FAILED ; if ( peg$silentFails === 0 ) { peg$fail ( peg$c95 ) ; } } if ( s7 !== peg$FAILED ) { peg$savedPos = s0 ; s1 = peg$c96 ( s3 , s5 ) ; s0 = s1 ; } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } } else { peg$currPos = s0 ; s0 = peg$FAILED ; } return s0 ; } function flatten ( a , acc = [ ] ) { for ( var i = 0 ; i < a . length ; i ++ ) { if ( Array . isArray ( a [ i ] ) ) { flatten ( a [ i ] , acc ) ; } else { acc . push ( a [ i ] ) ; } } return acc ; } function make_header ( hn , hv ) { var m = { } ; m [ hn ] = hv ; return m ; } function make_move ( move_number , move , nags , ravs , comments ) { var m = { } ; if ( move_number ) m . move_number = move_number ; if ( move ) m . move = move ; if ( nags && nags . length ) m . nags = nags ; if ( ravs && ravs . length ) m . ravs = ravs ; if ( comments && comments . length ) m . comments = comments ; return m ; } function make_rav ( moves , result ) { return { moves , result } ; } function make_game ( h , c , m , r ) { h = h || [ ] ; return { headers : h . reduce ( ( acc , x ) => Object . assign ( acc , x ) , { } ) , comments : c || [ ] , moves : m || [ ] , result : r } ; } peg$result = peg$startRuleFunction ( ) ; if ( peg$result !== peg$FAILED && peg$currPos === input . length ) { return peg$result ; } else { if ( peg$result !== peg$FAILED && peg$currPos < input . length ) { peg$fail ( peg$endExpectation ( ) ) ; } throw peg$buildStructuredError ( peg$maxFailExpected , peg$maxFailPos < input . length ? input . charAt ( peg$maxFailPos ) : null , peg$maxFailPos < input . length ? peg$computeLocation ( peg$maxFailPos , peg$maxFailPos + 1 ) : peg$computeLocation ( peg$maxFailPos , peg$maxFailPos ) ) ; } } module . exports = { SyntaxError : peg$SyntaxError , parse : peg$parse } ;