Created
October 25, 2021 02:03
-
-
Save IceDragon200/683a01895f89eba72716bf6ad39c6d45 to your computer and use it in GitHub Desktop.
KDL Data Model example (from Kuddle)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is an example document to demonstrate the data model result | |
document date=(date)"2021-10-24" { | |
numbers { | |
integer 12 | |
bin 0b1000_1000 | |
oct 0o7453 | |
hex 0xDEADBEEF | |
} | |
strings { | |
dquote "Hello, World" | |
raw r"This is a raw string\n" | |
} | |
booleans { | |
y true | |
n false | |
} | |
@null null | |
properties a="Hello" b=12 | |
// This is a test of the attributes with mixed arguments and properties | |
mixed_attributes "Argument 1" prop=1 "Argument 2" | |
} | |
footer { | |
(Author)author { | |
username "IceDragon200" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
%{ | |
name: "document", | |
annotations: [], | |
attributes: [ | |
{ | |
%{ | |
type: :id, | |
format: :plain, | |
annotations: [], | |
value: "date", | |
}, | |
%{ | |
type: :string, | |
format: :plain, | |
annotations: ["date"], | |
value: "2021-10-24", | |
}, | |
}, | |
], | |
children: [ | |
%{ | |
name: "numbers", | |
annotations: [], | |
attributes: [], | |
children: [ | |
%{ | |
name: "integer", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :integer, | |
format: :plain, | |
annotations: [], | |
value: 12, | |
}, | |
], | |
children: nil, | |
}, | |
%{ | |
name: "bin", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :integer, | |
format: :bin, | |
annotations: [], | |
value: 136, | |
}, | |
], | |
children: nil, | |
}, | |
%{ | |
name: "oct", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :integer, | |
format: :oct, | |
annotations: [], | |
value: 3883 | |
} | |
], | |
children: nil, | |
}, | |
%{ | |
name: "hex", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :integer, | |
format: :hex, | |
annotations: [], | |
value: 3735928559 | |
} | |
], | |
children: nil, | |
}, | |
], | |
}, | |
%{ | |
name: "strings", | |
children: [ | |
%{ | |
name: "dquote", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :string, | |
format: :plain, | |
annotations: [], | |
value: "Hello, World", | |
}, | |
], | |
children: nil, | |
}, | |
%{ | |
name: "raw", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :string, | |
format: :raw, | |
annotations: [], | |
value: "This is a raw string\\n", | |
}, | |
], | |
children: nil, | |
}, | |
], | |
}, | |
%{ | |
name: "booleans", | |
annotations: [], | |
attributes: [], | |
children: [ | |
%{ | |
name: "y", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :boolean, | |
format: :plain, | |
annotations: [], | |
value: true, | |
}, | |
], | |
children: nil, | |
}, | |
%{ | |
name: "n", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :boolean, | |
format: :plain, | |
annotations: [], | |
value: false, | |
}, | |
], | |
children: nil, | |
}, | |
], | |
}, | |
%{ | |
name: "@null", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :null, | |
format: :plain, | |
annotations: [], | |
value: nil | |
}, | |
], | |
children: nil | |
}, | |
%{ | |
name: "properties", | |
annotations: [], | |
attributes: [ | |
{ | |
%{ | |
type: :id, | |
format: :plain, | |
annotations: [], | |
value: "a", | |
}, | |
%{ | |
type: :string, | |
format: :plain, | |
annotations: [], | |
value: "Hello", | |
}, | |
}, | |
{ | |
%{ | |
type: :id, | |
format: :plain, | |
annotations: [], | |
value: "b", | |
}, | |
%{ | |
type: :integer, | |
format: :plain, | |
annotations: [], | |
value: 12, | |
}, | |
}, | |
], | |
children: nil | |
}, | |
%{ | |
name: "mixed_attributes", | |
annotations: [], | |
# And this is why kuddle only has an attributes field | |
# and it doesn't split arguments/properties | |
# By using just a list for both cases, it can guarantee the order | |
# of the arguments and properties as they appeared in the original document | |
# this is important when encoding so the attributes don't end up in random positions | |
attributes: [ | |
%{ | |
type: :string, | |
format: :plain, | |
annotations: [], | |
value: "Argument 1", | |
}, | |
{ | |
%{ | |
type: :id, | |
format: :plain, | |
annotations: [], | |
value: "prop", | |
}, | |
%{ | |
type: :integer, | |
format: :plain, | |
annotations: [], | |
value: 1, | |
}, | |
}, | |
%{ | |
type: :string, | |
format: :plain, | |
annotations: [], | |
value: "Argument 2", | |
}, | |
] | |
children: nil, | |
}, | |
], | |
}, | |
%{ | |
name: "footer", | |
annotations: [ | |
"Author", | |
], | |
attributes: [], | |
children: [ | |
%{ | |
name: "username", | |
annotations: [], | |
attributes: [ | |
%{ | |
type: :string, | |
format: :plain, | |
annotations: [], | |
value: "IceDragon200", | |
} | |
] | |
children: nil, | |
} | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment