~tim/scheme-vm

ref: e3ea9b9b3ff5b87f50cb7990ccdc5004a35caddc scheme-vm/spec/parser_spec.rb -rw-r--r-- 996 bytes
e3ea9b9bTim Morgan Refactor import bindings 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
43
require_relative './spec_helper'

describe Parser do
  describe '#parse' do
    subject do
      described_class.new(<<-END)
        ; comment
        'foo
        '(1 2)
        '()
        ,foo
        ,(foo bar) #; (baz) #;6
        #| this is a
           multi-line comment |#
        (print |space in identifier|)
        (if (< 1 2) #;(2 3)
            x ; another comment
            (foo (bar (baz "this is a string"))))
      END
    end

    it 'parses s-expressions' do
      expect(subject.parse).to eq([
        ['quote', 'foo'],
        ['quote', ['1', '2']],
        ['quote', []],
        ['unquote', 'foo'],
        ['unquote', ['foo', 'bar']],
        ['print', 'space in identifier'],
        ['if', ['<', '1', '2'],
               'x',
               ['foo', ['bar', ['baz', '"this is a string"']]]]
      ])
    end

    it 'parses touching parens' do
      expect(described_class.new('(foo)(bar)').parse).to eq([
        ['foo'],
        ['bar']
      ])
    end
  end
end