コード例 #1
0
    public CommandTreeToken Expect(CommandTreeToken.Kind expected)
    {
        if (Current == null)
        {
            throw CommandParseException.ExpectedTokenButFoundNull(expected);
        }

        var found = Current.TokenKind;

        if (expected != found)
        {
            throw CommandParseException.ExpectedTokenButFoundOther(expected, found);
        }

        return(Current);
    }
コード例 #2
0
 public static ParseException ExpectedTokenButFoundOther(CommandTreeToken.Kind expected, CommandTreeToken.Kind found)
 {
     return(new ParseException($"Expected to find token of type '{expected}' but found '{found}' instead."));
 }
コード例 #3
0
 public CommandTreeToken?Consume(CommandTreeToken.Kind type)
 {
     Expect(type);
     return(Consume());
 }
コード例 #4
0
 public static ParseException ExpectedTokenButFoundNull(CommandTreeToken.Kind expected)
 {
     return(new ParseException($"Expected to find any token of type '{expected}' but found null instead."));
 }