Browse Source

Update docstrings and parser dispatching in parser init file.

tags/v1.0^2
Benjamin Attal 10 years ago
parent
commit
d8b234f462
3 changed files with 12 additions and 23 deletions
  1. +12
    -23
      bitshift/parser/__init__.py
  2. +0
    -0
     
  3. +0
    -0
     

+ 12
- 23
bitshift/parser/__init__.py View File

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


_all__ = ["parse"] _all__ = ["parse"]


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


def parse(codelet, pid): 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 codelet: The codelet object to parsed.
:param pid: The id of the current python process. :param pid: The id of the current python process.


:type code: Codelet :type code: Codelet
:param pid: str. :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) 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
View File


+ 0
- 0
View File


Loading…
Cancel
Save