예제 #1
0
        /// <summary>
        /// Recognizes a map item's initializer.
        /// </summary>
        /// <returns>A <see cref="MapItemInitializer"/></returns>
        protected MapItemInitializer MapItemInitializer()
        {
            Expression key = Expression();

            if (key == null)
            {
                return(null);
            }

            Match(TokenID.Arrow);
            var value = Required <Expression>(Expression, Resources.ExpressionRequired);

            var initializer = new MapItemInitializer(key, value);

            initializer.SetLocation(key.Start, value.End);
            return(initializer);
        }
예제 #2
0
        private void ProcessMapItemInitializer(XmlElement parent, MapItemInitializer initializer)
        {
            XmlElement tmpElement = document.CreateElement("MapItemInitializer");

            parent.AppendChild(tmpElement);

            XmlElement previousElement = currentElement;

            currentElement = document.CreateElement("Key");
            initializer.Key.AcceptCompiler(this);
            previousElement.AppendChild(currentElement);

            currentElement = document.CreateElement("Value");
            initializer.Value.AcceptCompiler(this);
            previousElement.AppendChild(currentElement);

            currentElement = previousElement;
        }
예제 #3
0
 private void DumpMapItemInitializer(MapItemInitializer itemInitializer)
 {
     itemInitializer.Key.AcceptCompiler(this);
     textWriter.Write(" => ");
     itemInitializer.Value.AcceptCompiler(this);
 }
예제 #4
0
        /// <summary>
        /// Recognizes expressions that start with a left brace.
        /// </summary>
        /// <returns>
        /// A <see cref="MapInitializer"/> or a <see cref="SetInitializer"/>
        /// </returns>
        protected Expression AtomStartingWithLBrace()
        {
            bool isSet    = false;
            var  mapItems = new MapItemInitializer[0];
            var  setItems = new Expression[0];

            Token first = Match(TokenID.LeftBrace);

            Expression e1 = Expression();

            if (e1 == null)
            {
                if (TryMatch(TokenID.Arrow))
                {
                    Consume(1);
                }
                else
                {
                    isSet = true;
                }
            }
            else
            {
                if (TryMatch(TokenID.Arrow))
                {
                    Consume(1);
                    var e2      = Required <Expression>(Expression, Resources.ExpressionRequired);
                    var tmpList = new List <MapItemInitializer> {
                        new MapItemInitializer(e1, e2)
                    };
                    if (TryMatch(TokenID.Comma))
                    {
                        Consume(1);
                        tmpList.AddRange(List <MapItemInitializer>(MapItemInitializer, false, null));
                    }
                    mapItems = tmpList.ToArray();
                }
                else
                {
                    isSet = true;
                    var tmpList = new List <Expression> {
                        e1
                    };
                    if (TryMatch(TokenID.Comma))
                    {
                        Consume(1);
                        tmpList.AddRange(List <Expression>(Expression, false, null));
                    }
                    setItems = tmpList.ToArray();
                }
            }

            Token last = Match(TokenID.RightBrace);

            Expression initializer = isSet
                                   ? new SetInitializer(setItems)
                                   : (Expression) new MapInitializer(mapItems);

            initializer.SetLocation(first.Start, last.End);
            return(initializer);
        }