/// <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); }
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; }
private void DumpMapItemInitializer(MapItemInitializer itemInitializer) { itemInitializer.Key.AcceptCompiler(this); textWriter.Write(" => "); itemInitializer.Value.AcceptCompiler(this); }
/// <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); }