How to use the enaml.core.parsing.base_lexer.syntax_error 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 / parsing / 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 / parsing / 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 / parsing / base_parser.py View on Github external
def _validate_template_inst(self, node, lexer):
        """ Validate a template instantiation.

        This function ensures that the bindings on the instantiation refer
        to declared identifiers on the instantiation.

        """
        names = set()
        if node.identifiers:
            names.update(node.identifiers.names)
        for binding in node.body:
            if binding.name not in names:
                msg = "'%s' is not a valid template id reference"
                syntax_error(msg % binding.name,
                             FakeToken(lexer, binding.lineno))
github nucleic / enaml / enaml / core / parsing / base_parser.py View on Github external
def _validate_arglist_list(self, items, lexer):
        kwnames = set()
        saw_kw = False
        for item in items:
            if isinstance(item, ast.keyword):
                saw_kw = True
                if item.arg in kwnames:
                    msg = 'keyword argument repeated'
                    tok = FakeToken(lexer, item.lineno)
                    syntax_error(msg, tok)
                kwnames.add(item.arg)
            elif saw_kw:
                msg = 'non-keyword arg after keyword arg'
                tok = FakeToken(lexer, item.lineno)
                syntax_error(msg, tok)