From 2b0e20abd0eefe681bec7dda54889cc334b140ab Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Mon, 17 May 2021 19:50:10 +0200 Subject: [PATCH] fixed server to compile with current Nim --- server/server.nim | 26 ++++++++++++-------------- yaml/presenter.nim | 10 +++++++--- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/server/server.nim b/server/server.nim index 398ae38..8f35118 100644 --- a/server/server.nim +++ b/server/server.nim @@ -5,13 +5,12 @@ # distribution, for details about the copyright. import jester, asyncdispatch, json, streams, strutils -import packages.docutils.rstgen, packages.docutils.highlite +import packages.docutils.rstgen, packages.docutils.highlite, options import ../yaml routes: get "/": - headers["Content-Type"] = "text/plain" - resp "I am a friendly NimYAML parser webservice." + resp(Http200, [("Content-Type", "text/plain")], "I am a friendly NimYAML parser webservice.") post "/": var style: PresentationStyle @@ -19,10 +18,8 @@ routes: msg: string retStatus = Http200 contentType = "application/json" - headers["Access-Control-Allow-Origin"] = "*" - headers["Pragma"] = "no-cache" - headers["Cache-Control"] = "no-cache" - headers["Expires"] = "0" + headers = @[("Access-Control-Allow-Origin", "*"), ("Pragma", "no-cache"), + ("Cache-Control", "no-cache"), ("Expires", "0")] try: case @"style" of "minimal": style = psMinimal @@ -33,7 +30,7 @@ routes: of "tokens": var output = "+STR\n" - parser = newYamlParser() + parser = initYamlParser(false) events = parser.parse(newStringStream(@"input")) for event in events: output.add(parser.display(event) & "\n") output &= "-STR" @@ -44,7 +41,7 @@ routes: retStatus = Http400 msg = "Invalid style: " & escape(@"style") contentType = "text/plain;charset=utf8" - if isNil(msg): + if len(msg) == 0: var output = newStringStream() highlighted = "" @@ -60,9 +57,9 @@ routes: of gtNone, gtWhitespace: highlighted.add(substr(output.data, g.start, g.length + g.start - 1)) else: - highlighted.addf("$1", "\\span$2{$1}", [ + highlighted.addf("$1", "\\span$2{$1}", esc(outHtml, substr(output.data, g.start, g.length+g.start-1)), - tokenClassToStr[g.kind]]) + tokenClassToStr[g.kind]) resultNode["code"] = %0 resultNode["output"] = %highlighted @@ -70,8 +67,8 @@ routes: except YamlParserError: let e = (ref YamlParserError)(getCurrentException()) resultNode["code"] = %1 - resultNode["line"] = %e.line - resultNode["column"] = %e.column + resultNode["line"] = %e.mark.line + resultNode["column"] = %e.mark.column resultNode["message"] = %e.msg resultNode["detail"] = %e.lineContent msg = resultNode.pretty @@ -86,5 +83,6 @@ routes: "\nTrace:\n" & e.getStackTrace retStatus = Http500 contentType = "text/plain;charset=utf-8" - resp retStatus, msg, contentType + headers.add(("Content-Type", contentType)) + resp retStatus, headers, msg runForever() diff --git a/yaml/presenter.nim b/yaml/presenter.nim index 55b6ff1..8559989 100644 --- a/yaml/presenter.nim +++ b/yaml/presenter.nim @@ -805,7 +805,8 @@ proc transform*(input: Stream | string, output: Stream, ## while resolving non-specific tags to the ones in the YAML core tag ## library. If ``resolveToCoreYamlTags`` is ``true``, non-specific tags will ## be replaced by specific tags according to the YAML core schema. - doTransform(genInput(input), output, options, resolveToCoreYamlTags) + var c = Context(target: output, options: options) + doTransform(c, genInput(input), resolveToCoreYamlTags) proc transform*(input: Stream | string, options: PresentationOptions = defaultPresentationOptions, @@ -817,5 +818,8 @@ proc transform*(input: Stream | string, ## YAML string that represents the stream. If ``resolveToCoreYamlTags`` is ## ``true``, non-specific tags will be replaced by specific tags according to ## the YAML core schema. - result = "" - doTransform(genInput(input), addr result, options, resolveToCoreYamlTags) + var + ss = newStringStream() + c = Context(target: ss, options: options) + doTransform(c, genInput(input), resolveToCoreYamlTags) + return ss.data \ No newline at end of file