eval with inputs (#56)
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user