Ejemplo n.º 1
0
            public void Assert(BaseTerm assertion, bool asserta)
            {
                BaseTerm       head;
                TermNode       body = null;
                PredicateDescr pd;

                if (assertion.HasFunctor(PrologParser.IMPLIES))
                {
                    head = assertion.Arg(0);
                    body = assertion.Arg(1).ToGoalList();
                }
                else
                {
                    head = assertion;
                }

                if (!head.IsCallable)
                {
                    IO.Error("Illegal predicate head '{0}'", head.ToString());
                }

                string key = head.Key;

                if ((predefineds.Contains(key)) || (head.Precedence >= 1000))
                {
                    IO.Error("assert/1 cannot be applied to predefined predicate or operator '{0}'",
                             assertion.Index);
                }

                predTable.TryGetValue(key, out pd);
                ClauseNode newC = new ClauseNode(head, body);

                if (pd == null) // first head
                {
                    SetClauseList(head.FunctorToString, head.Arity, newC);
                    ResolveIndices();
                }
                else if (pd.IsCacheable)
                {
                    IO.Error("assert/1 cannot be applied to cached predicate '{0}'",
                             assertion.Index);
                }
                else if (asserta)                    // at beginning
                {
                    newC.NextClause = pd.ClauseList; // pd.ClauseList may be null
                    SetClauseList(head.FunctorToString, head.Arity, newC);
#if arg1index
                    pd.CreateFirstArgIndex(); // re-create
#endif
                }
                else // at end
                {
                    pd.AppendToClauseList(newC);
#if arg1index
                    pd.CreateFirstArgIndex(); // re-create
#endif
                }

                InvalidateCrossRef();
            }
Ejemplo n.º 2
0
        public static IFieldSort GetDefaultSort(this TermNode node, IQueryVisitorContext context)
        {
            var elasticContext = context as IElasticQueryVisitorContext;

            if (elasticContext == null)
            {
                throw new ArgumentException("Context must be of type IElasticQueryVisitorContext", nameof(context));
            }

            string field = elasticContext.GetNonAnalyzedFieldName(node.Field, "sort");

            var sort = new SortField {
                Field = field
            };

            if (node.IsNodeOrGroupedParentNegated())
            {
                sort.Order = SortOrder.Descending;
            }
            else
            {
                sort.Order = SortOrder.Ascending;
            }

            return(sort);
        }
Ejemplo n.º 3
0
        protected TermNode ParseTerm()
        {
            TermNode term = ReturnOrBacktrack(ParseBoolean);

            if (term != null)
            {
                return(term);
            }
            term = ReturnOrBacktrack(ParseNumberLiteral);
            if (term != null)
            {
                return(term);
            }
            term = ReturnOrBacktrack(ParseStringLiteral);
            if (term != null)
            {
                return(term);
            }
            term = ReturnOrBacktrack(ParseObjectPath);
            if (term != null)
            {
                return(term);
            }
            throw new ParserException("Could not parse Term");
        }
Ejemplo n.º 4
0
        public override void Visit(TermNode node)
        {
            // using all fields search
            if (String.IsNullOrEmpty(node.Field?.Field))
            {
                UsesPremiumFeatures = true;
            }

            if (node.Field != null)
            {
                // using a field not in the free list
                if (!_freeFields.Contains(node.Field.Field))
                {
                    UsesPremiumFeatures = true;
                }

                if (node.Field.Field.StartsWith("data."))
                {
                    UsesDataFields = true;
                    string termType = GetTermType(node.TermMin, node.TermMax, node.Term);
                    node.Field.Field = $"idx.{node.Field.Field.Substring(5).ToLower()}-{termType}";
                }
                else if (node.Field.Field.StartsWith("ref."))
                {
                    UsesDataFields   = true;
                    node.Field.Field = $"idx.{node.Field.Field.Substring(4).ToLower()}-r";
                }
            }

            base.Visit(node);
        }
