Expand description
Python parser for Rúnar contracts (.runar.py).
Parses Python-style contract definitions using a hand-written tokenizer with INDENT/DEDENT tokens and recursive descent parser. Produces the same AST as the TypeScript parser.
§Expected format
from runar import SmartContract, Addr, Sig, PubKey, public, assert_, hash160, check_sig
class P2PKH(SmartContract):
pub_key_hash: Addr
def __init__(self, pub_key_hash: Addr):
super().__init__(pub_key_hash)
self.pub_key_hash = pub_key_hash
@public
def unlock(self, sig: Sig, pub_key: PubKey):
assert_(hash160(pub_key) == self.pub_key_hash)
assert_(check_sig(sig, pub_key))Key mappings:
class Foo(SmartContract):-> contract@publicdecorator -> Visibility::Publicself.prop-> PropertyAccess (likethis.prop)assert_(expr)orassert expr-> assert(expr)//integer division -> Div in AST (OP_DIV)and/or/not-> And/Or/Not operators==/!=-> StrictEq/StrictNeReadonly[T]-> readonly propertyfor i in range(n):-> ForStatement- snake_case identifiers -> camelCase in AST
Functions§
- parse_
python - Parse a Python-format Rúnar contract source.