public PgnParserStatemachine() { _restOfLineCommentState = new TextCommentState(this); _textCommentState = new TextCommentState(this); _tagSectionState = new TagSectionState(this); _movesSectionState = new MovesSectionState(this); _initState = new InitState(this); _recursiveVariationState = new RecursiveVariationState(this); _annotationState = new AnnotationState(this); _initState.AddTransition(() => _restOfLineCommentState, c => c == PgnToken.RestOfLineComment.Token); _initState.AddTransition(() => _textCommentState, c => c == PgnToken.TextCommentBegin.Token); _initState.AddTransition(() => _tagSectionState, c => c == PgnToken.TagBegin.Token); _initState.AddTransition(() => _movesSectionState, c => char.IsDigit(c), game => _movesSectionState.InitGame(game)); _annotationState.AddExit(GetPreviousState, c => c == ' '); _recursiveVariationState.AddExit(GetPreviousState, c => c == PgnToken.RecursiveVariationEnd.Token); _recursiveVariationState.AddTransition(() => _annotationState, c => c == PgnToken.NumericAnnotationGlyph.Token); _recursiveVariationState.AddTransition(() => _restOfLineCommentState, c => c == PgnToken.RestOfLineComment.Token); _recursiveVariationState.AddTransition(() => _textCommentState, c => c == PgnToken.TextCommentBegin.Token); _recursiveVariationState.AddTransition(() => _recursiveVariationState, c => c == PgnToken.RecursiveVariationBegin.Token); _restOfLineCommentState.AddExit(GetPreviousState, c => c == '\n'); _textCommentState.AddExit(GetPreviousState, c => c == PgnToken.TextCommentEnd.Token); _textCommentState.AddTransition(() => _textCommentState, c => c == PgnToken.TextCommentBegin.Token); _tagSectionState.AddExit(() => _initState, c => c == PgnToken.TagEnd.Token); _tagSectionState.AddTransition(() => _restOfLineCommentState, c => c == PgnToken.RestOfLineComment.Token); _tagSectionState.AddTransition(() => _textCommentState, c => c == PgnToken.TextCommentBegin.Token); _movesSectionState.AddTransition(() => _annotationState, c => c == PgnToken.NumericAnnotationGlyph.Token); _movesSectionState.AddTransition(() => _restOfLineCommentState, c => c == PgnToken.RestOfLineComment.Token); _movesSectionState.AddTransition(() => _textCommentState, c => c == PgnToken.TextCommentBegin.Token); _movesSectionState.AddTransition(() => _recursiveVariationState, c => c == PgnToken.RecursiveVariationBegin.Token); _movesSectionState.AddExit(() => _tagSectionState, c => c == PgnToken.TagBegin.Token); _currentState = _initState; _currentState.Init(); }
public void ChangeState(PgnParserState newState, PgnMove currentMove = null) { _statemachine.SetState(newState); newState.OnEnter(currentMove); }
internal void SetState(PgnParserState newState) { _currentState = newState; }