Пример #1
0
        public override AttributeDefinition VisitAttribute_name_part(V1QueryParser.Attribute_name_partContext context)
        {
            var attributeName = context.NAME().GetText();
            var downcast      = context.downcast()?.asset_type_token().GetText();
            var filter        = context.attribute_filter();

            AttributeDefinition result;

            if (!_metaModel.TryGetAttributeDefinition(_rootAssetType, attributeName, out result))
            {
                throw new InvalidOperationException($"Cannot find attribute definition {_rootAssetType.Token}.{attributeName}");
            }

            if (!string.IsNullOrEmpty(downcast))
            {
                var downcastAssetType = _metaModel.GetAssetType(downcast);
                result = result.CreateDowncastAttributeDefinition(downcastAssetType);
            }

            if (filter != null)
            {
                var subVisitor = new FilterVisitor(result.RelatedAssetType, _metaModel);
                var subFilter  = subVisitor.Visit(filter);
                result = result.CreateFilteredAttributeDefinition(subFilter);
            }

            return(result);
        }
Пример #2
0
        public static FilterTerm ParseFilter(string filterToken, AssetType assetType, MetaModel metaModel)
        {
            ICharStream  charStream  = new AntlrInputStream(filterToken);
            ITokenSource tokenSource = new V1QueryLexer(charStream);
            ITokenStream tokenStream = new CommonTokenStream(tokenSource);
            var          parser      = new V1QueryParser(tokenStream);
            var          expression  = parser.filter_expression();
            var          visitor     = new FilterVisitor(assetType, metaModel);

            return(visitor.Visit(expression));
        }