1 module gherkin.base; 2 3 import std.json : parseJSON, JSONValue; 4 import std..string : empty; 5 import std.typecons : Nullable; 6 7 import asdf : serializeToJson; 8 import gherkin.location; 9 10 /// 11 abstract class Base 12 { 13 /// 14 string keyword; 15 /// 16 Nullable!string name; 17 /// 18 Location location; 19 20 /// 21 this(string keyword, string name, Location location) 22 { 23 this.keyword = keyword; 24 this.location = location; 25 if (!name.empty) 26 { 27 this.name = name; 28 } 29 } 30 31 /// 32 JSONValue toJSON() const 33 { 34 auto json = JSONValue([ 35 "keyword": JSONValue(keyword), 36 "location": parseJSON(serializeToJson(location)) 37 ]); 38 if (!name.isNull) 39 { 40 json["name"] = JSONValue(name.get); 41 } 42 43 return json; 44 } 45 }