Sha256: 30cde2b3c631e606a2e3a73f6b925762699c1c5ae8914e32867000dbcc8e38e2

Contents?: true

Size: 730 Bytes

Versions: 4

Compression:

Stored size: 730 Bytes

Contents

module Ting
  class Reader
    include Procable

    def initialize(conv, tone)
      @conv = conv.to_s
      @tone = Tones.const_get Ting.camelize(tone.to_s)
    end

    def parse(str)
      Conversions.tokenize(str).map do |token, pos|
        tone, syll = @tone.pop_tone(token)
        tsyll = Conversions.parse(@conv, syll)
        ini, fin = tsyll.initial, tsyll.final
        unless tone && fin && ini
          raise ParseError.new(token, pos),"Illegal syllable <#{token}> in input <#{str}> at position #{pos}."
        end
        tsyll + tone
      end
    rescue Object => e
      raise ParseError.new(str, 0, e), "Parsing of #{str.inspect} failed : #{e}"
    end

    alias :<< :parse
    alias :call :parse
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ting-0.12.0 lib/ting/reader.rb
ting-0.11.0 lib/ting/reader.rb
ting-0.10.0 lib/ting/reader.rb
ting-0.9.0 lib/ting/reader.rb