Sha256: 98aace46cf4702bf8d61476be5342fb8f376baa38858e8716a5b52fec449206e

Contents?: true

Size: 949 Bytes

Versions: 1

Compression:

Stored size: 949 Bytes

Contents

require_relative '../livetext'
require_relative 'string'

make_exception(:MismatchedQuotes, "Error: mismatched quotes")
make_exception(:NilValue,         "Error: nil value")
make_exception(:NullString,       "Error: null string")
make_exception(:ExpectedString,   "Error: expected a string")

class Livetext::ParseMisc < StringParser

  def initialize(str)
    super
  end

  def strip_quotes
    raise NullString if @line.empty?
    start, stop = @line[0], @line[-1]
    return @line unless %['"].include?(start)
    raise MismatchedQuotes if start != stop
    @line[1..-2]
  end

  def self.parse_vars(lines, prefix: nil)
    lines.map! {|line| line.sub(/# .*/, "").strip }  # strip comments
    pairs = []
    lines.each do |line|
      next if line.strip.empty?
      var, value = line.split(" ", 2)
      val = FormatLine.var_func_parse(value)
      var = prefix + "." + var if prefix
      pairs << [var, value]
    end
    pairs
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
livetext-0.9.13 lib/parser/general.rb