UPLC data parsing support by CBOR notation (#37)
* Implement constant data parsing support New notation: (con data #0000) Where #0000 is the CBOR hex representation of a PlutusDatum * Add pretty printing support for data * Format
This commit is contained in:
parent
db5695a1c4
commit
739f38beac
|
@ -6,6 +6,7 @@ use crate::{
|
|||
};
|
||||
|
||||
use interner::Interner;
|
||||
use pallas_primitives::{alonzo::PlutusData, Fragment};
|
||||
use peg::{error::ParseError, str::LineCol};
|
||||
|
||||
mod interner;
|
||||
|
@ -53,6 +54,7 @@ peg::parser! {
|
|||
/ constant_string()
|
||||
/ constant_unit()
|
||||
/ constant_bool()
|
||||
/ constant_data()
|
||||
) _* ")" {
|
||||
Term::Constant(con)
|
||||
}
|
||||
|
@ -110,6 +112,15 @@ peg::parser! {
|
|||
rule number() -> isize
|
||||
= n:$("-"* ['0'..='9']+) {? n.parse().or(Err("isize")) }
|
||||
|
||||
rule constant_data() -> Constant
|
||||
= "data" _+ "#" i:ident()* {
|
||||
Constant::Data(
|
||||
PlutusData::decode_fragment(
|
||||
hex::decode(String::from_iter(i)).unwrap().as_slice()
|
||||
).unwrap()
|
||||
)
|
||||
}
|
||||
|
||||
rule name() -> Name
|
||||
= text:ident() { Name { text, unique: 0.into() } }
|
||||
|
||||
|
|
Loading…
Reference in New Issue