Class: Oozby
- Inherits:
-
Object
- Object
- Oozby
- Defined in:
- lib/oozby/base.rb,
lib/oozby/version.rb
Overview
Oozby class loads up files and evaluates them to a syntax tree, and renders to openscad source code
Defined Under Namespace
Modules: Geometry Classes: Element, Environment, Preprocessor, Render
Constant Summary collapse
- Version =
'0.4.4'
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#filter_errors ⇒ Object
Returns the value of attribute filter_errors.
Class Method Summary collapse
Instance Method Summary collapse
- #abstract_tree ⇒ Object
-
#initialize ⇒ Oozby
constructor
A new instance of Oozby.
-
#parse(code, filename: 'eval') ⇒ Object
parse oozby code in to a syntax tree.
-
#parse_file(filename) ⇒ Object
parse a file containing oozby code in to a syntax tree.
-
#render ⇒ Object
render the last parsed oozby code in to openscad source code.
Constructor Details
#initialize ⇒ Oozby
Returns a new instance of Oozby.
7 8 9 10 11 |
# File 'lib/oozby/base.rb', line 7 def initialize @code_tree = [] @filter_errors = false @debug = false end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
5 6 7 |
# File 'lib/oozby/base.rb', line 5 def debug @debug end |
#filter_errors ⇒ Object
Returns the value of attribute filter_errors.
5 6 7 |
# File 'lib/oozby/base.rb', line 5 def filter_errors @filter_errors end |
Class Method Details
Instance Method Details
#abstract_tree ⇒ Object
58 59 60 |
# File 'lib/oozby/base.rb', line 58 def abstract_tree @code_tree end |
#parse(code, filename: 'eval') ⇒ Object
parse oozby code in to a syntax tree
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/oozby/base.rb', line 14 def parse code, filename: 'eval' env = Oozby::Environment.new(ooz: self) if File.exists? filename current_dir = Dir.pwd Dir.chdir File.dirname(filename) end # rescue block to filter out junk oozby library stuff from backtraces begin compiled = eval("lambda {; #{code}\n }", nil, filename) env._execute_oozby(&compiled) rescue StandardError, NoMethodError => err backtrace = $!.backtrace #backtrace = backtrace.select { |item| !item.include? __dir__ } unless backtrace.first.include? __dir__ if @filter_errors # and backtrace.index { |i| i.include? ".oozby:" } < 3 execute_oozby_idx = backtrace.index { |i| i.include? "in `_execute_oozby'" } backtrace = backtrace[0...execute_oozby_idx] if execute_oozby_idx backtrace.delete_if do |item| filename = item.split(':').first filename = File.realpath(filename) filename.start_with? __dir__ end end raise $!, $!., backtrace end @code_tree = env._abstract_tree ensure Dir.chdir current_dir if current_dir end |
#parse_file(filename) ⇒ Object
parse a file containing oozby code in to a syntax tree
48 49 50 |
# File 'lib/oozby/base.rb', line 48 def parse_file filename parse File.read(filename), filename: filename end |