internal static CommandBase FromCode(SyntaxElement rootElement)
        {
            var tableNameDeclaration = rootElement.GetUniqueDescendant <NameDeclaration>(
                "Table Name",
                n => n.NameInParent == "TableName");
            var mappingNameExpression = rootElement.GetUniqueDescendant <LiteralExpression>(
                "Mapping Name",
                n => n.NameInParent == "MappingName");
            var mappingKindToken = rootElement.GetUniqueDescendant <SyntaxToken>(
                "Mapping Kind",
                n => n.NameInParent == "MappingKind");
            var mappingFormatExpression = rootElement.GetUniqueDescendant <LiteralExpression>(
                "Mapping Format",
                n => n.NameInParent == "MappingFormat");
            var mappingFormatFirstPart  = QuotedText.FromLiteral(mappingFormatExpression);
            var mappingFormatExtraParts = rootElement
                                          .GetDescendants <CompoundStringLiteralExpression>()
                                          .SelectMany(c => c.Tokens)
                                          .Select(t => QuotedText.FromToken(t));
            var mappingFormatParts = mappingFormatExtraParts
                                     .Prepend(mappingFormatFirstPart)
                                     .Select(q => q.Text);
            var mappingFormat = string.Concat(mappingFormatParts);
            var command       = new CreateMappingCommand(
                EntityName.FromCode(tableNameDeclaration),
                mappingKindToken.Text,
                QuotedText.FromLiteral(mappingNameExpression),
                QuotedText.FromText(mappingFormat) !);

            return(command);
        }
 public DropMappingCommand(
     EntityName tableName,
     string mappingKind,
     QuotedText mappingName)
 {
     TableName   = tableName;
     MappingKind = mappingKind.ToLower();
     MappingName = mappingName;
 }
示例#3
0
        private static QuotedText?GetProperty(SyntaxElement rootElement, SyntaxKind kind)
        {
            var literal = rootElement
                          .GetDescendants <SyntaxElement>(e => e.Kind == kind)
                          .Select(e => e.Parent.GetDescendants <LiteralExpression>().FirstOrDefault())
                          .FirstOrDefault();

            return(literal == null
                ? null
                : QuotedText.FromLiteral(literal));
        }
 public CreateMappingCommand(
     EntityName tableName,
     string mappingKind,
     QuotedText mappingName,
     QuotedText mappingAsJson)
 {
     TableName     = tableName;
     MappingKind   = mappingKind.ToLower();
     MappingName   = mappingName;
     MappingAsJson = mappingAsJson;
 }
        internal static CommandBase FromCode(SyntaxElement rootElement)
        {
            var tableNameReference = rootElement.GetUniqueDescendant <NameReference>(
                "Table Name",
                n => n.NameInParent == "TableName");
            var mappingNameExpression = rootElement.GetUniqueDescendant <LiteralExpression>(
                "Mapping Name",
                n => n.NameInParent == "MappingName");
            var mappingKindToken = rootElement.GetUniqueDescendant <SyntaxToken>(
                "Mapping Kind",
                n => n.NameInParent == "MappingKind");
            var command = new DropMappingCommand(
                new EntityName(tableNameReference.SimpleName),
                mappingKindToken.Text,
                QuotedText.FromLiteral(mappingNameExpression));

            return(command);
        }
        public CreateFunctionCommand(
            EntityName functionName,
            IEnumerable <TypedParameterModel> parameters,
            string functionBody,
            QuotedText folder,
            QuotedText docString)
        {
            FunctionName = functionName;
            Parameters   = parameters.ToImmutableArray();

            if (functionBody.Trim().StartsWith('{'))
            {
                throw new ArgumentException(
                          $"Body should start with curly braces:  '{functionBody}'",
                          nameof(functionBody));
            }
            ValidateNoTableParameterAfterScalar(functionName, Parameters);
            Body      = functionBody.Trim().Replace("\r", string.Empty);
            Folder    = folder;
            DocString = docString;
        }
示例#7
0
        private static (QuotedText?folder, QuotedText?docString) ExtractWithProperties(
            SyntaxElement rootElement)
        {
            var keywords = rootElement
                           .GetDescendants <SyntaxElement>(n => n.Kind == SyntaxKind.FolderKeyword ||
                                                           n.Kind == SyntaxKind.DocStringKeyword);

            if (!keywords.Any())
            {
                return(null, null);
            }
            else
            {
                var propertiesParent = keywords.First().Parent;
                var tokenSequence    = propertiesParent
                                       .GetDescendants <SyntaxToken>(n => n.Kind == SyntaxKind.StringLiteralToken)
                                       .Select(n => QuotedText.FromToken(n));
                var zip = keywords
                          .Select(n => n.Kind)
                          .Zip(tokenSequence, (k, t) => (k, t))
                          .ToImmutableArray();
                QuotedText?folder    = null;
                QuotedText?docString = null;

                foreach (var p in zip)
                {
                    if (p.k == SyntaxKind.FolderKeyword)
                    {
                        folder = p.t;
                    }
                    else
                    {
                        docString = p.t;
                    }
                }

                return(folder, docString);
            }
        }
 public ColumnDocString(EntityName columnName, QuotedText docString)
 {
     ColumnName = columnName;
     DocString = docString;
 }
示例#9
0
 public static QuotedText Escape(QuotedText original)
 {
     return(new QuotedText(Escape(original.Text)));
 }