~tim/scheme-vm

ref: c5110102ce2df2d78a0c87f293edf20f5a3984e7 scheme-vm/parser.rb -rw-r--r-- 956 bytes
c5110102Tim Morgan Add more char functions 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
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
42
require 'fiddle'
require_relative 'vm/atom'
require 'pathname'

class Parser
  class ParseError < StandardError
    attr_reader :filename, :line, :column, :expected

    def initialize(filename, line, column, expected)
      @filename = filename
      @line = line
      @column = column
      @expected = expected
    end

    def message
      "expected one of: #{expected.sort.inspect}"
    end
  end

  def initialize(code = nil, filename: nil)
    @code = code
    @filename = filename || ''
  end

  def parse
    parse_native
  end
end

LIB_PATHS = %w[
  target/release/libscheme_vm.so
  target/debug/libscheme_vm.so
  target/release/libscheme_vm.dylib
  target/debug/libscheme_vm.dylib
]

root = Pathname.new(File.expand_path('../', __FILE__))
library_path = LIB_PATHS.detect { |path| root.join(path).exist? }
library = Fiddle::dlopen(library_path)
init_parser = Fiddle::Function.new(library['init_parser'], [], Fiddle::TYPE_VOID)
init_parser.call