Ejemplo n.º 5
0
        /// <summary>Parses the term AST node</summary>
        /// <param name="termNode">The AST node</param>
        internal void ParseTerm(TermNode termNode)
        {
            if (string.IsNullOrWhiteSpace(termNode.StringBasedValue))
            {
                return;
            }

            switch (termNode.StringBasedValue)
            {
            case ImageAssembleConstants.Repeat:
                this.RepeatValue = Repeat.Repeat;
                break;

            case ImageAssembleConstants.NoRepeat:
                this.RepeatValue = Repeat.NoRepeat;
                break;

            case ImageAssembleConstants.RepeatX:
                this.RepeatValue = Repeat.RepeatX;
                break;

            case ImageAssembleConstants.RepeatY:
                this.RepeatValue = Repeat.RepeatY;
                break;
            }
        }
Ejemplo n.º 6
0
 public void Clear()
 {
     term       = null;
     nextNode   = null;
     nextClause = null;
     level      = 0;
 }
Ejemplo n.º 7
0
 public SpyPoint(SpyPort p, TermNode g)
     : base()
 {
     port     = p;
     saveGoal = g;
     level    = g.Level;
 }
Ejemplo n.º 8
0
            public override string ToString()
            {
                string NL = Environment.NewLine;

                StringBuilder sb = new StringBuilder(NL + term.ToString());

                bool     first = true;
                TermNode tl    = nextNode;

                if (tl == null)
                {
                    return(sb.ToString() + '.' + NL);
                }

                while (true)
                {
                    if (first)
                    {
                        sb.Append(" :-");
                    }

                    sb.Append(NL + "  " + tl.Term);

                    if ((tl = tl.NextNode) == null)
                    {
                        return(sb.ToString() + '.' + NL);
                    }
                    else if (!first)
                    {
                        sb.AppendFormat(",");
                    }

                    first = false;
                }
            }
Ejemplo n.º 9
0
        public override void Visit(TermNode node, IQueryVisitorContext context)
        {
            var    validationInfo = context.GetValidationInfo();
            string field          = null;

            if (!String.IsNullOrEmpty(node.Field))
            {
                field = String.Equals(validationInfo.QueryType, QueryType.Query) ? node.GetFullName() : node.Field;
                if (!field.StartsWith("@"))
                {
                    validationInfo.ReferencedFields.Add(field);
                }
            }
            else
            {
                if (String.Equals(validationInfo.QueryType, QueryType.Aggregation))
                {
                    validationInfo.IsValid = false;
                }

                var nameParts = node.GetNameParts();
                if (nameParts.Length == 0)
                {
                    validationInfo.ReferencedFields.Add("_all");
                }
            }

            AddOperation(validationInfo, node.GetOperationType(), field);
        }
        /// <summary>Updates the term for vertical position</summary>
        /// <param name="termNode">The term node</param>
        /// <param name="updatedTermNode">The new term node</param>
        /// <param name="updatedY">The new Y position</param>
        /// <param name="webGreaseBackgroundDpi">The webgrease background dpi to use</param>
        /// <returns>Returns true if term is updated</returns>
        internal bool UpdateTermForY(TermNode termNode, out TermNode updatedTermNode, float?updatedY, float webGreaseBackgroundDpi)
        {
            if (termNode == this.YTermNode)
            {
                // Lets not assume any spriting direction here.
                // Update Y when it is in zero or pixels
                if (this.Y == 0 || this.YSource == Source.Px)
                {
                    // we need to adjust the physical pixel of the new sprite position according to dpi to get client pixels.
                    // then we add the client-pixels position from the source.
                    // then we multiply by the output unit factor and update the result.
                    var calcY = (float?)Math.Round(
                        (this.Y.GetValueOrDefault() + (updatedY.GetValueOrDefault() / webGreaseBackgroundDpi)) * this.outputUnitFactor,
                        3);

                    // Create a term with new y
                    updatedTermNode = new TermNode(calcY.UnaryOperator(), calcY.CssUnitValue(this.outputUnit), null, null, null, null);
                }
                else
                {
                    // No change in y and return the original term
                    updatedTermNode = termNode;
                }

                return(true);
            }

            updatedTermNode = termNode;
            return(false);
        }
        /// <summary>Adds a node with new updatedX, updatedY to specify the background position</summary>
        /// <param name="updatedX">The updated X</param>
        /// <param name="updatedY">The updated Y</param>
        /// <param name="webGreaseBackgroundDpi">The webgrease background dpi to use</param>
        /// <param name="outputUnit">The output init (px/em/rem) </param>
        /// <param name="outputUnitFactor">The factor which which to multiple the px value to get the output unit.</param>
        /// <returns>The declaration node</returns>
        internal static DeclarationNode CreateNewDeclaration(float?updatedX, float?updatedY, float webGreaseBackgroundDpi, string outputUnit, double outputUnitFactor)
        {
            if (updatedX == null || (updatedX == 0 && updatedY == 0))
            {
                return(null);
            }

            // Create a new term for coordinate x
            var calcX = (float?)Math.Round(((float)updatedX) * outputUnitFactor / webGreaseBackgroundDpi, 3);

            var termNodeX = new TermNode(calcX.UnaryOperator(), calcX.CssUnitValue(outputUnit), null, null, null, null);

            var termWithOperatorNodes = new List <TermWithOperatorNode>();

            // Create a new term with operator for coordinate y
            if (updatedY != null && updatedY != 0)
            {
                var calcY     = (float?)Math.Round(((float)updatedY) * outputUnitFactor / webGreaseBackgroundDpi, 3);
                var termNodeY = new TermNode(calcY.UnaryOperator(), calcY.CssUnitValue(outputUnit), null, null, null, null);
                termWithOperatorNodes.Add(new TermWithOperatorNode(ImageAssembleConstants.SingleSpace, termNodeY));
            }

            // Create a new expression
            var expressionNode = new ExprNode(termNodeX, termWithOperatorNodes.AsReadOnly(), null);

            // Create a new declaration node
            return(new DeclarationNode(ImageAssembleConstants.BackgroundPosition, expressionNode, null, null));
        }
