Class: Sparse

Inherits:
Object
  • Object
show all
Defined in:
lib/sparse/sparse.rb

Instance Method Summary collapse

Instance Method Details

#parse(text) ⇒ Object



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
# File 'lib/sparse/sparse.rb', line 2

def parse(text)
  @scanner = StringScanner.new(text)
  @line = 1
  @column = 1

  result = []
  until @scanner.eos?
    case
      when whitespace || comment
        # do nothing
      when open_parenthesis
        result << strip
      when quote
        result << :quote
        unless open_parenthesis
          blowup 'Expected list'
        end
        @scanner.unscan
      when syntax_quote
        result << :syntax_quote
        unless open_parenthesis
          blowup 'Expected list'
        end
        @scanner.unscan

      else
        blowup
    end

  end

  result

end