private bool TryAdaptVariableDeclarator(JassMapScriptAdapterContext context, bool isGlobalVariable, IVariableDeclaratorSyntax declarator, [NotNullWhen(true)] out IVariableDeclaratorSyntax?adaptedDeclarator)
        {
            if (!context.KnownTypes.ContainsKey(declarator.Type.TypeName.Name))
            {
                context.Diagnostics.Add($"Unknown variable type '{declarator.Type}'.");
            }

            if (isGlobalVariable)
            {
                if (!context.KnownGlobalVariables.TryAdd(declarator.IdentifierName.Name, declarator.Type.TypeName.Name))
                {
                    context.Diagnostics.Add($"Duplicate global variable '{declarator.IdentifierName}'.");
                }
            }
            else
            {
                if (!context.KnownLocalVariables.TryAdd(declarator.IdentifierName.Name, declarator.Type.TypeName.Name))
                {
                    context.Diagnostics.Add($"Duplicate local variable '{declarator.IdentifierName}'.");
                }
            }

            return(declarator switch
            {
                JassArrayDeclaratorSyntax arrayDeclarator => TryAdaptArrayDeclarator(context, isGlobalVariable, arrayDeclarator, out adaptedDeclarator),
                JassVariableDeclaratorSyntax variableDeclarator => TryAdaptVariableDeclarator(context, isGlobalVariable, variableDeclarator, out adaptedDeclarator),

                _ => TryAdaptDummy(context, declarator, out adaptedDeclarator),
            });
 public VariableDeclarationSyntax Transpile(IVariableDeclaratorSyntax declarator)
 {
     return(declarator switch
     {
         JassArrayDeclaratorSyntax arrayDeclarator => Transpile(arrayDeclarator),
         JassVariableDeclaratorSyntax variableDeclarator => Transpile(variableDeclarator),
     });
        public LuaVariableDeclaratorSyntax Transpile(JassVariableDeclaratorSyntax variableDeclarator)
        {
            var expression = variableDeclarator.Value is null
                ? LuaIdentifierLiteralExpressionSyntax.Nil
                : Transpile(variableDeclarator.Value);

            return(new LuaVariableDeclaratorSyntax(Transpile(variableDeclarator.IdentifierName), expression));
        }
        public void Render(JassVariableDeclaratorSyntax variableDeclarator)
        {
            Render(variableDeclarator.Type);
            Write(' ');
            Render(variableDeclarator.IdentifierName);

            if (variableDeclarator.Value is not null)
            {
                Write(' ');
                Render(variableDeclarator.Value);
            }
        }
        public LuaLocalDeclarationStatementSyntax Transpile(IVariableDeclaratorSyntax declarator, bool isLocalDeclaration)
        {
            RegisterVariableType(declarator, isLocalDeclaration);

            var luaDeclarator = declarator switch
            {
                JassArrayDeclaratorSyntax arrayDeclarator => Transpile(arrayDeclarator),
                JassVariableDeclaratorSyntax variableDeclarator => Transpile(variableDeclarator),
            };

            var declaration = new LuaVariableListDeclarationSyntax();

            luaDeclarator.IsLocalDeclaration = isLocalDeclaration;
            declaration.Variables.Add(luaDeclarator);

            return(new LuaLocalDeclarationStatementSyntax(declaration));
        }