Ejemplo n.º 12
0
        public void AddTermNode(TermNode termNode)
        {
            this.InitCheck();
            this.m_trTermNode.AddNodeToTree(termNode, true);

            //this.m_mapLocExtnIdToLocCvgList = new Dictionary<string, List<LocationCvg>>();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Adds or replaces a <see cref="TermNode"/>
        /// </summary>
        public bool TryAddOrReplace(TermNode term)
        {
            // Check the term options
            if (!TermOptions.TryGetValue(term.TermName, out var termOption))
            {
                return(false);
            }

            if (_terms.TryGetValue(term.TermName, out var existingTerm))
            {
                if (termOption.Single)
                {
                    // Replace
                    _terms[term.TermName] = term;
                    return(true);
                }

                // Add
                if (existingTerm is CompoundTermNode compound)
                {
                    compound.Children.Add(term as TermOperationNode);
                }
                else
                {
                    var newCompound = new AndTermNode(existingTerm as TermOperationNode, term as TermOperationNode);
                    _terms[term.TermName] = newCompound;
                    return(true);
                }
            }

            _terms[term.TermName] = term;

            return(true);
        }
        public override void Visit(TermNode node, IQueryVisitorContext context)
        {
            if (String.IsNullOrEmpty(node.Field))
            {
                return;
            }

            _fields.Add(node.GetSort(() => node.GetDefaultSort(context)));
        }
        public override void Visit(TermNode node, IQueryVisitorContext context)
        {
            if (String.IsNullOrEmpty(node.Term) || (node.Field != null && node.Field.StartsWith("@")))
            {
                return;
            }

            node.Field = node.Term;
            node.Term  = null;
        }
        /// <summary>The <see cref="Ast.TermNode"/> visit implementation</summary>
        /// <param name="termNode">The term AST node</param>
        /// <returns>The modified AST node if modified otherwise the original node</returns>
        public override AstNode VisitTermNode(TermNode termNode)
        {
            if (termNode == null)
            {
                throw new ArgumentNullException("termNode");
            }

            var funcNode         = termNode.FunctionNode;
            var numberBasedValue = termNode.NumberBasedValue;

            if (!string.IsNullOrWhiteSpace(numberBasedValue))
            {
                var match = NumberBasedValue.Match(numberBasedValue);
                if (match.Success)
                {
                    var fullNumber = match.Result("$1").ParseFloat(); // Say - 001.2400
                    var units      = match.Result("$4");              // Say % or px

                    // for zero values that are LENGTHS, we can omit the units altogether.
                    if (fullNumber == 0)
                    {
                        // number is zero
                        if (string.IsNullOrEmpty(units) || units == "%" || LengthUnits.IsMatch(units))
                        {
                            // either no units, or we can drop the units altogether (length or percentage) and just return the zero by itself
                            return(new TermNode(termNode.UnaryOperator, "0", termNode.StringBasedValue, termNode.Hexcolor, termNode.FunctionNode, termNode.ImportantComments));
                        }
                        else
                        {
                            // but we can't drop the units for Angles, Times, Frequencies, or Resolutions,
                            // and we shouldn't drop them for any unknown units.
                            return(new TermNode(termNode.UnaryOperator, string.Concat("0", units), termNode.StringBasedValue, termNode.Hexcolor, termNode.FunctionNode, termNode.ImportantComments));
                        }
                    }

                    var leftNumber  = match.Result("$2").TrimStart("0".ToCharArray()); // Say 001
                    var rightNumber = match.Result("$3").TrimEnd("0".ToCharArray());   // Say .2400
                    if (rightNumber == CssConstants.Dot.ToString())
                    {
                        rightNumber = string.Empty;
                    }

                    return(new TermNode(termNode.UnaryOperator, string.Concat(leftNumber, rightNumber, units), termNode.StringBasedValue, termNode.Hexcolor, termNode.FunctionNode, termNode.ImportantComments));
                }
            }
            else if (funcNode != null)
            {
                // this visitor should never convert a function node to anything other than
                // a function node, so just force the conversion.
                funcNode = (FunctionNode)funcNode.Accept(this);
            }

            return(new TermNode(termNode.UnaryOperator, numberBasedValue, termNode.StringBasedValue, termNode.Hexcolor, funcNode, termNode.ImportantComments));
        }
        public override Task VisitAsync(TermNode node, IQueryVisitorContext context)
        {
            // using all fields search
            if (String.IsNullOrEmpty(node.Field))
            {
                return(Task.CompletedTask);
            }

            node.Field = GetCustomFieldName(node.Field, new [] { node.Term });
            return(Task.CompletedTask);
        }
Ejemplo n.º 18
0
            static void DCGGoal(BaseTerm t, ref TermNode body, ref BaseTerm remainder, ref bool embedded)
            {
                BaseTerm temp;

                if (t.IsString || t is Cut)
                {
                    body.Append(t);
                }
                else if (t.HasFunctor(PrologParser.CURL))
                {
                    while (t.Arity == 2)
                    {
                        body.Append(t.Arg(0));
                        t        = t.Arg(1);
                        embedded = true;
                    }
                }
                else if (t.IsProperList)
                {
                    temp = new Variable();

                    t = (t.IsEmptyList) ? temp : ((ListTerm)t).Append(temp);

                    if (embedded)
                    {
                        body.Append(new CompoundTerm(PrologParser.EQ, remainder, t));
                        embedded = false;
                    }
                    else
                    {
                        ((Variable)remainder).Bind(t);
                    }
                    // in this case, nothing is appended to body, which may be left empty (e.g. t-->[x])

                    remainder = temp;
                }
                else if (t.IsAtom || t.IsCompound)
                {
                    t = new DcgTerm(t, ref remainder);
                    body.Append(t);
                }
                else if (t.IsNamedVar)
                {
                    IO.Error("Variable not allowed in DCG-clause: {0}", ((NamedVariable)t).Name);
                }
                else if (t.IsUnboundTerm)
                {
                    IO.Error("Unbound variable not allowed in DCG-clause");
                }
                else
                {
                    IO.Error("Illegal term in DCG-clause: {0}", t);
                }
            }
Ejemplo n.º 19
0
            public override string ToString()
            {
                StringBuilder sb     = new StringBuilder();
                bool          first  = true;
                int           indent = 2;
                TermNode      tn     = this;
                BaseTerm      t;

                while (tn != null)
                {
                    if ((t = tn.term) is TryOpenTerm)
                    {
                        if (!first)
                        {
                            sb.Append(',');
                        }

                        sb.AppendFormat("{0}{1}TRY{0}{1}(", Environment.NewLine, Spaces(2 * indent++));
                        first = true;
                    }
                    else if (t is CatchOpenTerm)
                    {
                        CatchOpenTerm co     = (CatchOpenTerm)t;
                        string        msgVar = (co.MsgVar is AnonymousVariable) ? null : co.MsgVar.Name;
                        string        comma  = (co.ExceptionClass == null || msgVar == null) ? null : ", ";

                        sb.AppendFormat("{0}{1}){0}{1}CATCH {2}{3}{4}{0}{1}(",
                                        Environment.NewLine, Spaces(2 * (indent - 1)), co.ExceptionClass, comma, msgVar);
                        first = true;
                    }
                    else if (t == TC_CLOSE)
                    {
                        sb.AppendFormat("{0}{1})", Environment.NewLine, Spaces(2 * --indent));
                        first = false;
                    }
                    else
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            sb.Append(',');
                        }

                        sb.AppendFormat("{0}{1}{2}", Environment.NewLine, Spaces(2 * indent), t);
                    }

                    tn = tn.nextNode;
                }

                return(sb.ToString());
            }
