Esempio n. 1
0
 def _fill_interpolation(self, n):
     text = n.format_string.value
     parser = Parser()
     format_string, expressions = self._extract_interpolations(text)
     exprs = [parser.parse(expr) for expr in expressions]
     n.format_string.value = format_string
     n.expressions.exprs.extend(exprs)
Esempio n. 2
0
 def _load_file(self, path):
     with open(path, 'r') as f:
         source = f.read()
         print source
         parser = Parser()
         transformer = AstTransformer()
         ast = parser.parse(source)
         transformer.visit(ast)
         return ast
Esempio n. 3
0
import sys

from setlx2py.setlx_parser import Parser
from setlx2py.setlx_ast_transformer import AstTransformer
from setlx2py.setlx_codegen import Codegen

HEADER = """
from setlx2py.builtin.setlx_functions import *
from setlx2py.builtin.setlx_internals import *
from setlx2py.builtin.setlx_set import SetlxSet
from setlx2py.builtin.setlx_list import SetlxList
from setlx2py.builtin.setlx_string import SetlxString

"""

parser = Parser()
transformer = AstTransformer()
generator = Codegen()


def error_msg(source, compiled=None, e=None):
    msg = 'Could not run stuff:\n'
    msg += 'Source:\n' + source + '\n'

    if compiled:
        msg += 'Compiled:\n' + compiled
    if e:
        msg += 'Reason:\n'
        msg += e.__class__.__name__ + '\n'
        msg += str(e) + '\n'
        msg += 'Line: ' + str(get_exception_line(e))
Esempio n. 4
0
    
    argparser.add_argument("-o", required=True, help="output file", metavar="FILE",
                        type=lambda x: is_writable(argparser,x))
    
    argparser.add_argument("-v", required=False, help="verbosity", action="store_true")
    return argparser

if  __name__ == '__main__':    
    args = build_argparser().parse_args()
    
    source = ""
    
    with open(args.i, 'r') as input_file:
        source = input_file.read()    
    
    parser = Parser()
    ast = parser.parse(source)
    
    if args.v: log_ast(ast)
        
    # Load files
    # We just search for calls to the 'load' function
        
    to_replace = {} # Stores which Call nodes to replace with AST from loaded file
    for i, stmt in enumerate(ast.stmts):
        if isinstance(stmt, Call) and stmt.name.name == 'load':
            path = stmt.args.arguments[0].value
            to_replace[i] = path
    
    # Second loop as you do not want to alter a list you are iterating on            
    for i, path in to_replace.items():        
Esempio n. 5
0
# License: Apache v2
#------------------------------------------------------------------------------

from __future__ import unicode_literals

import os

from nose.tools import eq_, with_setup, nottest

from setlx2py.setlx_parser import Parser

##
## Test housekeeping
##

parser = Parser(yacc_optimize=False)


def is_parsable(path):
    with open(path, 'r') as f:
        try:
            s = f.read()
        except Exception as e:
            print(path)
            raise

    try:
        parser.parse(s)
        return True
    except SyntaxError as e:
        return False