Esempio n. 1
0
        private bool TryCompileSelectionDialog(MessageScriptParser.SelectionDialogContext context, out SelectionDialog selectionWindow)
        {
            LogContextInfo(context);

            selectionWindow = null;

            //
            // Parse identifier
            //
            string identifier;

            {
                if (!TryGetFatal(context, context.Identifier, "Expected selection window name", out var identifierNode))
                {
                    return(false);
                }

                identifier = identifierNode.Symbol.Text;
            }

            LogInfo(context, $"Compiling selection window: {identifier}");

            //
            // Parse text content
            //
            List <TokenText> options;

            {
                if (!TryGetFatal(context, context.tokenText, "Expected selection window text", out var tagTextContext))
                {
                    return(false);
                }

                if (!TryCompileTokenText(tagTextContext, out options))
                {
                    LogError(tagTextContext, "Failed to compile selection window text");
                    return(false);
                }
            }

            //
            // Create Selection window
            //
            selectionWindow = new SelectionDialog(identifier, options);

            return(true);
        }
        private bool TryCompileSelectionDialog(MessageScriptParser.SelectionDialogContext context, out SelectionDialog selectionWindow)
        {
            LogContextInfo(context);

            selectionWindow = null;

            //
            // Parse identifier
            //
            string identifier;

            {
                if (!TryGetFatal(context, context.Identifier, "Expected selection window name", out var identifierNode))
                {
                    return(false);
                }

                identifier = ParseIdentifier(identifierNode);
            }

            LogInfo(context, $"Compiling selection window: {identifier}");

            //
            // Parse pattern
            //
            SelectionDialogPattern pattern = SelectionDialogPattern.Top;
            {
                if (TryGet(context, context.selectionDialogPattern, out var patternCtx))
                {
                    if (TryGet(patternCtx, patternCtx.SelectionDialogPatternId, out var patternIdNode))
                    {
                        switch (patternIdNode.Symbol.Text)
                        {
                        case "top": pattern = SelectionDialogPattern.Top; break;

                        case "bottom": pattern = SelectionDialogPattern.Bottom; break;

                        default:
                            LogError(patternCtx, $"Unknown selection dialog pattern: {patternIdNode.Symbol.Text}");
                            return(false);
                        }
                    }
                    else if (TryParseShortIntLiteral(context, "Failed to parse selection dialog pattern ID", patternCtx.IntLiteral, out var patternId))
                    {
                        pattern = (SelectionDialogPattern)patternId;
                    }
                    else
                    {
                        LogError(patternCtx, "Invalid selection dialog pattern");
                        return(false);
                    }
                }
            }

            //
            // Parse text content
            //
            List <TokenText> options;

            {
                if (!TryGetFatal(context, context.tokenText, "Expected selection window text", out var tagTextContext))
                {
                    return(false);
                }

                if (!TryCompileTokenText(tagTextContext, out options))
                {
                    LogError(tagTextContext, "Failed to compile selection window text");
                    return(false);
                }
            }

            //
            // Create Selection window
            //
            selectionWindow = new SelectionDialog(identifier, pattern, options);

            return(true);
        }