public void NamePart(string namePart)
        {
            if (_name == null)
            {
                _name = namePart;
            }
            else
            {
                _name += $".{namePart}";
            }

            if (_type == null && _expression == null)
            {
                _type = _parserContext.FindType(_name);
                if (_type != null)
                {
                    _name = null;
                }
            }
        }
        public override void EnterRuleFactMatch(RuleFactMatchContext context)
        {
            var patternTypeName = context.type().GetText();
            var patternType     = _parserContext.FindType(patternTypeName);

            if (patternType == null)
            {
                throw new InternalParseException($"Unknown type. Type={patternTypeName}", context);
            }

            var variableTypeName = context.local_variable_type().VAR() == null
                ? context.local_variable_type().type().GetText()
                : patternTypeName;

            var variableType = _parserContext.FindType(variableTypeName);

            if (variableType == null)
            {
                throw new InternalParseException($"Unknown type. Type={variableTypeName}", context);
            }

            var id             = context.identifier().GetText();
            var patternBuilder = _groupBuilder.Pattern(patternType, id);

            if (context.expression_list() != null)
            {
                foreach (var expressionContext in context.expression_list().expression())
                {
                    using (_parserContext.PushScope())
                    {
                        var expressionParser = new ExpressionParser(_parserContext, patternType);
                        var expression       = (LambdaExpression)expressionParser.Visit(expressionContext);
                        patternBuilder.DslConditions(_parserContext.Scope.Declarations, expression);
                    }
                }
            }
            _parserContext.Scope.Declare(variableType, id);
        }
Пример #3
0
        public override Expression VisitUnary_expression(Unary_expressionContext context)
        {
            if (context.primary_expression() != null)
            {
                return(Visit(context.primary_expression()));
            }

            var expression = Visit(context.unary_expression());

            if (context.type() != null)
            {
                var typeName = context.type().GetText();
                var type     = _parserContext.FindType(typeName);
                if (type == null)
                {
                    throw new InternalParseException($"Unknown type. Type={typeName}", context);
                }
                return(Expression.Convert(expression, type));
            }

            var op = context.children[0].GetText();

            if (op == "!" || op == "~")
            {
                expression = Expression.Not(expression);
            }
            else if (op == "+")
            {
                //Keep the expression
            }
            else if (op == "-")
            {
                expression = Expression.Negate(expression);
            }
            else
            {
                throw new InternalParseException($"Unsupported operation. Operation={op}", context);
            }
            return(expression);
        }