Exemple #1
0
 private static void Fill(InlineCollection inlines, ElementToken token, Hint hint)
 {
     foreach (var t in token.Tokens)
     {
         inlines.Add(GetInline(t, hint));
     }
 }
Exemple #2
0
        private static Inline BuildFont(ElementToken token, Hint hint)
        {
            var span = new Span();

            if (token.Attributes.TryGetValue("size", out var size))
            {
                var fc = new FontSizeConverter();
                var sz = (double)fc.ConvertFromString(size);
                span.FontSize = sz;
            }

            if (token.Attributes.TryGetValue("face", out var face))
            {
                span.FontFamily = new FontFamily(face);
            }

            if (token.Attributes.TryGetValue("color", out var color))
            {
                var bc = new BrushConverter();
                var br = (Brush)bc.ConvertFromString(color);
                span.Foreground = br;
            }

            return(span.Fill(token, hint));
        }
Exemple #3
0
        public override Token ExtractToken()
        {
            SkipWhitespace();
            Token token       = null;
            char  currentChar = CurrentChar;

            if (currentChar.IsEOF())
            {
                token = new EofToken(Source);
            }
            else if (currentChar == 'w' && Source.PeekChar == ':')
            {
                token = new ElementToken(Source);
            }
            else if (currentChar.IsLetter())
            {
                token = new WordToken(Source);
            }
            else if (currentChar == '"')
            {
                token = new StringToken(Source);
            }
            else if (currentChar.IsSymbol())
            {
                token = new SymbolToken(Source);
            }
            else
            {
                token = new Token(Source);
            }

            return(token);
        }
Exemple #4
0
 /// <summary>
 /// This method is used to extend DefaultFilterRules with our own implementation allowing width and height to be used on the image element
 /// </summary>
 /// <param name="element">The element</param>
 /// <returns></returns>
 public static IEnumerable <AttributeToken> GetAttributesForElement(ElementToken element)
 {
     if (element == ElementToken.Img)
     {
         return(new AttributeToken[] { AttributeToken.Width, AttributeToken.Height });
     }
     return(Enumerable.Empty <AttributeToken>());
 }
Exemple #5
0
        private static Inline BuildSymbol(ElementToken token, Hint hint)
        {
            string spanClass = token.Attributes["span-class"];
            string value     = token.Text;

            return(new Run(value)
            {
                Foreground = hint.MapBrush(spanClass)
            });
        }
        public override string ToCode()
        {
            StringBuilder buf = new StringBuilder();

            buf.Append(getStmtPrefix());
            buf.AppendFormat("循环每一个( {0},{1} , {2} )", this.ListExp.ToCode(), ElementToken.ToCode(), IndexToken != null?("," + IndexToken.GetText()):"");
            buf.AppendLine();
            buf.Append(Body.ToString());
            return(buf.ToString());
        }
Exemple #7
0
        private static Inline BuildParam(ElementToken token, Hint hint)
        {
            var pp = new ParamPanel();

            foreach (ParseToken pt in token.Tokens)
            {
                var et = pt as ElementToken;
                if (et != null)
                {
                    var tb = new TextBlock().Fill(et, hint);
                    pp.Children.Add(tb);
                    if (et.Name == "pname")
                    {
                        ParamPanel.SetNameColumn(tb, true);
                    }

                    continue;
                }

                var tt = pt as TextToken;
                if (tt != null && pp.Children.Count > 0)
                {
                    var elem = pp.Children[pp.Children.Count - 1] as TextBlock;
                    if (elem != null)
                    {
                        elem.Inlines.Add(GetInline(tt, hint));
                    }

                    continue;
                }
            }

            var span = new Span();

            span.Inlines.Add(new SoftBreak());
            span.Inlines.Add(new InlineUIContainer
            {
                Child             = pp,
                BaselineAlignment = BaselineAlignment.Bottom
            });
            span.Inlines.Add(new SoftBreak());
            return(span);
        }
Exemple #8
0
        private static Inline BuildRef(ElementToken token, Hint hint)
        {
            string handler;

            token.Attributes.TryGetValue("handler", out handler);

            string hintStr;

            token.Attributes.TryGetValue("hint", out hintStr);
            if (hintStr != null)
            {
                hintStr = "<code>" + hintStr + "</code>";
            }
            var hc = new HintControl(hintStr, handler);

            Fill(hc.Inlines, token, hint);
            return(new InlineUIContainer {
                Child = hc
            });
        }
