Example #1
0
def getGrammar():
    with open("grammar.tmp", "ab+") as file:
        file.seek(0)
        contents = file.read()
        file.seek(0)
        if not contents:
            # Regenerate grammar file:
            grammar = plyplus.Grammar(grammars.open('python.g'))
            dill.dump(grammar, file)
        else:
            # Access grammar file
            grammar = dill.load(file)
    return grammar
Example #2
0
 def setUp(self):
     with grammars.open('config.g') as g:
         self.g = Grammar(g)
Example #3
0
 def setUp(self):
     with grammars.open('python.g') as g:
         self.g = Grammar(g)
Example #4
0
 def setUp(self):
     with grammars.open('config.g') as g:
         self.g = Grammar(g)
Example #5
0
 def setUp(self):
     with grammars.open('python.g') as g:
         self.g = Grammar(g)
Example #6
0
    bin_expr = _bin_operator
    # arg = _assignment
    assign = _assignment
    if_expr = _if


def _read(n, *args):
    kwargs = {'encoding': 'iso-8859-1'}
    with open(os.path.join(CUR_PATH, n), *args, **kwargs) as f:
        return f.read()


if os.name == 'nt':
    if 'PyPy' in sys.version:
        PYTHON_LIB = os.path.join(sys.prefix, 'lib-python', sys.winver)
    else:
        PYTHON_LIB = os.path.join(sys.prefix, 'Lib')
else:
    PYTHON_LIB = [
        x for x in sys.path if x.endswith('%s.%s' % sys.version_info[:2])
    ][0]

# print(os.getcwd())
with grammars.open(os.getcwd() + '/grammar.g') as g:
    g = Grammar(g)

p = RParser()
tree = g.parse(_read('sample.r'))

tree.to_png_with_pydot('list_parser_tree.png')