module Python::Syntax
Constants
- And
- Apply
- AssignAttr
- AssignIdentifier
- AttrRef
- BinaryOp
- ClassDef
- Conditional
- Def
- Expression
- LiteralObject
- Not
- Or
- PyBoolizeError
Exceptions possibly occurring when evaluating
- PyCallError
- PyNameError
- RefIdentifier
- Return
- StatementList
- UnaryOp
Public Class Methods
define_element_type(base, *attrs, &eval_proc)
click to toggle source
# File lib/python/syntax.rb, line 48 def self.define_element_type(base, *attrs, &eval_proc) cls = Class.new(base) cls.send(:define_method, :attrs) { attrs } cls.send(:define_method, :eval_proc) { eval_proc } cls.send(:attr_reader, *attrs.flatten) return cls end
draw_syntax_tree(val, depth=0)
click to toggle source
# File lib/python/syntax.rb, line 56 def self.draw_syntax_tree(val, depth=0) case val when Statement puts (" " * depth) + "Node<#{val.class.name}>:" val.attrs.flatten.each do |attrname| puts (" " * (depth + 1)) + "#{attrname}:" draw_syntax_tree(val.instance_variable_get("@#{attrname}".to_sym), depth + 2) end when Array val.each_with_index do |v, i| puts (" " * (depth + 1)) + "[#{i}]" draw_syntax_tree(v, depth + 2) end else puts (" " * (depth + 1)) + val.to_s end end
exp(*attrs, &eval)
click to toggle source
# File lib/python/syntax.rb, line 44 def self.exp(*attrs, &eval) define_element_type(Expression, *attrs, &eval) end
pytrue?(object)
click to toggle source
# File lib/python/syntax.rb, line 79 def self.pytrue?(object) boolized = object.call_special_method("__bool__") if boolized == Builtins::True return true elsif boolized == Builtins::False return false else raise PyBoolizeError.new end end
stmt(*attrs, &eval)
click to toggle source
# File lib/python/syntax.rb, line 40 def self.stmt(*attrs, &eval) define_element_type(Statement, *attrs, &eval) end