/// <summary> /// The visit subroutine for a function definition. /// Entering this means that we've begun parsing a new function. /// </summary> public override VisitorResult VisitF_defi([NotNull] HaskellmmParser.F_defiContext context) { int eqIndex = -1; for (int i = 0; i < context.ChildCount; i++) { if (context.GetChild(i).GetText() == "=") { eqIndex = i; break; } } if (eqIndex == -1) { throw new VisitException(context.Start.Line, context.Start.Column, "'=' expected in function definition"); } string functionName = context.GetChild(0).GetText(); currentFunction = new Function(functionName); for (int i = 1; i < eqIndex; i++) { currentFunction.AddParameter(new Parameter(context.GetChild(i).GetText())); } if (Functions.Find(f => f.Name == functionName) != null) { throw new VisitException(context.Start.Line, context.Start.Column, "Multiple definitions found for function " + functionName); } Functions.Add(currentFunction); currentNode = null; return(base.VisitF_defi(context)); }
/// <summary> /// Visit a parse tree produced by <see cref="HaskellmmParser.f_defi"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitF_defi([NotNull] HaskellmmParser.F_defiContext context) { return(VisitChildren(context)); }
/// <summary> /// Exit a parse tree produced by <see cref="HaskellmmParser.f_defi"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitF_defi([NotNull] HaskellmmParser.F_defiContext context) { }