Module: BEL::LibBEL

Extended by:
LibraryResolver
Defined in:
lib/bel/libbel.rb,
lib/bel/libbel/bel_token.rb,
lib/bel/libbel/node_test.rb,
lib/bel/libbel/bel_token_list.rb,
lib/bel/libbel/node_traversal.rb,
lib/bel/libbel/bel_ast_structs.rb,
lib/bel/libbel/library_resolver.rb,
lib/bel/libbel/library_load_error.rb,
lib/bel/libbel/node_transformation.rb,
lib/bel/libbel/platform_support_error.rb

Defined Under Namespace

Modules: LibraryResolver, NodeTest, NodeTransformation, NodeTraversal Classes: AstNodeTypeUnion, BelAst, BelAstNode, BelAstNodeToken, BelAstNodeTypeInfo, BelAstNodeValue, BelToken, BelTokenList, LibraryLoadError, PlatformSupportError

Constant Summary collapse

FFI =

Constant holding the FFI module for this ruby engine.

BEL::LibBEL::load_ffi

Constants included from LibraryResolver

LibraryResolver::EXT_BASE_PATH

Class Method Summary collapse

Methods included from LibraryResolver

resolve_library

Class Method Details

.copy_ast(bel_ast) ⇒ Object



141
142
143
144
145
146
# File 'lib/bel/libbel.rb', line 141

def self.copy_ast(bel_ast)
  copy_root = self.copy_ast_node(bel_ast.root)
  new_ast   = BEL::LibBEL::BelAst.new(BEL::LibBEL::bel_new_ast())
  new_ast.root = copy_root
  new_ast
end

.copy_ast_node(bel_ast_node) ⇒ Object



148
149
150
# File 'lib/bel/libbel.rb', line 148

def self.copy_ast_node(bel_ast_node)
  BEL::LibBEL::BelAstNode.new(BEL::LibBEL::bel_copy_ast_node(bel_ast_node))
end

.find_ffiObject

Determine FFI constant for this ruby engine.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bel/libbel.rb', line 17

def find_ffi
  if rubinius?
    # Use ffi gem instead of rubinius-bundled FFI
    # Rubinius 2.5.2 does not seem to support FFI::ManagedStruct
    require "ffi"
    ::FFI
  else # mri, jruby, etc
    require "ffi"
    ::FFI
  end
end

.load_ffiObject

Extend with the correct ffi implementation.



31
32
33
34
35
# File 'lib/bel/libbel.rb', line 31

def load_ffi
  ffi_module = BEL::LibBEL::find_ffi
  extend ffi_module::Library
  ffi_module
end

.load_libBELObject

Loads the libbel shared library.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bel/libbel.rb', line 39

def load_libBEL
  ffi_module = find_ffi
  extend ffi_module::Library

  lib_path = resolve_library('libbel')

  begin
    ffi_lib lib_path
    true
  rescue LoadError => err
    raise LibraryLoadError.new('libbel', err)
    false
  end
end

.parse_statement(bel_string) ⇒ Object



129
130
131
# File 'lib/bel/libbel.rb', line 129

def self.parse_statement(bel_string)
  BEL::LibBEL::BelAst.new(BEL::LibBEL::bel_parse_statement(bel_string))
end

.parse_term(bel_string) ⇒ Object



133
134
135
# File 'lib/bel/libbel.rb', line 133

def self.parse_term(bel_string)
  BEL::LibBEL::BelAst.new(BEL::LibBEL::bel_parse_term(bel_string))
end


152
153
154
# File 'lib/bel/libbel.rb', line 152

def self.print_ast(bel_ast)
  BEL::LibBEL::bel_print_ast(bel_ast)
end


156
157
158
# File 'lib/bel/libbel.rb', line 156

def self.print_token(token)
  self.bel_print_token(token.pointer)
end


160
161
162
# File 'lib/bel/libbel.rb', line 160

def self.print_token_list(list)
  self.bel_print_token_list(list.pointer)
end

.rubinius?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/bel/libbel.rb', line 11

def rubinius?
  defined?(RUBY_ENGINE) && ("rbx" == RUBY_ENGINE)
end

.tokenize_term(bel_string) ⇒ Object



137
138
139
# File 'lib/bel/libbel.rb', line 137

def self.tokenize_term(bel_string)
  BEL::LibBEL::BelTokenList.new(self.bel_tokenize_term(bel_string))
end