Procházet zdrojové kódy

Update docstrings and parser dispatching in parser init file.

tags/v1.0^2
Benjamin Attal před 10 roky
rodič
revize
d8b234f462
3 změnil soubory, kde provedl 12 přidání a 23 odebrání
  1. +12
    -23
      bitshift/parser/__init__.py
  2. +0
    -0
     
  3. +0
    -0
     

+ 12
- 23
bitshift/parser/__init__.py Zobrazit soubor

@@ -1,7 +1,9 @@
import os, ast
import pygments.lexers as pgl
from ..languages import LANGS
from .python import parse_py
from .c import parse_c
from .java import parse_java
from .ruby import parse_ruby

_all__ = ["parse"]

@@ -24,39 +26,26 @@ def _lang(codelet):

def parse(codelet, pid):
"""
Sends codelet code to the Java parsing process via a named pipe. Reads the
resulting symbols from the pipe and updates the codelet.
Dispatches the codelet to the correct parser based on its language.

:param codelet: The codelet object to parsed.
:param pid: The id of the current python process.

:type code: Codelet
:param pid: str.

.. todo::
Identify languages using pygments and change the write file based on
that.
"""

codelet.language = _lang(codelet)
lang = _lang(codelet)

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

else:
write_f = "../../tmp/%d_parser.proc" % codelet.language

with open(write_f, 'a') as wf:
wf.write('pid:' + str(pid) + '\n')
wf.write('body:\n' + codelet.code)

read_f = '../../tmp/%s_py.data' % str(pid)
data = ''
elif lang == LANGS.index("C"):
parse_c(codelet)

while data == '':
with open(read_f) as rf:
data = rf.read()
elif lang == LANGS.index("Java"):
parse_java(codelet)

os.remove(read_f)
codelet.symbols = ast.literal_eval(data.split(',')[1])
elif lang == LANGS.index("Ruby"):
parse_ruby(codelet)


+ 0
- 0
Zobrazit soubor


+ 0
- 0
Zobrazit soubor


Načítá se…
Zrušit
Uložit