eval with inputs (#56)

This commit is contained in:
Lucas
2022-09-08 18:20:52 -04:00
committed by GitHub
parent 739f38beac
commit 6d6f671f4f
5 changed files with 49 additions and 10 deletions

View File

@@ -39,6 +39,21 @@ where
term: applied_term,
}
}
/// We use this to apply the validator to Datum,
/// then redeemer, then ScriptContext. If datum is
/// even necessary (i.e. minting policy).
pub fn apply_term(&self, term: &Term<T>) -> Self {
let applied_term = Term::Apply {
function: Rc::new(self.term.clone()),
argument: Rc::new(term.clone()),
};
Program {
version: self.version,
term: applied_term,
}
}
}
impl<'a, T> Display for Program<T>

View File

@@ -25,6 +25,19 @@ pub fn program(src: &str) -> Result<Program<Name>, ParseError<LineCol>> {
Ok(program)
}
pub fn term(src: &str) -> Result<Term<Name>, ParseError<LineCol>> {
// initialize the string interner to get unique name
let mut interner = Interner::new();
// run the generated parser
let mut term = uplc::term(src)?;
// assign proper unique ids in place
interner.term(&mut term);
Ok(term)
}
peg::parser! {
grammar uplc() for str {
pub rule program() -> Program<Name>
@@ -37,7 +50,7 @@ peg::parser! {
(major as usize, minor as usize, patch as usize)
}
rule term() -> Term<Name>
pub rule term() -> Term<Name>
= constant()
/ builtin()
/ var()