Class: Trxl::RequireDirective
- Inherits:
-
Treetop::Runtime::SyntaxNode
- Object
- Treetop::Runtime::SyntaxNode
- Trxl::RequireDirective
- Defined in:
- lib/trxl/trxl.rb
Instance Method Summary collapse
- #eval(env = Environment.new) ⇒ Object
- #identifier(env = Environment.new) ⇒ Object
-
#load_library(env = Environment.new) ⇒ Object
override this in subclasses.
- #optimize_stdlib_access? ⇒ Boolean
Instance Method Details
#eval(env = Environment.new) ⇒ Object
274 275 276 277 278 279 280 281 |
# File 'lib/trxl/trxl.rb', line 274 def eval(env = Environment.new) library = ((l = load_library(env))[-1..-1]) == ';' ? "#{l} ENV" : "#{l}; ENV" unless env.library_included?(identifier(env)) env.merge!(Calculator.new.eval(library, env).local) env.add_library(identifier(env)) end env end |
#identifier(env = Environment.new) ⇒ Object
283 284 285 |
# File 'lib/trxl/trxl.rb', line 283 def identifier(env = Environment.new) @identifier ||= string_literal.eval(env) end |
#load_library(env = Environment.new) ⇒ Object
override this in subclasses
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/trxl/trxl.rb', line 288 def load_library(env = Environment.new) path = identifier(env).split('/') if path[0] == ('stdlib') if optimize_stdlib_access? if path.size == 2 const = path[1].upcase if Trxl::StdLib.constants.include?(const) Calculator.stdlib(const) else raise MissingLibraryException, "Failed to load '#{identifier}'" end else Calculator.stdlib end else raise NotImplementedException, "Only optimized access is supported" end else raise NotImplementedException, "Only require 'stdlib' is supported" end end |
#optimize_stdlib_access? ⇒ Boolean
310 311 312 |
# File 'lib/trxl/trxl.rb', line 310 def optimize_stdlib_access? true end |