How to use the enaml.core.parser.base_parser.FakeToken function in enaml

To help you get started, we’ve selected a few enaml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nucleic / enaml / enaml / core / parser / parser3.py View on Github external
def p_decl_funcdef3(self, p):
        ''' decl_funcdef : NAME NAME parameters RETURNARROW test COLON suite '''
        lineno = p.lineno(1)
        if p[1] != 'func':
            syntax_error('invalid syntax', FakeToken(p.lexer.lexer, lineno))
        funcdef = ast.FunctionDef()
        funcdef.name = p[2]
        funcdef.args = p[3]
        funcdef.returns = p[5]
        funcdef.body = p[7]
        funcdef.decorator_list = []
        funcdef.lineno = lineno
        ast.fix_missing_locations(funcdef)
        self._validate_decl_funcdef(funcdef, p.lexer.lexer)
        decl_funcdef = enaml_ast.FuncDef()
        decl_funcdef.lineno = lineno
        decl_funcdef.funcdef = funcdef
        decl_funcdef.is_override = False
        p[0] = decl_funcdef
github nucleic / enaml / enaml / core / parser / base_parser.py View on Github external
def _validate_template_paramlist(self, paramlist, starparam, lexer):
        keywords = []
        positional = []
        seen_params = set([starparam])
        for param in paramlist:
            if param.name in seen_params:
                msg = "duplicate argument '%s' in template definition"
                syntax_error(msg % param.name, FakeToken(lexer, param.lineno))
            seen_params.add(param.name)
            if isinstance(param, enaml_ast.KeywordParameter):
                keywords.append(param)
            elif keywords:
                msg = "non-default argument follows default argument"
                syntax_error(msg, FakeToken(lexer, param.lineno))
            else:
                positional.append(param)
        return positional, keywords
github nucleic / enaml / enaml / core / parser / base_parser.py View on Github external
def check_id(name, node):
            if name in ident_names:
                msg = "redeclaration of identifier '%s'"
                msg += " (this will be an error in Enaml version 1.0)"
                syntax_warning(msg % name, FakeToken(lexer, node.lineno))
            ident_names.add(name)
github nucleic / enaml / enaml / core / parser / base_parser.py View on Github external
"""
        kwnames = set()
        args = []
        kws = []
        self._validate_arglist_list(items, p.lexer.lexer)
        for arg in items:
            if isinstance(arg, ast.keyword):
                kws.append(arg)
                kwnames.add(arg.arg)
            else:
                args.append(arg)
        for kw in keywords:
            if not isinstance(kw, ast.keyword):
                msg = 'only named arguments may follow *expression'
                tok = FakeToken(p.lexer.lexer, p.lineno(2))
                syntax_error(msg, tok)
            if kw.arg in kwnames:
                msg = 'keyword argument repeated'
                tok = FakeToken(p.lexer.lexer, kw.lineno)
                syntax_error(msg, tok)
            kwnames.add(kw.arg)
        kws.extend(keywords)

        return args, kws
github nucleic / enaml / enaml / core / parser / base_parser.py View on Github external
def p_operator_expr3(self, p):
        ''' operator_expr : DOUBLECOLON suite '''
        lineno = p.lineno(1)

        for item in ast.walk(self.create_module(p[2])):
            if type(item) in self._NOTIFICATION_DISALLOWED:
                msg = '%s not allowed in a notification block'
                msg = msg % self._NOTIFICATION_DISALLOWED[type(item)]
                syntax_error(msg, FakeToken(p.lexer.lexer, item.lineno))

        func_node = ast.FunctionDef()
        func_node.name = 'f'
        func_node.args = self._make_args([])
        func_node.decorator_list = []
        func_node.returns = None
        func_node.body = p[2]
        func_node.lineno = lineno

        mod = self.create_module([func_node])
        ast.fix_missing_locations(mod)

        python = enaml_ast.PythonModule(ast=mod, lineno=lineno)
        p[0] = enaml_ast.OperatorExpr(operator=p[1], value=python,
                                      lineno=lineno)
github nucleic / enaml / enaml / core / parser / base_parser.py View on Github external
def p_arglist11(self, p):
        ''' arglist : STAR test COMMA argument '''
        keyword = p[4]
        if isinstance(keyword, ast.keyword):
            p[0] = Arguments(keywords=[keyword], starargs=p[2])
        else:
            msg = 'only named arguments may follow *expression'
            tok = FakeToken(p.lexer.lexer, p.lineno(1))
            syntax_error(msg, tok)
github nucleic / enaml / enaml / core / parser / base_parser.py View on Github external
def p_template_simple_item1(self, p):
        ''' template_simple_item : storage_alias_const_expr '''
        if not isinstance(p[1], enaml_ast.ConstExpr):
            syntax_error('invalid syntax', FakeToken(p.lexer.lexer, p[1].lineno))
        p[0] = p[1]
github nucleic / enaml / enaml / core / parser / base_parser.py View on Github external
def p_expr_stmt3(self, p):
        ''' expr_stmt : testlist_star_expr equal_list '''
        all_items = [p[1]] + p[2]
        targets = list(map(ast_for_testlist, all_items))
        value = targets.pop()
        for item in targets:
            if type(item) == ast.Yield:
                msg = "assignment to yield expression not possible"
                syntax_error(msg, FakeToken(p.lexer.lexer, item.lineno))
            self.set_context(item, Store, p)
        assg = ast.Assign()
        assg.targets = targets
        assg.value = value
        p[0] = assg
github nucleic / enaml / enaml / core / parser / base_parser.py View on Github external
def _validate_decl_funcdef(self, funcdef, lexer):
        walker = ast.walk(funcdef)
        next(walker)  # discard toplevel funcdef
        for item in walker:
            if type(item) in self._DECL_FUNCDEF_DISALLOWED:
                msg = '%s not allowed in a declarative function block'
                msg = msg % self._DECL_FUNCDEF_DISALLOWED[type(item)]
                syntax_error(msg, FakeToken(lexer, item.lineno))
github nucleic / enaml / enaml / core / parser / base_parser.py View on Github external
def p_expr_stmt2(self, p):
        ''' expr_stmt : testlist_star_expr augassign testlist
                      | testlist_star_expr augassign yield_expr '''
        op, lineno = p[2]
        lhs = ast_for_testlist(p[1])
        rhs = ast_for_testlist(p[3])
        self.set_context(lhs, Store, p)
        if type(lhs) not in self.aug_assign_allowed:
            msg = 'illegal expression for augmented assignment'
            syntax_error(msg, FakeToken(p.lexer.lexer, lineno))
        aug = ast.AugAssign()
        aug.target = lhs
        aug.value = rhs
        aug.op = op
        p[0] = aug