Ejemplo n.º 1
0
 internal void Render(LuaCodeTemplateExpressionSyntax node)
 {
     foreach (var code in node.Expressions)
     {
         code.Render(this);
     }
 }
Ejemplo n.º 2
0
        private void FillManifestInitConf(LuaInvocationExpressionSyntax invocation)
        {
            LuaTableInitializerExpression confTable = new LuaTableInitializerExpression();

            if (mainEntryPoint_ != null)
            {
                LuaIdentifierNameSyntax methodName = new LuaIdentifierNameSyntax(mainEntryPoint_.Name);
                var methodTypeName = XmlMetaProvider.GetTypeName(mainEntryPoint_.ContainingType, null);
                var quote          = new LuaIdentifierNameSyntax(LuaSyntaxNode.Tokens.Quote);

                LuaCodeTemplateExpressionSyntax codeTemplate = new LuaCodeTemplateExpressionSyntax();
                codeTemplate.Expressions.Add(quote);
                codeTemplate.Expressions.Add(new LuaMemberAccessExpressionSyntax(methodTypeName, methodName));
                codeTemplate.Expressions.Add(quote);

                confTable.Items.Add(new LuaKeyValueTableItemSyntax(new LuaTableLiteralKeySyntax(methodName), codeTemplate));
            }
            if (confTable.Items.Count > 0)
            {
                invocation.AddArgument(confTable);
            }
        }
Ejemplo n.º 3
0
 internal void Render(LuaCodeTemplateExpressionSyntax node)
 {
     WriteNodes(node.Expressions);
 }
Ejemplo n.º 4
0
        private LuaExpressionSyntax BuildCodeTemplateExpression(string codeTemplate, ExpressionSyntax targetExpression, IEnumerable <ExpressionSyntax> arguments, ImmutableArray <ITypeSymbol> typeArguments)
        {
            LuaCodeTemplateExpressionSyntax codeTemplateExpression = new LuaCodeTemplateExpressionSyntax();

            var matchs    = codeTemplateRegex_.Matches(codeTemplate);
            int prevIndex = 0;

            foreach (Match match in matchs)
            {
                if (match.Index > prevIndex)
                {
                    string prevToken = codeTemplate.Substring(prevIndex, match.Index - prevIndex);
                    codeTemplateExpression.Expressions.Add(new LuaIdentifierNameSyntax(prevToken));
                }
                string comma = match.Groups[1].Value;
                string key   = match.Groups[2].Value;
                if (key == "this")
                {
                    AddCodeTemplateExpression(BuildMemberAccessTargetExpression(targetExpression), comma, codeTemplateExpression);
                }
                else if (key == "class")
                {
                    var type = semanticModel_.GetTypeInfo(targetExpression).Type;
                    LuaExpressionSyntax typeName;
                    if (type.TypeKind == TypeKind.Enum)
                    {
                        typeName = GetTypeShortName(type);
                        AddExportEnum(type);
                    }
                    else
                    {
                        typeName = GetTypeName(type);
                    }
                    AddCodeTemplateExpression(typeName, comma, codeTemplateExpression);
                }
                else if (key[0] == '^')
                {
                    int typeIndex;
                    if (int.TryParse(key.Substring(1), out typeIndex))
                    {
                        var typeArgument = typeArguments.GetOrDefault(typeIndex);
                        if (typeArgument != null)
                        {
                            LuaExpressionSyntax typeName;
                            if (typeArgument.TypeKind == TypeKind.Enum && codeTemplate.StartsWith("System.Enum.TryParse"))
                            {
                                typeName = GetTypeShortName(typeArgument);
                                AddExportEnum(typeArgument);
                            }
                            else
                            {
                                typeName = GetTypeName(typeArgument);
                            }
                            AddCodeTemplateExpression(typeName, comma, codeTemplateExpression);
                        }
                    }
                }
                else if (key[0] == '*')
                {
                    int paramsIndex;
                    if (int.TryParse(key.Substring(1), out paramsIndex))
                    {
                        LuaCodeTemplateExpressionSyntax paramsExpression = new LuaCodeTemplateExpressionSyntax();
                        foreach (var argument in arguments.Skip(paramsIndex))
                        {
                            var argumentExpression = (LuaExpressionSyntax)argument.Accept(this);
                            paramsExpression.Expressions.Add(argumentExpression);
                        }
                        if (paramsExpression.Expressions.Count > 0)
                        {
                            AddCodeTemplateExpression(paramsExpression, comma, codeTemplateExpression);
                        }
                    }
                }
                else
                {
                    int argumentIndex;
                    if (int.TryParse(key, out argumentIndex))
                    {
                        var argument = arguments.ElementAtOrDefault(argumentIndex);
                        if (argument != null)
                        {
                            var argumentExpression = (LuaExpressionSyntax)argument.Accept(this);
                            AddCodeTemplateExpression(argumentExpression, comma, codeTemplateExpression);
                        }
                    }
                }
                prevIndex = match.Index + match.Length;
            }

            if (prevIndex < codeTemplate.Length)
            {
                string last = codeTemplate.Substring(prevIndex);
                codeTemplateExpression.Expressions.Add(new LuaIdentifierNameSyntax(last));
            }

            return(codeTemplateExpression);
        }
Ejemplo n.º 5
0
 private void AddCodeTemplateExpression(LuaExpressionSyntax expression, string comma, LuaCodeTemplateExpressionSyntax codeTemplateExpression)
 {
     if (!string.IsNullOrEmpty(comma))
     {
         codeTemplateExpression.Expressions.Add(new LuaIdentifierNameSyntax(comma));
     }
     codeTemplateExpression.Expressions.Add(expression);
 }