protected TerminalExpressionNode(
     ExpressionTypeDescriptor expressionType,
     ISourceCodeFragment fragment)
 {
     Fragment       = fragment;
     ExpressionType = expressionType;
 }
Ejemplo n.º 2
0
        public CapturingGroupBrick Clone(IFlexpressionAlgebra algebra, string groupName, bool freeze = false)
        {
            var expressionType = string.Equals(groupName, _expressionType.Name)
                ? _expressionType
                : ExpressionTypeDescriptor.Create(groupName, _expressionType.ValueTypeId, _expressionType.DefinesExpressionClass);

            return(new CapturingGroupBrick(expressionType, algebra.GetHighestPrioritizedAlgebra(this), Content, freeze));
        }
Ejemplo n.º 3
0
        public CapturingGroupBrick(ExpressionTypeDescriptor expressionType, IFlexpressionAlgebra algebra, FlexpressionBrick content, bool freeze)
            : base(algebra)
        {
            Guard.ArgNotNull(expressionType, nameof(expressionType));

            _expressionType = expressionType;
            Content         = content;
            ApplyRuleDefinition(Content, GroupName, content, true, freeze);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MathExpressionParameterlessFunctionNode"/> class.
 /// </summary>
 /// <param name="expressionTypeId">The expression type identifier.</param>
 /// <param name="functionNameFragment">The function name fragment.</param>
 /// <param name="function">The function to evaluate function value.</param>
 /// <param name="valueTypeId">The value type identifier.</param>
 public MathExpressionParameterlessFunctionNode(
     string expressionTypeId,
     ISourceCodeFragment functionNameFragment,
     Func <object> function,
     string valueTypeId = null)
     : base(ExpressionTypeDescriptor.CreateExpressionClass(expressionTypeId, valueTypeId), functionNameFragment)
 {
     _function = function;
 }
Ejemplo n.º 5
0
        private static ExpressionTypeDescriptor CreateExpressionType(string ruleName, string valueTypeId = null)
        {
            if (String.IsNullOrEmpty(ruleName))
            {
                Guard.ArgNullOrEmpty(valueTypeId, nameof(valueTypeId));
                return(ExpressionTypeDescriptor.Undefined);
            }

            return(ExpressionTypeDescriptor.CreateExpressionClass(ruleName, valueTypeId));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MathExpressionFunctionNode"/> class.
        /// </summary>
        /// <param name="expressionType"></param>
        /// <param name="functionNameFragment">The function name fragment.</param>
        /// <param name="subNodes">The sub nodes (parameters).</param>
        /// <param name="function">The delegate to calculate function value.</param>
        /// <exception cref="ArgumentException">null sub node</exception>
        public MathExpressionFunctionNode(
            ExpressionTypeDescriptor expressionType,
            ISourceCodeFragment functionNameFragment,
            IEnumerable <IParsingProduct> subNodes,
            Func <object[], object> function)
            : base(expressionType, functionNameFragment, subNodes)
        {
            _function = function;

            if (SubNodes.Cast <IExecutableExpressionNode>().Any(n => n == null))
            {
                throw new ArgumentException("null sub node");
            }
        }
        private IParsingProduct GetFunction(
            ISourceCodeFragment functionName,
            string expressionTypeId,
            IEnumerable <IParsingProduct> arguments)
        {
            if (!_functionsByNameByArgCount.TryGetValue(functionName, out var functionByArgsCount))
            {
                return(null);
            }

            var args = arguments?.ToArray() ?? Array.Empty <IParsingProduct>();

            if (!functionByArgsCount.TryGetValue(args.Length, out var func))
            {
                return(null);
            }

            return(new MathExpressionFunctionNode(ExpressionTypeDescriptor.CreateExpressionClass(expressionTypeId), functionName, args, func));
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        protected override IParsingProduct TryParseInternal(IParsingContextStream ctx, ParsingOptions options)
        {
            var res = Content.TryParse(ctx, options);

            if (res == null)
            {
                ctx.SetError(new ParsingError(1, $"{GroupName} expected at: '{ctx}'; {Name}"));

                return(null);
            }

            var overwriteExpressionType = res.ExpressionType.ValueTypeId != null && _expressionType.ValueTypeId == null;

            var expressionType = overwriteExpressionType
                ? ExpressionTypeDescriptor.Create(_expressionType.Name, res.ExpressionType.ValueTypeId,
                                                  _expressionType.DefinesExpressionClass) : _expressionType;

            var node = ctx.Accept().CreateExpressionForAcceptedFragment(
                expressionType,
                res.ToList());

            return(node);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MathExpressionValueNode"/> class.
 /// </summary>
 /// <param name="expressionTypeId">The expression type identifier.</param>
 /// <param name="valueFragment">The source code fragment that represents the value.</param>
 /// <param name="value">The value.</param>
 /// <param name="valueTypeId">The value type identifier.</param>
 public MathExpressionValueNode(string expressionTypeId, ISourceCodeFragment valueFragment, object value, string valueTypeId = null)
     : base(ExpressionTypeDescriptor.CreateExpressionClass(expressionTypeId, valueTypeId), valueFragment)
 {
     _value = value;
 }
Ejemplo n.º 10
0
 public static FlexpressionBrick DefinesSealedRule(this FlexpressionBrick source, ExpressionTypeDescriptor expressionType)
 {
     return((source.Algebra ?? DefaultAlgebra).DefineSealedRule(source, expressionType));
 }
Ejemplo n.º 11
0
 private TermNode(ExpressionTypeDescriptor expressionType, ISourceCodeFragment fragment)
 {
     ExpressionType = expressionType;
     Fragment       = fragment;
 }
Ejemplo n.º 12
0
 public static TermNode Create(ExpressionTypeDescriptor expressionType, ISourceCodeFragment fragment)
 {
     return(new TermNode(expressionType, fragment));
 }
Ejemplo n.º 13
0
 public IParsingProduct CreateExpression(ExpressionTypeDescriptor expressionType, ISourceCodeFragment codeFragment, IReadOnlyCollection <IParsingProduct> subNodes)
 {
     return(ExpressionNode.Create(expressionType, codeFragment, subNodes));
 }
Ejemplo n.º 14
0
 public IParsingProduct CreateTerm(ExpressionTypeDescriptor expressionType, ISourceCodeFragment codeFragment)
 {
     return(TermNode.Create(expressionType, codeFragment));
 }