add ReprTree::from_str() to simplify creation of initial representation nodes

This commit is contained in:
Michael Sippel 2024-08-06 16:29:28 +02:00
parent 6e2b82585e
commit 8d637a6f32
Signed by: senvas
GPG key ID: F96CF119C34B64A6
4 changed files with 47 additions and 16 deletions
examples/tty-04-posint/src

View file

@ -66,16 +66,22 @@ async fn main() {
nested_tty::setup_edittree_hook(&ctx);
/* Create a Representation-Tree of type ``
* with a specific representation-path (big-endian hexadecimal string)
*/
let mut rt_int = ReprTree::new_arc( Context::parse(&ctx, "") );
let mut rt_int = nested::repr_tree::ReprTree::from_str(
/* TYPE */
Context::parse(&ctx, "
~ <PosInt 16 BigEndian>
~ <Seq <Digit 16>>
~ <List <Digit 16>>
~ <List Char>
~ <Vec Char>
"),
/* Add a specific Representation-Path (big-endian hexadecimal)
*/
rt_int.insert_leaf(
Context::parse(&ctx, "<PosInt 16 BigEndian>~<Seq <Digit 16>>~<List <Digit 16>>~<List Char>~<Vec Char>"),
nested::repr_tree::ReprLeaf::from_vec_buffer(
VecBuffer::with_data(vec![ 'c', 'f', 'f' ]
)));
/* VALUE */
"cff"
);
/* initially copy values from Vec to EditTree...
*/