How to use the edgedb.lang.common.lang.javascript.ast function in edgedb

To help you get started, we’ve selected a few edgedb 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 edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / jsparser2.py View on Github external
self.must_match('(')
                param = self.parse_ID()
                self.must_match(')', '{')
                # same as function, need to clear the labels
                self.labels = []
                func = self.parse_block_guts()
                return jsast.SetPropertyNode(name=prop, param=param, functionbody=func)
            else:
                # kinda hacky, but generates the right error message
                # we KNOW by this point that ':' isn't there (tried matching it earlier)
                # so forcing that match will complain appropriately
                self.must_match(':')
        else:
            self.must_match(':')
            val = self.parse_assignment_expression()
            return jsast.SimplePropertyNode(name=prop, value=val)
github edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / js.py View on Github external
def reduce_GetProperty(self, *kids):
        "%reduce ID PropertyName LPAREN RPAREN LCBRACKET FunctionBody RCBRACKET"
        if kids[0].val == 'get':
            self.val = jsast.GetPropertyNode(name=kids[1].val, functionbody=kids[5].val)
        else:
            raise SyntaxError("'get' expected")
github edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / js.py View on Github external
def reduce_For_with_declaration(self, *kids):
        "%reduce FOR LPAREN VAR VariableDeclarationList SEMICOLON ExpressionListOPT SEMICOLON ExpressionListOPT RPAREN EndStatement"
        declarations = jsast.VarDeclarationNode(vars=kids[3].val)
        if declarations.countIN() > 0:
            raise SyntaxError("unexpected 'in'")
        else:
            self.val = jsast.ForNode(part1=declarations, part2=kids[5].val, part3=kids[7].val, statement=kids[9].val);
github edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / jsparser2.py View on Github external
tryblock = self.parse_block_guts()
        catchid = catchblock = finallyblock = None
        if self.tentative_match('catch'):
            self.must_match('(')
            catchid = self.parse_ID().name
            self.must_match(')', '{')
            catchblock = self.parse_block_guts()
        # depending on presence of catch block, finally block may or may not be optional
        if not catchid:
            self.must_match('finally', '{')
            finallyblock = self.parse_block_guts()
        else:
            if self.tentative_match('finally'):
                self.must_match('{')
                finallyblock = self.parse_block_guts()
        return jsast.TryNode(tryblock=tryblock, catchid=catchid, catchblock=catchblock, finallyblock=finallyblock)
github edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / js.py View on Github external
def reduce_LHSExpression_AssignmentOp_AssignmentExpression(self, *kids):
        "%reduce LHSExpressionLEFTMOD AssignmentOp AssignmentExpressionRIGHTMOD"
        self.val = jsast.AssignmentExpressionNode(left=kids[0].val, op=kids[1].val, right=kids[2].val)
github edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / jsparser2.py View on Github external
var_list.append(jsast.VarInitNode(name=varname.name, value=self.parse_assignment_expression()))
            else:
                var_list.append(jsast.VarInitNode(name=varname.name, value=None))
            if self.tentative_match(','):
                continue
            elif self.tentative_match(';', consume=statement):
                break
            elif self.tentative_match('in', consume=statement):
                # this can only happen in 'noin' mode
                break
            else:
                raise UnexpectedToken(self.token)
        if statement:
            return jsast.StatementNode(statement=jsast.VarDeclarationNode(vars=var_list))
        else:
            return jsast.VarDeclarationNode(vars=var_list)
github edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / js.py View on Github external
def reduce_RETURN_ExpressionList_SEMICOLON(self, *kids):
        "%reduce RETURN ExpressionList SEMICOLON"
        self.val = jsast.ReturnNode(expression=kids[1].val)
github edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / js.py View on Github external
def reduce_ID_ASSIGN_AssignmentExpression(self, *kids):
        "%reduce ID ASSIGN AssignmentExpressionMETAMOD"
        self.val = jsast.VarInitNode(name=kids[0].val, value=kids[2].val)
github edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / jsparser2.py View on Github external
def parse_property_name(self):
        # get the property name
        id = self.token.type
        if self.token.type == 'NUMBER':
            prop = jsast.NumericLiteralNode(value=self.token.string)
            self.get_next_token()
        elif self.token.type == 'STRING':
            prop = jsast.StringLiteralNode(value=self.token.string)
            self.get_next_token()
        else:
            id = 'ID'
            prop = self.parse_ID(allowkeyword=True)
        return (prop, id)
github edgedb / edgedb / edgedb / lang / common / lang / javascript / parser / js.py View on Github external
def reduce_DEFAULT_COLON_StatementList(self, *kids):
        "%reduce DEFAULT COLON StatementList"
        self.val = jsast.DefaultNode(statements=kids[2].val)