Ejemplo n.º 20
0
        public override void Visit(TermNode node, IQueryVisitorContext context)
        {
            if (!IsNestedPropertyType(node.Field?.Split('.'), context))
            {
                return;
            }

            node.SetQuery(new NestedQuery {
                Path = node.GetParentFullName(), Query = node.GetQuery(() => node.GetDefaultQuery(context))
            });
        }
Ejemplo n.º 21
0
        public void Visit(TermNode node)
        {
            // using all fields search
            if (String.IsNullOrEmpty(node.Field))
            {
                UsesPremiumFeatures = true;
                return;
            }

            node.Field = GetCustomFieldName(node.Field, node.Term) ?? node.Field;
        }
        public override void Visit(TermNode node, IQueryVisitorContext context)
        {
            var validationInfo = context.GetValidationInfo();

            AddField(validationInfo, node, context);
            AddOperation(validationInfo, node.GetOperationType(), node.Field);

            // aggregations must have a field
            if (context.QueryType == QueryType.Aggregation && String.IsNullOrEmpty(node.Field))
            {
                validationInfo.IsValid = false;
            }
        }
Ejemplo n.º 23
0
            void SetupCrossRefTable() //TODO (later...): deal with arguments of not/1 and call/1
            {
                if (!crossRefInvalid)
                {
                    return;
                }

                crossRefTable.Reset();
                PredicateDescr pd;

                foreach (KeyValuePair <string, PredicateDescr> kv in predTable)
                {
                    pd = kv.Value;
                    bool       isPredefined = IsPredefined(kv.Key);
                    ClauseNode clause       = pd.ClauseList;

                    if (!isPredefined)
                    {
                        crossRefTable.AddPredicate(pd);
                    }

                    // iterate over NextClause and NextClause.NextNode
                    while (clause != null)
                    {
                        TermNode node = clause.NextNode;

                        while (node != null)
                        {
                            if (node.PredDescr != null && !isPredefined)
                            {
                                PredicateDescr npd;
                                //IO.WriteLine ("{0} uses {1}", pd.Name, node.PredDescr.Name);
                                crossRefTable[pd, npd = node.PredDescr] = false;

                                if (npd.Name == "not/1" || npd.Name == "call/1") // add args to cref
                                {
                                    TermNode arg = node.NextNode;
                                    IO.WriteLine("{0} arg is {1}", npd.Name, arg);
                                }
                            }

                            node = node.NextNode;
                        }

                        clause = clause.NextClause;
                    }
                }

                crossRefTable.CalculateClosure();
                crossRefInvalid = false;
            }
