セイロンにファイルライターを書くことを私は任務を務めましたが、その過程で、セイロンにifステートメントを書くことが難しくなりました。セイロンの遠くの土地でのコンパイルの狭い橋の上でタイプ正しさの強大なウィザードが直面している:ifステートメントをセイロンに書く
私が手にエラーが「:(10、1)セイロン:正しくない構文: 『もし』での行方不明EOFエラー」であります
これは私の文の(最初の行は10行である)場合:
if (is Nil fileResource || is File fileResource) {
File file = createFileIfNil(fileResource);
value writer = file.Overwriter();
//writer.writeLine("Hello, World!");
} else {
print("hello");
}
EDIT: これはBastien Jansensの推奨に従って更新されたif文です。エラーが、しかし、同じ:(
Path folderPath = parsePath("""C:\Users\Jon\Auchitect\POSTtoFile""");
Path filePath = folderPath.childPath("BPset.json.txt");
FResource fileResource = filePath.resource;
if (is Nil|File fileResource) {
File file = createFileIfNil(fileResource);
value writer = file.Overwriter();
//writer.writeLine("Hello, World!");
} else {
print("hello");
}
ままこれが私のアプリケーションの完全なソースコードです:
import ceylon.http.server { newServer, startsWith, Endpoint, Request, Response }
import ceylon.io { SocketAddress }
import ceylon.file { Path, parsePath, File, createFileIfNil, FResource = Resource }
// let's create a file with "hello world":
Path folderPath = parsePath("""C:\Users\Jon\Auchitect\POSTtoFile""");
Path filePath = folderPath.childPath("BPset.json.txt");
FResource fileResource = filePath.resource;
if (is Nil|File fileResource) {
File file = createFileIfNil(fileResource);
value writer = file.Overwriter();
//writer.writeLine("Hello, World!");
} else {
print("hello");
}
shared void runServer() {
//create a HTTP server
value server = newServer {
//an endpoint, on the path /hello
Endpoint {
path = startsWith("/postBPset");
//handle requests to this path
function service(Request request, Response response) {
variable String logString;
variable String jsonString;
variable String contentType;
contentType = request.contentType
else "(not specified)";
logString = "Received " + request.method.string + " request \n"
+ "Content type: " + contentType + "\n"
+ "Request method: " + request.method.string + "\n";
jsonString = request.read();
print(logString);
return response;
}
}
};
//start the server on port 8080
server.start(SocketAddress("127.0.0.1",8080));
}
チップのおかげで。私はそれに応じて更新しました。ただし、エラーメッセージは同じままです。 – loldrup
私のコメントを編集しました。関数に 'if'を入れる必要があります。 –
これで、ファイルに何も書き込まれない限り(これは作成されるだけです)、動作します。私は単に、私の最上位レベルの行をrunServer関数に置きます。 – loldrup