/// <summary> /// Exit a parse tree produced by <see cref="iroParser.block"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitBlock([NotNull] iroParser.BlockContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="iroParser.block"/>. /// <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 VisitBlock([NotNull] iroParser.BlockContext context) { return(VisitChildren(context)); }
/// <summary> /// Visits a top level statement containing an attribute definition or system set. /// </summary> public override IroVariable VisitBlock([NotNull] iroParser.BlockContext context) { //Prepare locals. IroAttribute thisAttrib = null; //System set? if (context.sys_set() != null) { //Define all the sets. var set = context.sys_set(); var setAttrib = VisitSys_set(set); //Is it an attribute? if (!(setAttrib is IroAttribute)) { Error.Fatal(context, "Defined system set did not return an attribute. Please log an issue on the repository page with the source grammar."); return(null); } thisAttrib = (IroAttribute)setAttrib; } //Is it a statement? else if (context.statement() != null) { //Statement. var stat = context.statement(); var toAdd = VisitStatement(stat); //If anything comes back up, try to add it. if (toAdd != null) { //Make sure it's an attribute so the name is there too. if (!(toAdd is IroAttribute)) { Error.Warn(stat, "Non-attribute variable reached the top of the stack, skipping."); return(null); } //Attempt to add. thisAttrib = (IroAttribute)toAdd; } } //Unknown operation. else { Error.Fatal(context, "Unknown block statement type, please submit an issue on the repository with your source grammar."); } //If a variable has been generated, try to add it to scope. if (thisAttrib != null) { if (IroScope.VariableExists(thisAttrib.Name)) { Error.Fatal(context, "Variable already exists with the name '" + thisAttrib.Name + "'."); return(null); } IroScope.AddVariable(thisAttrib.Name, thisAttrib.Value); } return(null); }