Ejemplo n.º 24
0
        /// <summary>The <see cref="TermNode"/> visit implementation</summary>
        /// <param name="termNode">The term AST node</param>
        /// <returns>The modified AST node if modified otherwise the original node</returns>
        public override AstNode VisitTermNode(TermNode termNode)
        {
            // term
            // : unary_operator?
            // [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
            // TIME S* | FREQ S* ]
            // | STRING S* | IDENT S* | URI S* | hexcolor | function
            // ;

            // append for: unary_operator?
            // TODO - Shall we remove the '+' operator here?
            _printerFormatter.Append(termNode.UnaryOperator);
            if (termNode.IsBinary && FunctionNode.IsBinaryOperator(termNode.UnaryOperator))
            {
                _printerFormatter.Append(" ");
            }

            // append for: [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* | TIME S* | FREQ S* ]
            if (!string.IsNullOrWhiteSpace(termNode.NumberBasedValue))
            {
                _printerFormatter.Append(termNode.NumberBasedValue);
            }
            else if (!string.IsNullOrWhiteSpace(termNode.StringBasedValue))
            {
                // append for: | STRING S* | IDENT S* | URI S*
                _printerFormatter.Append(termNode.StringBasedValue);
            }
            else if (!string.IsNullOrWhiteSpace(termNode.ReplacementTokenBasedValue))
            {
                // TODO: REPLACECSSTOKENONPRINT
                _printerFormatter.Append(termNode.ReplacementTokenBasedValue);
            }
            else if (!string.IsNullOrWhiteSpace(termNode.Hexcolor))
            {
                // append for: hexcolor
                _printerFormatter.Append(termNode.Hexcolor);
            }
            else if (termNode.FunctionNode != null)
            {
                // append for: function
                // Invoke the Function visitor
                termNode.FunctionNode.Accept(this);
            }

            foreach (var comment in termNode.ImportantComments)
            {
                comment.Accept(this);
            }

            return(termNode);
        }
