Expand description
Ruby parser for Rúnar contracts (.runar.rb).
Parses Ruby-style contract definitions using a hand-written tokenizer and recursive descent parser. Produces the same AST as the TypeScript and Python parsers.
§Expected format
require 'runar'
class P2PKH < Runar::SmartContract
prop :pub_key_hash, Addr
def initialize(pub_key_hash)
super(pub_key_hash)
@pub_key_hash = pub_key_hash
end
runar_public sig: Sig, pub_key: PubKey
def unlock(sig, pub_key)
assert hash160(pub_key) == @pub_key_hash
assert check_sig(sig, pub_key)
end
endKey mappings:
class Foo < Runar::SmartContract-> contractrunar_public-> Visibility::Public for the next methodparams-> pending param types for a private methodprop :name, Type-> PropertyNode@ivar-> PropertyAccess (likethis.prop)assert expr-> assert(expr)**-> pow() calland/or/not-> And/Or/Not operators==/!=-> StrictEq/StrictNefor i in start...end-> ForStatement (exclusive)for i in start..end-> ForStatement (inclusive)unless-> if with negated condition- snake_case identifiers -> camelCase in AST
Functions§
- parse_
ruby - Parse a Ruby-format Rúnar contract source.