Class: Gly::Parser

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

Overview

parses gly source

Constant Summary collapse

SYLLABLE_SEP =
'--'

Instance Method Summary collapse

Instance Method Details

#parse(io) ⇒ Object



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
# File 'lib/gly/parser.rb', line 6

def parse(io)
  @doc = Document.new
  @score = ParsedScore.new

  if io.respond_to? :path
    @doc.path = io.path
  end

  io.each do |line|
    line = strip_comments(line)

    if empty? line
      next
    elsif new_score? line
      push_score
      @score = ParsedScore.new
    elsif header_start? line
      push_score
      @score = @doc.header
    elsif header_line? line
      parse_header line
    elsif lyrics_line? line
      parse_lyrics line
    else
      parse_music line
    end
  end

  push_score

  return @doc
end