Ejemplo n.º 25
0
        /// <summary>Updates the term for url</summary>
        /// <param name="originalTermNode">The original term node</param>
        /// <param name="updatedTermNode">The new term node</param>
        /// <param name="updatedUrl">The new url</param>
        /// <returns>True if the term is updated</returns>
        internal bool UpdateTermForUrl(TermNode originalTermNode, out TermNode updatedTermNode, string updatedUrl)
        {
            if (originalTermNode == this.UrlTermNode)
            {
                updatedUrl = string.Format(CultureInfo.CurrentUICulture, ImageAssembleConstants.UrlTerm, updatedUrl);

                // Create a term with new assembled image url
                updatedTermNode = new TermNode(originalTermNode.UnaryOperator, originalTermNode.NumberBasedValue, updatedUrl, originalTermNode.Hexcolor, originalTermNode.FunctionNode, originalTermNode.ImportantComments);
                return(true);
            }

            updatedTermNode = originalTermNode;
            return(false);
        }
        public override void Visit(TermNode node, IQueryVisitorContext context)
        {
            if (String.IsNullOrEmpty(node.Term))
            {
                return;
            }

            if (IsKnownAggregationType(node.Field))
            {
                node.SetOperationType(node.Field);
                node.Field = node.Term;
                node.Term  = null;
            }
        }
Ejemplo n.º 27
0
            public TermNode Append(TermNode t)
            {
                TermNode tail = this;
                TermNode next = nextNode;

                while (next != null) // get the last TermNode
                {
                    tail = next;
                    next = next.nextNode;
                }

                tail.nextNode = t;

                return(this);
            }
