|
|
@@ -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) |
|
|
|