~tim/scheme-vm

ed6d292c02005337753d09906eb7b07558af2ec1 — Tim Morgan 4 years ago 4d81576
Make parser use Atom instead of plain strings

This breaks the rust tests because the constant VM is unavailable when
the parser is loaded directly from tests. Should be fixable.
4 files changed, 13 insertions(+), 2 deletions(-)

A src/atom.rs
M src/lib.rs
M src/lisp.rustpeg
M test.rb
A src/atom.rs => src/atom.rs +9 -0
@@ 0,0 1,9 @@
use rb;
use rb::{Value, RB_NIL};

pub fn atom(name: &str) -> Value {
    let name_rbstr = rb::str_new(&name.to_string());
    let vm_class = rb::const_get("VM", &RB_NIL);
    let atom_class = rb::const_get("Atom", &vm_class);
    rb::class_new_instance(&atom_class, vec![name_rbstr])
}

M src/lib.rs => src/lib.rs +1 -0
@@ 4,6 4,7 @@ extern crate ruby_sys;
#[macro_use] mod rb;
use rb::{CallbackPtr, Value, RB_NIL};

mod atom;
mod tests;

mod lisp {

M src/lisp.rustpeg => src/lisp.rustpeg +2 -1
@@ 1,5 1,6 @@
use rb;
use rb::Value;
use atom::atom;

whitespace
	= [ \t\n]+


@@ 11,7 12,7 @@ string -> Option<Value>
	= "\"" s:$(escape / [^"])* "\"" { Some(rb::str_new(&s.to_string())) }

atom -> Option<Value>
	= n:$([^\(\) \t\n\[\]\{\}"]+) { Some(rb::str_new(&n.to_string())) }
	= n:$([^\(\) \t\n\[\]\{\}"]+) { Some(atom(&n)) }

sexp -> Option<Value>
	= n:(quoted_sexp / simple_sexp) { Some(n) }

M test.rb => test.rb +1 -1
@@ 1,6 1,6 @@
require 'fiddle'
require 'benchmark'
require_relative './parser'
require_relative './vm'

class Parser
  class ParseError < StandardError