Module: Wcl
- Defined in:
- lib/wcl.rb,
lib/wcl/types.rb,
lib/wcl/convert.rb,
lib/wcl/version.rb,
lib/wcl/callback.rb,
lib/wcl/document.rb,
lib/wcl/wasm_runtime.rb
Defined Under Namespace
Modules: Callback, Convert Classes: BlockRef, Decorator, Diagnostic, Document, ValueError, WasmRuntime
Constant Summary collapse
- VERSION =
"0.9.0.alpha1"
Class Method Summary collapse
-
.parse(source, root_dir: nil, allow_imports: nil, max_import_depth: nil, max_macro_depth: nil, max_loop_depth: nil, max_iterations: nil, functions: nil, variables: nil) ⇒ Object
Parse a WCL source string and return a Document.
-
.parse_file(path, **kwargs) ⇒ Object
Parse a WCL file and return a Document.
Class Method Details
.parse(source, root_dir: nil, allow_imports: nil, max_import_depth: nil, max_macro_depth: nil, max_loop_depth: nil, max_iterations: nil, functions: nil, variables: nil) ⇒ Object
Parse a WCL source string and return a Document.
13 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 |
# File 'lib/wcl.rb', line 13 def parse(source, root_dir: nil, allow_imports: nil, max_import_depth: nil, max_macro_depth: nil, max_loop_depth: nil, max_iterations: nil, functions: nil, variables: nil) = {} ["rootDir"] = root_dir.to_s if root_dir ["allowImports"] = allow_imports unless allow_imports.nil? ["maxImportDepth"] = max_import_depth if max_import_depth ["maxMacroDepth"] = max_macro_depth if max_macro_depth ["maxLoopDepth"] = max_loop_depth if max_loop_depth ["maxIterations"] = max_iterations if max_iterations ["variables"] = variables if variables = .empty? ? nil : JSON.generate() runtime = WasmRuntime.get if functions && !functions.empty? Callback.set_functions(functions) begin func_names_json = JSON.generate(functions.keys) handle = runtime.parse_with_functions(source, , func_names_json) ensure Callback.clear_functions end else handle = runtime.parse(source, ) end Document.new(handle) end |
.parse_file(path, **kwargs) ⇒ Object
Parse a WCL file and return a Document.
44 45 46 47 48 49 50 51 52 |
# File 'lib/wcl.rb', line 44 def parse_file(path, **kwargs) path = path.to_s source = File.read(path) rescue Errno::ENOENT, Errno::EACCES => e raise IOError, "#{path}: #{e.}" else kwargs[:root_dir] ||= File.dirname(File.(path)) parse(source, **kwargs) end |