Ejemplo n.º 28
0
        public override async Task VisitAsync(TermNode node, IQueryVisitorContext context)
        {
            if (context.QueryType != QueryType.Query || !(context is IElasticQueryVisitorContext elasticContext) || !elasticContext.IsGeoPropertyType(node.Field))
            {
                return;
            }

            string location = _resolveGeoLocation != null ? await _resolveGeoLocation(node.Term).ConfigureAwait(false) ?? node.Term : node.Term;

            var query = new GeoDistanceQuery {
                Field = node.Field, Location = location, Distance = node.Proximity ?? Distance.Miles(10)
            };

            node.SetQuery(query);
        }
Ejemplo n.º 29
0
 public override void Visit(TermNode node, IQueryVisitorContext context)
 {
     if (!String.IsNullOrEmpty(node.Field))
     {
         AddField(node);
     }
     else
     {
         var nameParts = node.GetNameParts();
         if (nameParts.Length == 0)
         {
             _fields.Add("_all");
         }
     }
 }
 /// <summary>Assigns the length to horizontal or vertical value</summary>
 /// <param name="termNode">The term node</param>
 /// <param name="offset">The length to assign</param>
 /// <param name="sign">The sign of term</param>
 /// <param name="source">The unit of length</param>
 private void AssignXy(TermNode termNode, float?offset, int?sign, Source source)
 {
     if (this.XSource == null)
     {
         this.AssignX(termNode, offset, sign, source);
     }
     else if (this.YSource == null)
     {
         this.AssignY(termNode, offset, sign, source);
     }
     else
     {
         throw new ImageAssembleException(string.Format(CultureInfo.CurrentUICulture, CssStrings.TooManyLengthsError, termNode.PrettyPrint()));
     }
 }
Ejemplo n.º 31
0
        public IArithmeticNode Term()
        {
            IArithmeticNode firstOpNode = Factor();
            IArithmeticNode secondOpNode;
            IArithmeticNode termNode = new TermNode(TokenType.UNKNOWN, firstOpNode, null);

            while ((curTokenType == TokenType.MULT) ||
                    (curTokenType == TokenType.DIV) ||
                    (curTokenType == TokenType.POWER))
            {
                switch (curTokenType)
                {
                    case TokenType.MULT:
                        Match(ref matchToken, TokenType.MULT);
                        secondOpNode = Term();
                        termNode = new TermNode(TokenType.MULT, firstOpNode, secondOpNode);
                        break;
                    case TokenType.DIV:
                        Match(ref matchToken, TokenType.DIV);
                        secondOpNode = Term();
                        termNode = new TermNode(TokenType.DIV, firstOpNode, secondOpNode);
                        break;
                    case TokenType.POWER:
                        Match(ref matchToken, TokenType.POWER);
                        secondOpNode = Term();
                        termNode = new TermNode(TokenType.POWER, firstOpNode, secondOpNode);
                        break;
                    default:
                        Expect(TokenType.UNKNOWN, lookAheadToken);
                        termNode = new ErrorNode();
                        break;
                }
            }
            return termNode;
        }
Ejemplo n.º 32
0
 private bool Equals(TermNode other)
 {
     return string.Equals(this.Term, other.Term);
 }
 /// <summary>
 /// invariant for document update
 /// </summary>
 public void Add(Term term, DeleteSlice slice)
 {
     TermNode termNode = new TermNode(term);
     Add(termNode);
     /*
      * this is an update request where the term is the updated documents
      * delTerm. in that case we need to guarantee that this insert is atomic
      * with regards to the given delete slice. this means if two threads try to
      * update the same document with in turn the same delTerm one of them must
      * win. By taking the node we have created for our del term as the new tail
      * it is guaranteed that if another thread adds the same right after us we
      * will apply this delete next time we update our slice and one of the two
      * competing updates wins!
      */
     slice.SliceTail = termNode;
     Debug.Assert(slice.SliceHead != slice.SliceTail, "slice head and tail must differ after add");
     TryApplyGlobalSlice(); // TODO doing this each time is not necessary maybe
     // we can do it just every n times or so?
 }