public override object VisitFunctionExpression(FunctionExpressionContext context) { var r = (new Result()); r.text += Visit(context.parameterClauseIn()) + " => " + BlockLeft + Wrap; this.add_current_set(); this.add_func_stack(); r.text += ProcessFunctionSupport(context.functionSupportStatement()); this.delete_current_set(); r.text += BlockRight + Wrap; if (get_func_async()) { r.text = " async " + r.text; } this.delete_func_stack(); r.data = "var"; return(r); }
private void ParseNode(IParseTree node) { if (node is SourceElementsContext) { SourceElementsContext elementsContext = node as SourceElementsContext; SourceElementContext[] srcElements = elementsContext.sourceElement(); foreach (SourceElementContext srcElement in srcElements) { StatementContext statementContext = srcElement.statement(); VariableStatementContext varStatementContext = statementContext.variableStatement(); FunctionDeclarationContext functionContext = statementContext.functionDeclaration(); ImportStatementContext importContext = statementContext.importStatement(); ExportStatementContext exportContext = statementContext.exportStatement(); if (varStatementContext != null) { VariableDeclarationListContext variableListContex = varStatementContext.variableDeclarationList(); if (variableListContex != null) { var variables = variableListContex.children; foreach (var variable in variables) { if (variable is VariableDeclarationContext) { VariableDeclarationContext declarationContext = variable as VariableDeclarationContext; string name = declarationContext.assignable().GetText(); ObjectLiteralExpressionContext[] exps = declarationContext.GetRuleContexts <ObjectLiteralExpressionContext>(); if (exps == null || exps.Length == 0) { this.WriteKeyValue("Field", name); } else { this.WriteKeyValue("Class", name); this.WriteBeginBrace(); foreach (ObjectLiteralExpressionContext exp in exps) { ObjectLiteralContext literalContext = exp.objectLiteral(); PropertyAssignmentContext[] properties = literalContext.propertyAssignment(); foreach (PropertyAssignmentContext property in properties) { PropertyNameContext propertyNameContext = property.GetRuleContext <PropertyNameContext>(0); FunctionExpressionContext funcExpContext = property.GetRuleContext <FunctionExpressionContext>(0); bool isFunction = funcExpContext != null; string propertyName = propertyNameContext.identifierName().GetText(); this.WriteKeyValue(isFunction ? "Function" : "Property", propertyName); } } this.WriteEndBrace(); } } } } } else if (functionContext != null) { string name = functionContext.Identifier().GetText(); this.WriteKeyValue("Function", name); } else if (importContext != null) { ImportFromBlockContext fromContext = importContext.importFromBlock(); ModuleItemsContext[] moduleItems = fromContext.GetRuleContexts <ModuleItemsContext>(); foreach (ModuleItemsContext module in moduleItems) { AliasNameContext[] aliasNames = module.aliasName(); foreach (AliasNameContext aliasName in aliasNames) { string name = aliasName.identifierName().LastOrDefault().GetText(); this.WriteKeyValue("Import", name); } } } else if (exportContext != null) { DeclarationContext[] declarations = exportContext.GetRuleContexts <DeclarationContext>(); ExportFromBlockContext[] exportBlocks = exportContext.GetRuleContexts <ExportFromBlockContext>(); foreach (DeclarationContext declaration in declarations) { FunctionDeclarationContext funcContext = declaration.functionDeclaration(); if (funcContext != null) { string name = funcContext.Identifier().GetText(); this.WriteKeyValue("Export", name); } } foreach (ExportFromBlockContext exportBlock in exportBlocks) { ModuleItemsContext[] moduleItems = exportBlock.GetRuleContexts <ModuleItemsContext>(); foreach (ModuleItemsContext module in moduleItems) { AliasNameContext[] aliasNames = module.aliasName(); foreach (AliasNameContext aliasName in aliasNames) { IdentifierNameContext[] identifierNames = aliasName.identifierName(); string name = identifierNames.LastOrDefault().Identifier().GetText(); this.WriteKeyValue("Export", name); } } } } } } }
private ExprContext expr(int _p) { ParserRuleContext _parentctx = Context; int _parentState = State; ExprContext _localctx = new ExprContext(Context, _parentState); ExprContext _prevctx = _localctx; int _startState = 0; EnterRecursionRule(_localctx, 0, RULE_expr, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 23; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 0, Context)) { case 1: { _localctx = new IfExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 11; ifexpr(); } break; case 2: { _localctx = new FunctionExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 12; function(); } break; case 3: { _localctx = new LiteralExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 13; literal(); } break; case 4: { _localctx = new FieldExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 14; field(); } break; case 5: { _localctx = new NotExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 15; Match(T__0); State = 16; expr(9); } break; case 6: { _localctx = new NegateExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 17; Match(T__1); State = 18; expr(8); } break; case 7: { _localctx = new BracketedExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 19; Match(T__2); State = 20; expr(0); State = 21; Match(T__3); } break; } Context.Stop = TokenStream.LT(-1); State = 45; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context); while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER) { if (_alt == 1) { if (ParseListeners != null) { TriggerExitRuleEvent(); } _prevctx = _localctx; { State = 43; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 1, Context)) { case 1: { _localctx = new MulDivExpressionContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 25; if (!(Precpred(Context, 6))) { throw new FailedPredicateException(this, "Precpred(Context, 6)"); } State = 26; _la = TokenStream.LA(1); if (!(_la == T__4 || _la == T__5)) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 27; expr(7); } break; case 2: { _localctx = new AddSubExpressionContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 28; if (!(Precpred(Context, 5))) { throw new FailedPredicateException(this, "Precpred(Context, 5)"); } State = 29; _la = TokenStream.LA(1); if (!(_la == T__1 || _la == T__6)) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 30; expr(6); } break; case 3: { _localctx = new ComparisonExpressionContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 31; if (!(Precpred(Context, 4))) { throw new FailedPredicateException(this, "Precpred(Context, 4)"); } State = 32; _la = TokenStream.LA(1); if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__7) | (1L << T__8) | (1L << T__9) | (1L << T__10))) != 0))) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 33; expr(5); } break; case 4: { _localctx = new EqualityExpressionContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 34; if (!(Precpred(Context, 3))) { throw new FailedPredicateException(this, "Precpred(Context, 3)"); } State = 35; _la = TokenStream.LA(1); if (!(_la == T__11 || _la == T__12)) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 36; expr(4); } break; case 5: { _localctx = new AndExpressionContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 37; if (!(Precpred(Context, 2))) { throw new FailedPredicateException(this, "Precpred(Context, 2)"); } State = 38; Match(T__13); State = 39; expr(3); } break; case 6: { _localctx = new OrExpressionContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 40; if (!(Precpred(Context, 1))) { throw new FailedPredicateException(this, "Precpred(Context, 1)"); } State = 41; Match(T__14); State = 42; expr(2); } break; } } } State = 47; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream, 2, Context); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return(_localctx); }