Able to export SGF files from successful games.
This commit is contained in:
134
data/SGF.g
134
data/SGF.g
@@ -44,36 +44,42 @@ $sgfProperty = new SGFProperty();
|
||||
| (strIdent{$sgfProperty.setIdentifier($strIdent.sgfIdent);}) ((LBRACKET RBRACKET){$sgfProperty.addValue(SGFValue.EMPTY);})
|
||||
| (strIdent{$sgfProperty.setIdentifier($strIdent.sgfIdent);}) ((LBRACKET strValue RBRACKET){$sgfProperty.addValue(new SGFValue<String>($strValue.text));})+
|
||||
|
||||
| (result{$sgfProperty.setIdentifier(SGFIdentifier.RESULT);}) ((LBRACKET resValue RBRACKET){$sgfProperty.addValue(new SGFValue<SGFResult>(new SGFResult($resValue.text)));})+
|
||||
| (result{$sgfProperty.setIdentifier(SGFIdentifier.RESULT);}) ((LBRACKET strValue RBRACKET){$sgfProperty.addValue(new SGFValue<SGFResult>(new SGFResult($strValue.text)));})+
|
||||
|
||||
| (komi{$sgfProperty.setIdentifier(SGFIdentifier.KOMI);}) ((LBRACKET realValue RBRACKET){$sgfProperty.addValue(new SGFValue<Double>(Double.parseDouble($realValue.text)));})+
|
||||
| (coordIdent{$sgfProperty.setIdentifier($coordIdent.sgfIdent);})((LBRACKET coordValue RBRACKET){$sgfProperty.addValue(new SGFValue<SGFCoord>(new SGFCoord($coordValue.text)));})+
|
||||
;
|
||||
|
||||
|
||||
//playerIdent is a disambiguating rule
|
||||
playerIdent returns [SGFIdentifier sgfPlayer]
|
||||
: {(input.LT(1).getText().equals("W"))}? strIdent {$sgfPlayer = $strIdent.sgfIdent;}
|
||||
| {(input.LT(1).getText().equals("B"))}? strIdent {$sgfPlayer = $strIdent.sgfIdent;}
|
||||
| {(input.LT(1).getText().equals("White"))}? strIdent {$sgfPlayer = $strIdent.sgfIdent;}
|
||||
| {(input.LT(1).getText().equals("Black"))}? strIdent {$sgfPlayer = $strIdent.sgfIdent;}
|
||||
;
|
||||
|
||||
strIdent returns [SGFIdentifier sgfIdent]
|
||||
: charEnc{$sgfIdent = SGFIdentifier.CHARSET;}
|
||||
| source
|
||||
| blackCountry
|
||||
| whiteCountry
|
||||
| event
|
||||
| playerBlack
|
||||
| playerWhite
|
||||
| blackRank
|
||||
| whiteRank
|
||||
| result
|
||||
| rules
|
||||
| place
|
||||
| application
|
||||
| source{$sgfIdent = SGFIdentifier.SOURCE;}
|
||||
| blackCountry{$sgfIdent = SGFIdentifier.COUNTRY_BLACK;}
|
||||
| whiteCountry{$sgfIdent = SGFIdentifier.COUNTRY_WHITE;}
|
||||
| event{$sgfIdent = SGFIdentifier.EVENT;}
|
||||
| playerBlack{$sgfIdent = SGFIdentifier.PLAYER_BLACK;}
|
||||
| playerWhite{$sgfIdent = SGFIdentifier.PLAYER_WHITE;}
|
||||
| blackRank{$sgfIdent = SGFIdentifier.RANK_BLACK;}
|
||||
| whiteRank{$sgfIdent = SGFIdentifier.RANK_WHITE;}
|
||||
| rules{$sgfIdent = SGFIdentifier.RULES;}
|
||||
| place{$sgfIdent = SGFIdentifier.PLACE;}
|
||||
| application{$sgfIdent = SGFIdentifier.APPLICATION;}
|
||||
| copyright
|
||||
| username
|
||||
| date
|
||||
| date{$sgfIdent = SGFIdentifier.DATE;}
|
||||
| 'Black'{$sgfIdent = SGFIdentifier.MOVE_BLACK;}
|
||||
| 'White'{$sgfIdent = SGFIdentifier.MOVE_WHITE;}
|
||||
| 'B'{$sgfIdent = SGFIdentifier.MOVE_BLACK;}
|
||||
| 'W'{$sgfIdent = SGFIdentifier.MOVE_WHITE;}
|
||||
| view{$sgfIdent = SGFIdentifier.VIEW;} //this is not really a strIdent, but is a placeholder since I don't use this info
|
||||
| comment{$sgfIdent = SGFIdentifier.COMMENT;}
|
||||
//SGF grammar proper allows extensions, but this reader does not
|
||||
; //if this is matched from rule playerIdent, the value is thrown away - this rule alone
|
||||
//lack the context to disambiguate the single-character player movement IDs.
|
||||
@@ -90,48 +96,65 @@ numIdent returns [SGFIdentifier sgfIdent]
|
||||
| time{$sgfIdent = SGFIdentifier.TIME;};
|
||||
|
||||
numValue returns [SGFValue<Integer> sgfValue]
|
||||
: (DIGIT+){$sgfValue = new SGFValue<Integer>(Integer.parseInt($numValue.text));};
|
||||
|
||||
: (STRVALUE){$sgfValue = new SGFValue<Integer>(Integer.parseInt($numValue.text));};
|
||||
|
||||
realIdent
|
||||
: komi;
|
||||
|
||||
resValue //'R' is resign
|
||||
: playerIdent PLUS ('R' | realValue);
|
||||
|
||||
realValue
|
||||
: DIGIT+ PERIOD DIGIT+;
|
||||
|
||||
: STRVALUE;
|
||||
|
||||
coordValue returns [SGFCoord sgfCoord]
|
||||
: LCLETTER LCLETTER {$sgfCoord = new SGFCoord($text);}
|
||||
: STRVALUE {$sgfCoord = new SGFCoord($coordValue.text);}
|
||||
;
|
||||
|
||||
fileFormat
|
||||
: 'FF';
|
||||
game : 'GM';
|
||||
size : 'SZ';
|
||||
|
||||
game : 'GM' | 'GaMe';
|
||||
|
||||
size : 'SZ' | 'SiZe';
|
||||
|
||||
view : 'VW' | 'VieW';
|
||||
|
||||
charEnc : 'CA';
|
||||
|
||||
source : 'SO';
|
||||
|
||||
blackCountry
|
||||
: 'BC';
|
||||
|
||||
whiteCountry
|
||||
: 'WC';
|
||||
event : 'EV';
|
||||
|
||||
event : 'EV' | 'EVent';
|
||||
|
||||
playerBlack
|
||||
: 'PB';
|
||||
: 'PB' | 'PlayerBlack';
|
||||
playerWhite
|
||||
: 'PW';
|
||||
: 'PW' | 'PlayerWhite';
|
||||
blackRank
|
||||
: 'BR';
|
||||
|
||||
whiteRank
|
||||
: 'WR';
|
||||
|
||||
komi : 'KM';
|
||||
result : 'RE';
|
||||
|
||||
result : 'RE'
|
||||
| 'REsult'
|
||||
;
|
||||
|
||||
rules : 'RU';
|
||||
place : 'PC';
|
||||
|
||||
place : 'PC' | 'PlaCe';
|
||||
|
||||
application
|
||||
: 'AP';
|
||||
|
||||
time : 'TM';
|
||||
date : 'DT';
|
||||
|
||||
date : 'DT' | 'DaTe';
|
||||
|
||||
addBlack returns [SGFIdentifier sgfIdent]
|
||||
: 'AB'{$sgfIdent = SGFIdentifier.ADD_BLACK;}
|
||||
@@ -143,19 +166,40 @@ addWhite returns [SGFIdentifier sgfIdent]
|
||||
|
||||
copyright
|
||||
: 'CP';
|
||||
|
||||
username: 'US';
|
||||
|
||||
strValue : (UCLETTER | LCLETTER | MINUS | DIGIT | SPACE | PERIOD | COMMA | PLUS | SLASH | COLON)+;
|
||||
comment : 'C';
|
||||
|
||||
strValue
|
||||
: (STRVALUE)+;
|
||||
|
||||
SPACE : ' ';
|
||||
|
||||
fragment DIGIT : '0'..'9';
|
||||
|
||||
COLON : ':';
|
||||
|
||||
MINUS : '-';
|
||||
|
||||
fragment PERIOD : '.';
|
||||
|
||||
COMMA : ',';
|
||||
|
||||
PLUS : '+';
|
||||
|
||||
SLASH : '/';
|
||||
|
||||
|
||||
STRVALUE : (UCLETTER | LCLETTER | MINUS | DIGIT | SPACE | PERIOD | COMMA | PLUS | SLASH | COLON )+;
|
||||
|
||||
LPAREN : '(' ;
|
||||
|
||||
SEMICOLON : ';' ;
|
||||
|
||||
UCLETTER : 'A'..'Z';
|
||||
fragment UCLETTER : 'A'..'Z';
|
||||
|
||||
LCLETTER : 'a'..'z';
|
||||
|
||||
DIGIT : '0'..'9';
|
||||
fragment LCLETTER : 'a'..'z';
|
||||
|
||||
LBRACKET
|
||||
: '[';
|
||||
@@ -165,20 +209,6 @@ RBRACKET
|
||||
|
||||
RPAREN : ')';
|
||||
|
||||
COLON : ':';
|
||||
//CR : '\r'{$channel=HIDDEN;};
|
||||
|
||||
MINUS : '-';
|
||||
|
||||
SPACE : ' ';
|
||||
|
||||
PERIOD : '.';
|
||||
|
||||
COMMA : ',';
|
||||
|
||||
PLUS : '+';
|
||||
|
||||
SLASH : '/';
|
||||
|
||||
CR : '\r'{$channel=HIDDEN;};
|
||||
|
||||
NEWLINE : '\n'{$channel=HIDDEN;};
|
||||
//NEWLINE : '\n'{$channel=HIDDEN;};
|
||||
|
||||
Reference in New Issue
Block a user