From 244a4b5b1499aca5c36de2c6c1f8bd202de42f4b Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Thu, 17 Jul 2014 16:33:18 +0200 Subject: [PATCH] Adds compatibility for Nimrod's 0.9.4 compiler. --- babel.babel | 2 +- src/babel.nim | 4 ++-- src/babelpkg/compat.nim | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/babelpkg/compat.nim diff --git a/babel.babel b/babel.babel index 31282f0..359682e 100644 --- a/babel.babel +++ b/babel.babel @@ -9,4 +9,4 @@ bin = "babel" srcDir = "src" [Deps] -Requires: "nimrod >= 0.9.5" +Requires: "nimrod >= 0.9.4" diff --git a/src/babel.nim b/src/babel.nim index f96dc9d..18ae079 100644 --- a/src/babel.nim +++ b/src/babel.nim @@ -6,8 +6,8 @@ import httpclient, parseopt, os, strutils, osproc, pegs, tables, parseutils, from sequtils import toSeq -import babelpkg/packageinfo, babelpkg/version, babelpkg/tools, babelpkg/download, - babelpkg/config +import babelpkg/packageinfo, babelpkg/version, babelpkg/tools, + babelpkg/download, babelpkg/config, babelpkg/compat when not defined(windows): from posix import getpid diff --git a/src/babelpkg/compat.nim b/src/babelpkg/compat.nim new file mode 100644 index 0000000..408e5df --- /dev/null +++ b/src/babelpkg/compat.nim @@ -0,0 +1,28 @@ +# Copyright (C) Dominik Picheta. All rights reserved. +# BSD License. Look at license.txt for more info. + +## This module contains additional code from the development version of +## Nimrod's standard library. These procs are required to be able to compile +## against the last stable release 0.9.4. Once 0.9.6 is release these procs +## will disappear. + +import json + +when not defined(`json.{}`): + proc `{}`*(node: PJsonNode, key: string): PJsonNode = + ## Transverses the node and gets the given value. If any of the + ## names does not exist, returns nil + result = node + if isNil(node): return nil + result = result[key] + +when not defined(`json.{}=`): + proc `{}=`*(node: PJsonNode, names: varargs[string], value: PJsonNode) = + ## Transverses the node and tries to set the value at the given location + ## to `value` If any of the names are missing, they are added + var node = node + for i in 0..(names.len-2): + if isNil(node[names[i]]): + node[names[i]] = newJObject() + node = node[names[i]] + node[names[names.len-1]] = value