// have finished with the header // so about to enter the node body and all its statements // do the initial setup required before compiling that body statements // eg emit a new startlabel public override void ExitHeader(YarnSpinnerParser.HeaderContext context) { var headerKey = context.header_key.Text; // Use the header value if provided, else fall back to the // empty string. This means that a header like "foo: \n" will // be stored as 'foo', '', consistent with how it was typed. // That is, it's not null, because a header was provided, but // it was written as an empty line. var headerValue = context.header_value?.Text ?? ""; if (headerKey.Equals("title", StringComparison.InvariantCulture)) { // Set the name of the node CurrentNode.Name = headerValue; // Throw an exception if this node name contains illegal // characters if (invalidNodeTitleNameRegex.IsMatch(CurrentNode.Name)) { throw new ParseException($"The node '{CurrentNode.Name}' contains illegal characters in its title."); } } if (headerKey.Equals("tags", StringComparison.InvariantCulture)) { // Split the list of tags by spaces, and use that var tags = headerValue.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); CurrentNode.Tags.Add(tags); if (CurrentNode.Tags.Contains("rawText")) { // This is a raw text node. Flag it as such for future compilation. RawTextNode = true; } } }
/// <summary> /// Visit a parse tree produced by <see cref="YarnSpinnerParser.header"/>. /// <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 VisitHeader([NotNull] YarnSpinnerParser.HeaderContext context) { return(VisitChildren(context)); }
/// <summary> /// Enter a parse tree produced by <see cref="YarnSpinnerParser.header"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void EnterHeader([NotNull] YarnSpinnerParser.HeaderContext context) { }