class Object

Public Instance Methods

_get_next_7_bits_as_byte(integer, base = 128) { |byte| ... } click to toggle source
# File lib/types.rb, line 629
def _get_next_7_bits_as_byte(integer, base = 128)
  # Base is the initial value of the byte before
  # before |'ing it with 7bits from the integer
  groups_of_7 = (integer.size * 8) / 7 + (integer.size % 7 == 0 ? 0 : 1)
  0.upto(groups_of_7 - 1) do |group_number|
    byte = base
    0.upto(7).each do |bit_number|
      byte = byte | (integer[group_number * 7 + bit_number] << bit_number)
    end
    yield(byte)
  end
end
lexer(path) click to toggle source
# File lib/lexer.rb, line 3
def lexer(path)
  tokens = []
  line_num = 0
  File.open(path).each do |line|
    while line.size > 0
      if /^#/.match(line)
        break
      elsif /^\n/.match(line)
        break
      elsif /^ /.match(line)
        line = line[1..line.size]
      elsif /^</.match(line)
        line = line[1..line.size]
        tokens << :less_than
      elsif /^>/.match(line)
        line = line[1..line.size]
        tokens << :greater_than
        next
      elsif /^{/.match(line)
        line = line[1..line.size]
        tokens << :open_block
      elsif /^=/.match(line)
        line = line[1..line.size]
        tokens << :equal
      elsif /^}/.match(line)
        line = line[1..line.size]
        tokens << :close_block
      elsif /^\[/.match(line)
        line = line[1..line.size]
        tokens << :open_brace
      elsif /^\]/.match(line)
        line = line[1..line.size]
        tokens << :close_brace
      elsif /^\(/.match(line)
        line = line[1..line.size]
        tokens << :open_paren
      elsif /^\)/.match(line)
        line = line[1..line.size]
        tokens << :close_paren
      elsif /^\|/.match(line)
        line = line[1..line.size]
        tokens << :bar
      elsif match = /^([0-9]+)/.match(line)
        tokens << match[0].to_i
        line = line[(match[0].size)..line.size]
        next
      elsif match = /^[a-z,A-Z,_][_,a-z,A-Z,0-9]+/.match(line)
        tokens << match[0]
        line = line[(match[0].size)..line.size]
      elsif /:/.match(line)
        tokens << :colon
        line = line[1..line.size]
      else
        raise SchemaParsingException.new("Unable to lex line #{line_num} near #{line.inspect}")
      end
    end
    line_num += 1
  end
  return tokens
end
parser(tokens, definitions = {}) click to toggle source
# File lib/parser.rb, line 146
def parser(tokens, definitions = {})
  parser = Parser.new
  parser.parse(tokens)
  return parser.definitions
end