Ejemplo n.º 1
0
        // a regular ol' line of text
        public override int VisitLine_statement(YarnSpinnerParser.Line_statementContext context)
        {
            // TODO: add support for line conditions:
            //
            // Mae: here's a line <<if true>>
            //
            // is identical to
            //
            // <<if true>> Mae: here's a line <<endif>>

            // Evaluate the inline expressions and push the results onto the
            // stack.
            var expressionCount = this.GenerateCodeForExpressionsInFormattedText(context.line_formatted_text().children);

            // Get the lineID for this string from the hashtags
            var lineIDTag = Compiler.GetLineIDTag(context.hashtag());

            if (lineIDTag == null)
            {
                throw new InvalidOperationException("Internal error: line should have an implicit or explicit line ID tag, but none was found");
            }

            var lineID = lineIDTag.text.Text;

            this.compiler.Emit(OpCode.RunLine, context.Start, new Operand(lineID), new Operand(expressionCount));

            return(0);
        }
Ejemplo n.º 2
0
        // a regular ol' line of text
        public override int VisitLine_statement(YarnSpinnerParser.Line_statementContext context)
        {
            // TODO: add support for line conditions:
            //
            // Mae: here's a line <<if true>>
            //
            // is identical to
            //
            // <<if true>>
            // Mae: here's a line
            // <<endif>>

            // Convert the formatted string into a string with
            // placeholders, and evaluate the inline expressions and push
            // the results onto the stack.
            GenerateFormattedText(context.line_formatted_text().children, out var composedString, out var expressionCount);

            // Get the lineID for this string from the hashtags if it has one; otherwise, a new one will be created
            string lineID = compiler.GetLineID(context.hashtag());

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

            int lineNumber = context.Start.Line;

            string stringID = compiler.RegisterString(
                composedString.ToString(),
                compiler.CurrentNode.Name,
                lineID,
                lineNumber,
                hashtagText);

            compiler.Emit(OpCode.RunLine, new Operand(stringID), new Operand(expressionCount));

            return(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);
        }
Ejemplo n.º 4
0
        // a regular ol' line of text
        public override int VisitLine_statement(YarnSpinnerParser.Line_statementContext context)
        {
            // TODO: add support for line conditions:
            //
            // Mae: here's a line <<if true>>
            //
            // is identical to
            //
            // <<if true>> Mae: here's a line <<endif>>

            // Evaluate the inline expressions and push the results onto
            // the stack.
            var expressionCount = GenerateCodeForExpressionsInFormattedText(context.line_formatted_text().children);

            // Get the lineID for this string from the hashtags
            string lineID = Compiler.GetLineID(context.hashtag());

            if (lineID == null)
            {
                throw new ParseException("No line ID specified");
            }

            compiler.Emit(OpCode.RunLine, new Operand(lineID), new Operand(expressionCount));

            return(0);
        }
Ejemplo n.º 5
0
        // a regular ol' line of text
        public override int VisitLine_statement(YarnSpinnerParser.Line_statementContext context)
        {
            // grabbing the line of text and stripping off any "'s if they had them
            string lineText = context.text().GetText().Trim('"');

            // getting the lineID from the hashtags if it has one
            string lineID = compiler.GetLineID(context.hashtag_block());

            // technically this only gets the line the statement started on
            int lineNumber = context.Start.Line;

            string stringID = compiler.RegisterString(lineText, compiler.currentNode.Name, lineID, lineNumber);

            compiler.Emit(OpCode.RunLine, new Operand(stringID));

            return(0);
        }
Ejemplo n.º 6
0
        // a regular ol' line of text
        public override int VisitLine_statement(YarnSpinnerParser.Line_statementContext context)
        {
            // grabbing the line of text and stripping off any "'s if they had them
            string lineText = context.text().GetText().Trim('"');

            // getting the lineID from the hashtags if it has one
            string lineID = compiler.GetLineID(context.hashtag_block());

            // technically this only gets the line the statement started on
            int lineNumber = context.Start.Line;

            // TODO: why is this called num?
            string num = compiler.program.RegisterString(lineText, compiler.currentNode.name, lineID, lineNumber, true);

            compiler.Emit(ByteCode.RunLine, num);

            return(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);
        }
Ejemplo n.º 8
0
            /// <inheritdoc/>
            public override void ExitLine_statement([NotNull] YarnSpinnerParser.Line_statementContext context)
            {
                // We're looking at a complete line statement.

                // First, figure out if this line statement already has a line
                // tag. Start by taking the hashtags...
                var hashtags = context.hashtag();

                // Get the text for all of these hashtags...
                var texts = StringTableGeneratorVisitor.GetHashtagTexts(hashtags);

                // And then look for a line ID hashtag.
                foreach (var text in texts)
                {
                    if (text.StartsWith("line:"))
                    {
                        // This line contains a line code. Nothing left to do.
                        return;
                    }
                }

                // Find the index of the first token on the default channel to
                // the left of the newline.
                var previousTokenIndex = IndexOfPreviousTokenOnChannel(
                    TokenStream,
                    context.NEWLINE().Symbol.TokenIndex,
                    YarnSpinnerLexer.DefaultTokenChannel
                    );

                // Did we find one?
                if (previousTokenIndex == -1)
                {
                    // No token was found before this newline. This is an
                    // internal error - there must be at least one symbol
                    // besides the terminating newline.
                    throw new InvalidOperationException($"Internal error: failed to find any tokens before the newline in line statement on line {context.Start.Line}");
                }

                // Get the token at this index. We'll put our tag after it.
                var previousToken = TokenStream.Get(previousTokenIndex);

                // Generate a new, unique line ID.
                string newLineID = Utility.GenerateString(existingStrings);

                // Record that we've used this new line ID, so that we don't
                // accidentally use it twice.
                existingStrings.Add(newLineID);

                // Create a text replacement that inserts a space followed by
                // the line tag at the end of the line.
                var replacement = new Upgrader.TextReplacement()
                {
                    Start           = previousToken.StopIndex + 1,
                    StartLine       = previousToken.Line,
                    OriginalText    = "",
                    ReplacementText = $" #{newLineID} ",
                    Comment         = "Added line tag"
                };

                // Add this replacement to the list.
                this.Replacements.Add(replacement);
            }
 /// <summary>
 /// Visit a parse tree produced by <see cref="YarnSpinnerParser.line_statement"/>.
 /// <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 VisitLine_statement([NotNull] YarnSpinnerParser.Line_statementContext context)
 {
     return(VisitChildren(context));
 }
 /// <summary>
 /// Exit a parse tree produced by <see cref="YarnSpinnerParser.line_statement"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitLine_statement([NotNull] YarnSpinnerParser.Line_statementContext context)
 {
 }