Exemple #9
0
        private static Inline BuildHint(ElementToken token, Hint hint)
        {
            Trace.Assert(token.Name == "hint");

            string handler;

            token.Attributes.TryGetValue("handler", out handler);

            string key;

            token.Attributes.TryGetValue("key", out key);

            string value = token.Attributes["value"];

            var hc = key == null ? new HintControl(token.ToString(), handler)
                           : new HintControl(key, hint.RaiseGetHintContent, handler);

            //Fill(hc.Inlines, token);
            hc.Inlines.Add(new Run(value));
            return(new InlineUIContainer {
                Child = hc
            });
        }
Exemple #10
0
        private static Inline BuildSymbolHint(ElementToken token, Hint hint)
        {
            Trace.Assert(token.Name == "symbol");

            string handler;

            token.Attributes.TryGetValue("handler", out handler);

            string key       = token.Attributes["id"];
            string spanClass = token.Attributes["span-class"];

            string value = token.Text;

            var hc = new HintControl(key, hint.RaiseGetHintContent, handler);

            hc.Inlines.Add(new Run(value)
            {
                Foreground = hint.MapBrush(spanClass)
            });
            return(new InlineUIContainer {
                Child = hc
            });
        }
Exemple #11
0
 private static TextBlock Fill(this TextBlock tb, ElementToken token, Hint hint)
 {
     Fill(tb.Inlines, token, hint);
     return(tb);
 }
