Explorar el Código

Fix data length sent to client from ruby server. Pad with extra bytes.

tags/v1.0^2
Benjamin Attal hace 10 años
padre
commit
d8048a74f0
Se han modificado 2 ficheros con 31 adiciones y 14 borrados
  1. +13
    -2
      parsers/ruby/lib/parse_server.rb
  2. +18
    -12
      parsers/ruby/lib/parser.rb

+ 13
- 2
parsers/ruby/lib/parse_server.rb Ver fichero

@@ -1,6 +1,17 @@
require 'socket'
require File.expand_path('../parser.rb', __FILE__)

def pack_int(i)
bytes = []; mask = 255

while bytes.length < 4
bytes.unshift (i & mask)
i = i >> 8
end

return bytes.pack('cccc')
end

server = TCPServer.new 5003

loop do
@@ -11,8 +22,8 @@ loop do
size = (client.readline).to_i
p = Bitshift::Parser.new client.read(size)
# Get the parsed result
symbols = p.parse.to_s
client.puts [symbols.length].pack('c')
symbols = p.parse
client.puts pack_int(symbols.length)
client.puts symbols
ensure
# Close the socket


+ 18
- 12
parsers/ruby/lib/parser.rb Ver fichero

@@ -12,9 +12,9 @@ module Bitshift
parser = RubyParser.new
tree = parser.parse(@source)
offset = tree.line - 1
processor = NodeVisitor.new offset
processor.process tree
return processor.symbols
processor = NodeVisitor.new offset, tree
processor.process(tree)
return processor.to_s
end
end

@@ -22,16 +22,16 @@ module Bitshift
attr_accessor :symbols
attr_accessor :offset

def initialize(offset)
def initialize(offset, tree)
super()
@require_empty = false
@offset = offset

module_hash = Hash.new {|hash, key| hash[key] = Hash.new}
class_hash = module_hash.clone
function_hash = Hash.new {|hash, key| hash[key] = { calls: [] } }
var_hash = Hash.new {|hash, key| hash[key] = [] }

@require_empty = false
@offset = offset
@symbols = {
modules: module_hash,
classes: class_hash,
@@ -68,7 +68,7 @@ module Bitshift
end

def process_module(exp)
pos = block_position exp
pos = block_position(exp)
exp.shift
name = exp.shift
symbols[:modules][name] = pos
@@ -77,7 +77,7 @@ module Bitshift
end

def process_class(exp)
pos = block_position exp
pos = block_position(exp)
exp.shift
name = exp.shift
symbols[:classes][name] = pos
@@ -86,7 +86,7 @@ module Bitshift
end

def process_defn(exp)
pos = block_position exp
pos = block_position(exp)
exp.shift
name = exp.shift
symbols[:functions][name][:declaration] = pos
@@ -95,7 +95,7 @@ module Bitshift
end

def process_call(exp)
pos = statement_position exp
pos = statement_position(exp)
exp.shift
exp.shift
name = exp.shift
@@ -105,7 +105,7 @@ module Bitshift
end

def process_iasgn(exp)
pos = statement_position exp
pos = statement_position(exp)
exp.shift
name = exp.shift
symbols[:vars][name] << pos
@@ -114,12 +114,18 @@ module Bitshift
end

def process_lasgn(exp)
pos = statement_position exp
pos = statement_position(exp)
exp.shift
name = exp.shift
symbols[:vars][name] << pos
exp.each_sexp {|s| process(s)}
return exp.clear
end

def to_s
str = symbols.to_s
str = str.gsub(/:(\w*)=>/, '"\1":')
return str
end
end
end

Cargando…
Cancelar
Guardar