JSON.ttcn 4.46 KB
Newer Older
Yann Garcia's avatar
Yann Garcia committed
module JSON {
  
YannGarcia's avatar
YannGarcia committed
  // These constants are used in the JSON date/time type definitions
  const charstring
    dash := "-",
    cln  := ":",
    year := "[0-9]#4",
    yearExpansion := "(-([1-9][0-9]#(0,))#(,1))#(,1)",
    month := "(0[1-9]|1[0-2])",
    dayOfMonth := "(0[1-9]|[12][0-9]|3[01])",
    hour := "([01][0-9]|2[0-3])",
    minute := "([0-5][0-9])",
    second := "([0-5][0-9])",
    sFraction := "(.[0-9]#(1,))#(,1)",
    endOfDayExt := "24:00:00(.0#(1,))#(,1)",
    nums := "[0-9]#(1,)",
    ZorTimeZoneExt := "(Z|[+-]((0[0-9]|1[0-3]):[0-5][0-9]|14:00))#(,1)",
    durTime := "(T[0-9]#(1,)"&
               "(H([0-9]#(1,)(M([0-9]#(1,)(S|.[0-9]#(1,)S))#(,1)|.[0-9]#(1,)S|S))#(,1)|"&
               "M([0-9]#(1,)(S|.[0-9]#(1,)S)|.[0-9]#(1,)M)#(,1)|"&
               "S|"&
               ".[0-9]#(1,)S))";
  type universal charstring utf8string;
  type utf8string JSONCompatibleString
  (
   char(0,0,0,9)..char(0,0,0,9),
   char(0,0,0,10)..char(0,0,0,10),
   char(0,0,0,13)..char(0,0,0,13),
   char(0,0,0,32)..char(0,0,215,255),
   char(0,0,224,0)..char(0,0,255,253),
   char(0,1,0,0)..char(0,16,255,253)
   );
  type utf8string JSONStringWithNoWhitespace
  (
   char(0,0,0,33)..char(0,0,215,255),
   char(0,0,224,0)..char(0,0,255,253),
   char(0,1,0,0)..char(0,16,255,253)
   );
  type utf8string JSONStringWithNoCRLFHT
  (
   char(0,0,0,32)..char(0,0,215,255),
   char(0,0,224,0)..char(0,0,255,253),
   char(0,1,0,0)..char(0,16,255,253)
   );

Yann Garcia's avatar
Yann Garcia committed
  // JSON Number type (generic)
  type float Number (!-infinity .. !infinity) /*with {
    variant "JSON:number"
YannGarcia's avatar
YannGarcia committed
    }*/;
Yann Garcia's avatar
Yann Garcia committed
  // Integer type
  type integer Integer (-infinity .. infinity) /*with {
    variant "JSON:integer"
YannGarcia's avatar
YannGarcia committed
    }*/;
Yann Garcia's avatar
Yann Garcia committed
  // String type
YannGarcia's avatar
YannGarcia committed
  type utf8string String /*with {
Yann Garcia's avatar
Yann Garcia committed
    variant "JSON:string"
YannGarcia's avatar
YannGarcia committed
    }*/;
  type JSONStringWithNoCRLFHT NormalizedString /*with {
    variant "JSON:normalizedString";
    }*/;
  type JSONStringWithNoWhitespace Name /*with {
    variant "JSON:Name";
    }*/;
  type Name NCName /*with {
    variant "JSON:NCName";
    }*/;
  type NormalizedString Token /*with {
    variant "JSON:token";
    }*/;
  type JSONStringWithNoCRLFHT AnyURI /*with {
    variant "JSON:anyURI";
    }*/;
  type charstring Duration (pattern
                            "{dash}#(,1)P({nums}(Y({nums}(M({nums}D{durTime}#(,1)|{durTime}#(,1))|D{durTime}#(,1))|" &
                            "{durTime}#(,1))|M({nums}D{durTime}#(,1)|{durTime}#(,1))|D{durTime}#(,1))|{durTime})")
  /*with {
    variant "JSON:duration";
    }*/;
  type charstring DateTime (pattern
                            "{yearExpansion}{year}{dash}{month}{dash}{dayOfMonth}T({hour}{cln}{minute}{cln}{second}" &
                            "{sFraction}|{endOfDayExt}){ZorTimeZoneExt}" )
  /*with {
    variant "JSON:dateTime";
    }*/;
  type charstring Time (pattern "({hour}{cln}{minute}{cln}{second}{sFraction}|{endOfDayExt}){ZorTimeZoneExt}" )
  /*with {
    variant "JSON:time";
    }*/;
  type charstring Date (pattern "{yearExpansion}{year}{dash}{month}{dash}{dayOfMonth}{ZorTimeZoneExt}" )
  /*with {
    variant "JSON:date";
    }*/;
Yann Garcia's avatar
Yann Garcia committed
  // Array type
  /*type record of JSON.Values Array with {
    variant "JSON:array"
    }*/
  // Subsidiary array types
  type record of JSON.String StrArray /*with {
    variant "JSON:array"
    }*/
  type record of JSON.Number NumArray /*with {
    variant "JSON:array"
    }*/
  type record of JSON.Integer IntArray /*with {
    variant "JSON:array"
    }
  type record of JSON.Bool BoolArray with {
    variant "JSON:array"
    }
  type record of JSON.Object ObjArray with {
    variant "JSON:array"
    }*/
  // Object member
  /*type record ObjectMember {
    JSON.String name,
    JSON.Values value_
    } with {
    variant "JSON:objectMember"
    }*/
  // Generic JSON object type
  /*type record Object {
    record length (1..infinity) of JSON.ObjectMember memberList optional
    } with {
    variant "JSON:object"
    }
  type union Values {
    JSON.String str,
    JSON.Number num,
    JSON.Integer int,
    JSON.Object object,
    JSON.Array array,
    JSON.StrArray strArray,
    JSON.NumArray numArray,
    JSON.IntArray intArray,
    JSON.BoolArray boolArray,
    JSON.ObjArray objArray,
    JSON.Bool bool,
    JSON.Null null_
  } with {
    variant "asValue"
  }*/
  
  //JSON literals
  //When only the true and false literals are allowed
  type boolean Bool /*with { variant "JSON:literal" }*/
  //When only the null literal is allowed
  type enumerated Null { null_ }; /*with { variant "JSON:literal" }*/
  
YannGarcia's avatar
YannGarcia committed
} with {
  encode "JSON"
Yann Garcia's avatar
Yann Garcia committed
} // End of module JSON