Exemple #12
0
 private static Span Fill(this Span span, ElementToken token, Hint hint)
 {
     Fill(span.Inlines, token, hint);
     return(span);
 }
        public override void Analy(AnalyStmtContext context)
        {
            //base.LoadRefTypes(context);
            int foreachIndex = context.MethodContext.CreateForeachIndex();

            if (ListExp == null)
            {
                error("'循环每一个语句'不存在要循环的列表");
            }
            if (ElementToken == null)
            {
                error("'循环每一个语句'不存在成员名称");
            }
            if (ListExp == null || ElementToken == null)
            {
                return;
            }

            this.AnalyStmtContext = context;
            var symbols = context.Symbols;

            ListExp = AnalyExp(ListExp);

            if (ListExp == null)
            {
                TrueAnalyed = false;
                return;
            }
            if (ListExp.RetType == null)
            {
                TrueAnalyed = false;
                return;
            }
            else if (!canForeach(ListExp.RetType))
            {
                error(ListExp.Postion, "该结果不能用作循环每一个");
                return;
            }

            if (ReflectionUtil.IsExtends(ListExp.RetType, typeof(列表 <>)))
            {
                startIndex    = 1;
                compareMethod = typeof(Calculater).GetMethod("LEInt", new Type[] { typeof(int), typeof(int) });
            }
            else
            {
                startIndex    = 0;
                compareMethod = typeof(Calculater).GetMethod("LTInt", new Type[] { typeof(int), typeof(int) });
            }

            //PropertyInfo countProperty = ListExp.RetType.GetProperty("Count");
            ExPropertyInfo countProperty = GclUtil.SearchExProperty("Count", ListExp.RetType);

            getCountMethod = new ExMethodInfo(countProperty.Property.GetGetMethod(), countProperty.IsSelf);
            //PropertyInfo itemProperty = ListExp.RetType.GetProperty("Item");
            ExPropertyInfo itemProperty = GclUtil.SearchExProperty("Item", ListExp.RetType);

            diMethod = new ExMethodInfo(itemProperty.Property.GetGetMethod(), itemProperty.IsSelf);

            elementName = ElementToken.GetText();

            if (IndexToken != null)
            {
                indexName = IndexToken.GetText();
            }
            else
            {
                indexName = "$$$foreach_" + foreachIndex + "_index";
            }
            createForeachSymbols(context, symbols, foreachIndex, ListExp.RetType);
            analySubStmt(Body);
        }
        internal void Push(Token token)
        {
            int wordtype;
            switch (token.Type)
            {
                case TokenType.Number:
                case TokenType.Boolean:
                    wordtype = (int)TokenType.String;
                    break;

                default:
                    wordtype = (int)token.Type;
                    break;
            }

            var action = _action[_stateStack[_stateStack.Count - 1]][wordtype];
            if (action == null)
            {
                IsLoopingForReduce = false;
                throw new ParseException($"Grammar error at line {token.Line}");
            }
            else if (action[0] == 'A')
            {
                IsAccepted = true;
                IsLoopingForReduce = false;
                switch (action[1])
                {
                    case '1'://ACC for elements
                        var blocktype = (BlockTypes)System.Enum.Parse(typeof(BlockTypes), _tokenStack[1].Value);
                        _blockToken = new BlockToken(blocktype, _tokenStack[_tokenStack.Count - 1] as ElementToken);
                        break;

                    case '2'://ACC for settings
                        _blockToken = new BlockToken(_tokenStack[_tokenStack.Count - 1] as AttributeToken);
                        break;

                    case '3'://ACC for content
                        _blockToken = new BlockToken(_tokenStack[_tokenStack.Count - 1].Value);
                        break;
                }
                Block = new Block(_blockToken);
            }
            else if (action[0] == 'S')
            {
                var statestring = "";
                for (var i = 1; i < action.Length; i++)
                {
                    statestring += action[i];
                }
                var nextstate = int.Parse(statestring);
                _stateStack.Add(nextstate);
                _tokenStack.Add(token);
                IsLoopingForReduce = false;
            }
            else
            {
                IsLoopingForReduce = true;
                var reducestring = "";
                for (var i = 1; i < action.Length; i++)
                {
                    reducestring += action[i];
                }
                var reducerule = int.Parse(reducestring);
                switch (reducerule)
                {
                    //case 1:// Block -> Type Bracket Elements Bracket
                    //    break;
                    //case 2:// Block -> Settings
                    //    break;
                    //case 3:// Block -> Content
                    //    break;
                    case 4:// Elements -> Element
                        _stateStack[_stateStack.Count - 1] = _goto[_stateStack[_stateStack.Count - 2]][2];
                        break;

                    case 5:// Elements -> Elements Element
                        var nextele = _tokenStack[_tokenStack.Count - 1] as ElementToken;
                        var preele = _tokenStack[_tokenStack.Count - 2] as ElementToken;
                        Debug.Assert(nextele != null, "nextele != null");
                        nextele.Next = preele;
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(nextele);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][2]);
                        break;

                    case 6:// Element -> Sharp Ename Equals Value Break
                        var eName = _tokenStack[_tokenStack.Count - 4].Value;
                        var eType = (ElementTypes)System.Enum.Parse(typeof(ElementTypes), eName);
                        var setele = new ElementToken(_tokenStack[_tokenStack.Count - 5].Line, eType, _tokenStack[_tokenStack.Count - 2].Value);
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(setele);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][3]);
                        break;

                    case 7:// Element -> EName Bracket Atts Bracket
                        var elementName = _tokenStack[_tokenStack.Count - 4].Value;
                        var elementType = (ElementTypes)System.Enum.Parse(typeof(ElementTypes), elementName);
                        var atts = _tokenStack[_tokenStack.Count - 2] as AttributeToken;
                        Debug.Assert(atts != null, "atts != null");
                        var element = new ElementToken(atts.Line, elementType, atts);
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(element);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][3]);
                        break;

                    case 8:// Settings -> Setting
                        _stateStack[_stateStack.Count - 1] = _goto[_stateStack[_stateStack.Count - 2]][0];
                        break;

                    case 9:// Settings -> Settings Setting
                        var nextset = _tokenStack[_tokenStack.Count - 1] as AttributeToken;
                        var preset = _tokenStack[_tokenStack.Count - 2] as AttributeToken;
                        Debug.Assert(nextset != null, "nextset != null");
                        nextset.Next = preset;
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(nextset);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][0]);
                        break;
                    //case 10:// Content -> USD Value Break
                    //    break;
                    case 11:// Setting -> Sharp Att
                        _tokenStack.RemoveAt(_tokenStack.Count - _popCount[reducerule - 1]);
                        _stateStack.RemoveAt(_stateStack.Count - _popCount[reducerule - 1]);
                        _stateStack[_stateStack.Count - 1] = _goto[_stateStack[_stateStack.Count - 2]][1];
                        break;

                    case 12:// Atts -> Att
                        _stateStack[_stateStack.Count - 1] = _goto[_stateStack[_stateStack.Count - 2]][4];
                        break;

                    case 13:// Atts -> Atts Att
                        var nextatt = _tokenStack[_tokenStack.Count - 1] as AttributeToken;
                        var preatt = _tokenStack[_tokenStack.Count - 2] as AttributeToken;
                        Debug.Assert(nextatt != null, "nextatt != null");
                        nextatt.Next = preatt;
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(nextatt);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][4]);
                        break;

                    case 14:// Att -> Name Equals Value Break
                        AttributeValueType valueType = AttributeValueType.String;
                        switch (_tokenStack[_tokenStack.Count - 2].Type)
                        {
                            case TokenType.Number:
                                valueType = AttributeValueType.Number;
                                break;

                            case TokenType.Boolean:
                                valueType = AttributeValueType.Boolean;
                                break;
                        }
                        AttributeTypes attType = (AttributeTypes)System.Enum.Parse(typeof(AttributeTypes), _tokenStack[_tokenStack.Count - 4].Value);
                        AttributeToken att = new AttributeToken
                            (
                                _tokenStack[_tokenStack.Count - 2].Line,
                                attType,
                                _tokenStack[_tokenStack.Count - 2].Value,
                                valueType
                            );
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(att);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][5]);
                        break;
                }
            }
        }
	private Expression OnElement( Expression contentModel, Expression[] atoms ) {
		contentModel = VerifyText(contentModel,atoms);
		
		Trace.WriteLine("<"+document.Name+">");
		Trace.Indent();
		Trace.WriteLine("expecting: "+ ExpPrinter.printContentModel(contentModel));
		
		ElementExp[] match = ContentModelCollector.Collect(
			contentModel, new XmlName(document.NamespaceURI,document.LocalName) );
		
		if(match[0]==null) {
			// error: unexpected element
			ReportError(ERR_UNEXPECTED_ELEMENT,document.Name);
		}
		
		Expression combinedChild = Expression.NotAllowed;
		int i;
		for( i=0; match[i]!=null; i++ )
			combinedChild = builder.CreateChoice( combinedChild, match[i].exp );
		int clen = i;
		
		Expression[] cp = null;
		if(clen>1) {
			Trace.WriteLine(string.Format("{0} elements are matched",clen));
			cp = new Expression[clen];
			for( i=0; i<clen; i++ )
				cp[i] = match[i].exp;
		}

		Trace.WriteLine("combined child: "+
			ExpPrinter.printContentModel(combinedChild));

		if(document.MoveToFirstAttribute())
			do {
				combinedChild = OnAttribute( combinedChild, cp );
			} while( document.MoveToNextAttribute() );
		
		document.MoveToElement();
		
		combinedChild = attPruner.prune(combinedChild);
		if(combinedChild==Expression.NotAllowed) {
			// error: required attribute is missing
			// TODO: name of required attributes
			ReportError(ERR_MISSING_ATTRIBUTE);
		}
			
		if( !document.IsEmptyElement ) {
			document.ReadStartElement();
			combinedChild = Verify(combinedChild,cp);
			combinedChild = VerifyText(combinedChild,cp);
			Trace.Unindent();
			Trace.WriteLine("</"+document.Name+">");
		} else {
			// treat it as ""
			combinedChild = VerifyText(combinedChild,cp);
			Trace.Unindent();
			Trace.WriteLine("</"+document.Name+">");
		}
		
		if( !combinedChild.IsNullable ) {
			// error: unexpected end of element.
			ReportError( ERR_CONTENTMODEL_INCOMPLETE, document.Name );
		}
		
		document.Read();	// read the end tag.
		
		
		if(cp!=null)
			for( i=0; i<clen; i++ )
				if(!cp[i].IsNullable)
					match[i]=null;
		
		ElementToken e = new ElementToken(match,clen);
		if(atoms!=null)
			for( i=0; i<atoms.Length; i++ )
				atoms[i] = Residual.Calc(atoms[i],e,builder);
		
		contentModel = Residual.Calc(contentModel,e,builder);
		Trace.WriteLine("residual: " + ExpPrinter.printContentModel(contentModel));
		return contentModel;
	}
 internal Element(ElementToken item)
 {
     ElementType = item.ElementType;
     Line = item.Line;
     AttributeList = new Attribute(item.AttributeList);
     if (item.Next != null)
     {
         Next = new Element(item.Next);
     }
 }