Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public DropMappingCommand(
     EntityName tableName,
     string mappingKind,
     QuotedText mappingName)
 {
     TableName   = tableName;
     MappingKind = mappingKind.ToLower();
     MappingName = mappingName;
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 4
0
 public CreateMappingCommand(
     EntityName tableName,
     string mappingKind,
     QuotedText mappingName,
     QuotedText mappingAsJson)
 {
     TableName     = tableName;
     MappingKind   = mappingKind.ToLower();
     MappingName   = mappingName;
     MappingAsJson = mappingAsJson;
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 9
0
 public static QuotedText Escape(QuotedText original)
 {
     return(new QuotedText(Escape(original.Text)));
 }