diff --git a/platforms/json.lt b/platforms/json.lt new file mode 100644 index 0000000..8e69138 --- /dev/null +++ b/platforms/json.lt @@ -0,0 +1,100 @@ + +type UTF8-String = <Seq Char~Unicode> ~ UTF-8 ~ <Seq~<ValueTerminated 0> native.UInt8> ; + +type SerializedJson.Value = json.Value + ~ <Enum + <Null json.Null ~ SerializedJson.Null > + <String json.String ~ SerializedJson.String > + <Number json.Number ~ SerializedJson.Number > + <Bool json.Bool ~ SerializedJson.Bool > + <Array json.Array ~ SerializedJson.Array > + <Object json.Object ~ SerializedJson.Object >> + ~ <Seq Char> ; + +type SerializedJson.Null = < Struct~<Seq Char> "\"null\"" > ; + +type SerializedJson.String = <Seq Char> + ~ <Struct~<Seq Char> "\"" <Seq Char> "\""> + ~ <Seq Char> ; + +type SerializedJson.Number = ℝ + ~ <PosInt 10 BigEndian> + ~ <Seq <Digit 10> ~ Char> ; + +type SerializedJson.Bool = Bool + ~ <Enum~<Seq Char> + <True~"\"true\"" <>> + <False~"\"false\"" <>>> + ~ <Seq Char> ; + +type SerializedJson.Array = <Struct~<Seq Char> + "[" + <Seq json.Value> + ~ <ValueSep ',' Char> + ~ <Seq Char> + "]" > + ~ <Seq Char> ; + +type SerializedJson.Object = <Struct~<Seq Char> + "{" + <members <Seq + <Struct~<Seq Char> + <key json.String> + ":" + <value json.Value>>>> + "}" + > + ~ <Seq Char>; + +type parsedJson.Value = json.Value ~ <Enum~native.UInt8 + < parsedJson_Null~0 <> > + < parsedJson_String~1 <Ref UTF8-String> ~ native.Address > + < parsedJson_Int~2 ℝ~ℕ~native.UInt64 > + < parsedJson_Float~2 ℝ~native.Float64 > + < parsedJson_Bool~3 Bool ~ native.UInt8 > + + < parsedJson_Array~4 <Ref <Seq ~ <LengthPrefix native.UInt64> + parsedJsonValue + > + > + ~ native.Address > + + < parsedJson_Object~5 <Ref <Seq ~ <LengthPrefix native.UInt64> + <Struct + <key <Ref UTF8-String> ~ native.Address> + <val parsedJsonValue> + > + > + ~ native.Address >> + ~ <Struct + <tag native.UInt8> + native.UInt64 >; + +parse_json_value () + json.Value ~ UTF8-String +--> json.Value ~ parsedJsonValue +``` + + { + dst->tag = PARSED_JSON_NULL; + dst->parsedJson_Null; + } + + { + dst->tag = PARSED_JSON_STRING; + dst->parsedJson_String = malloc(len); + strncpy(dst->parsedJson_String, src, len); + src += len; + } + + { + dst->tag = PARSED_JSON_NUMBER; + + MORPH( + "ℝ ~ ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10> ~ Char> ~ UTF8-String", + "ℝ ~ ℕ ~ native.UInt64", + src, + &dst->parsedJson_Number + ); + } +``` diff --git a/platforms/json5.lt b/platforms/json5.lt new file mode 100644 index 0000000..e69de29 diff --git a/platforms/protobuf.lt b/platforms/protobuf.lt new file mode 100644 index 0000000..ce273f6 --- /dev/null +++ b/platforms/protobuf.lt @@ -0,0 +1,3 @@ + +type protobuf.Varint = ℕ ~ <PosInt 128 LittleEndian> ~ <Seq~MsbCont <Digit 128> ~ ℤ_128 ~ native.UInt8> ; +type protobuf.String = <Seq Char ~ Unicode> ~ UTF-8 ~ <Seq ~ <LengthPrefix protobuf.Varint> Byte> ; diff --git a/platforms/spapod.lt b/platforms/spapod.lt new file mode 100644 index 0000000..e69de29 diff --git a/platforms/x86.lt b/platforms/x86.lt new file mode 100644 index 0000000..0348efc --- /dev/null +++ b/platforms/x86.lt @@ -0,0 +1,5 @@ + +type x86.UInt64 = ℤ_2/\64 ~ <PosInt 256 LittleEndian> ~ <Seq~<StaticLength 8> <Digit 256> ~ x86.UInt8 >; +type x86.UInt32 = ℤ_2/\32 ~ <PosInt 256 LittleEndian> ~ <Seq~<StaticLength 4> <Digit 256> ~ x86.UInt8 >; +type x86.UInt16 = ℤ_2^16 ~ <PosInt 256 LittleEndian> ~ <Seq~<StaticLength 2> <Digit 256> ~ x86.UInt8 >; +type x86.UInt8 = ℤ_256 ~ <Posint 2 BigEndian> ~ <Seq~<StaticLength 8> <Digit 2> ~ Bit>;