浏览代码

Add function to start parse servers in parser/__init__.py

tags/v1.0^2
Benjamin Attal 10 年前
父节点
当前提交
c9520fd4e3
共有 1 个文件被更改,包括 29 次插入2 次删除
  1. +29
    -2
      bitshift/parser/__init__.py

+ 29
- 2
bitshift/parser/__init__.py 查看文件

@@ -2,13 +2,24 @@ import json
import sys
import socket
import struct
import subprocess

from os import path
from pygments import lexers as pgl, util

from ..languages import LANGS
from .python import parse_py

_all__ = ["parse"]
_all__ = ["parse", "start_parse_servers"]

PARSER_COMMANDS = [
('Java', ['mvn', '-f',
path.join(path.dirname(__file__), "../../parsers/java/pom.xml"),
'exec:java', '-Dexec.args="%d"']),
('Ruby', ['rake', '-f',
path.join(path.dirname(__file__), "../../parsers/ruby/Rakefile"),
"'start_server[%d]'"])
]

class UnsupportedFileError(Exception):
pass
@@ -72,6 +83,22 @@ def _recv_data(server_socket):
server_socket.close()
return ''.join(total_data)

def start_parse_servers():
"""
Starts all the parse servers for languages besides python.

:rtype: list
"""

procs = []

for (lang, cmd) in PARSER_COMMANDS:
procs.append(
subprocess.Popen(' '.join(cmd) % (5001 + LANGS.index(lang)),
shell=True))

return procs

def parse(codelet):
"""
Dispatches the codelet to the correct parser based on its language.
@@ -87,7 +114,7 @@ def parse(codelet):
lang = _lang(codelet)
source = codelet.code
codelet.language = lang
server_socket_number = 5000 + lang
server_socket_number = 5001 + lang

if lang == LANGS.index('Python'):
parse_py(codelet)


正在加载...
取消
保存