コード例 #1
0
        public override int VisitLine_statement([NotNull] YarnSpinnerParser.Line_statementContext context)
        {
            int lineNumber = context.Start.Line;

            string lineID = Compiler.GetLineID(context.hashtag());

            var hashtagText = GetHashtagTexts(context.hashtag());

            GenerateFormattedText(context.line_formatted_text().children, out var composedString, out var expressionCount);

            string stringID = stringTableManager.RegisterString(
                composedString.ToString(),
                fileName,
                currentNodeName,
                lineID,
                lineNumber,
                hashtagText);

            if (lineID == null)
            {
                var hashtag = new YarnSpinnerParser.HashtagContext(context, 0);
                hashtag.text = new CommonToken(YarnSpinnerLexer.HASHTAG_TEXT, stringID);
                context.AddChild(hashtag);
            }

            return(0);
        }
コード例 #2
0
        public override int VisitLine_statement([NotNull] YarnSpinnerParser.Line_statementContext context)
        {
            int lineNumber = context.Start.Line;

            YarnSpinnerParser.HashtagContext[] hashtags = context.hashtag();
            var lineIDTag = Compiler.GetLineIDTag(hashtags);
            var lineID    = lineIDTag?.text.Text ?? null;

            var hashtagText = GetHashtagTexts(hashtags);

            GenerateFormattedText(context.line_formatted_text().children, out var composedString, out var expressionCount);

            // Does this string table already have a string with this ID?
            if (lineID != null && stringTableManager.ContainsKey(lineID))
            {
                // If so, this is an error.
                ParserRuleContext diagnosticContext;

                diagnosticContext = lineIDTag ?? (ParserRuleContext)context;

                this.diagnostics.Add(new Diagnostic(fileName, diagnosticContext, $"Duplicate line ID {lineID}"));

                return(0);
            }

            string stringID = stringTableManager.RegisterString(
                composedString.ToString(),
                fileName,
                currentNodeName,
                lineID,
                lineNumber,
                hashtagText);

            if (lineID == null)
            {
                var hashtag = new YarnSpinnerParser.HashtagContext(context, 0);
                hashtag.text = new CommonToken(YarnSpinnerLexer.HASHTAG_TEXT, stringID);
                context.AddChild(hashtag);
            }

            return(0);
        }