/// <summary> /// Exit a parse tree produced by <see cref="iroParser.sys_set"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitSys_set([NotNull] iroParser.Sys_setContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="iroParser.sys_set"/>. /// <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 VisitSys_set([NotNull] iroParser.Sys_setContext context) { return(VisitChildren(context)); }
/// <summary> /// Visits a top level system set and defines it. /// </summary> public override IroVariable VisitSys_set([NotNull] iroParser.Sys_setContext context) { //Parse the set on its own. var set = new IroSet(); //Add individual attributes to the set, checking for uniqueness. foreach (var statement in context.statement()) { string name; IroVariable value; //Attribute? if (statement.attribute() != null) { //Get name, value. var attribute = statement.attribute(); name = attribute.IDENTIFIER().GetText(); value = VisitAttribute(attribute); } //Set? else if (statement.set() != null) { //Get name, value. var childSet = statement.set(); //Is it an anonymous set? if (childSet.IDENTIFIER() == null) { //Automatic naming. name = "set_" + ShortId.Generate(RAND_ID_LEN); } else { //Named, just set it normally. name = childSet.IDENTIFIER().GetText(); } value = ((IroAttribute)VisitSet(childSet)).Value; } //Include? else if (statement.include() != null) { if (statement.include().IDENTIFIER()[0].GetText() != "include") { Error.Fatal(statement.include(), "Invalid inline set statement."); return(null); } //Add it to the list. name = "include_" + ShortId.Generate(RAND_ID_LEN); value = new IroInclude(statement.include().IDENTIFIER()[1].GetText()); } //Unrecognized statement in set. else { Error.Fatal(context, "Unrecognized statement in set, please open an issue on the repository with this source grammar."); return(null); } //Check if the name already exists. if (set.ContainsKey(name)) { Error.Fatal(context, "Set already contains a variable with name '" + name + "'."); return(null); } //Safe to add. set.Add(name, value); } //Return the created set. return(new IroAttribute(context.IDENTIFIER().GetText(), set)); }