当前位置: 首页>>代码示例>>C#>>正文


C# Lexer.GetToken方法代码示例

本文整理汇总了C#中TidyNet.Lexer.GetToken方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.GetToken方法的具体用法?C# Lexer.GetToken怎么用?C# Lexer.GetToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TidyNet.Lexer的用法示例。


在下文中一共展示了Lexer.GetToken方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: parseXMLDocument

		public static Node parseXMLDocument(Lexer lexer)
		{
			Node node, document, doctype;
			
			document = lexer.NewNode();
			document.Type = Node.RootNode;
			doctype = null;
			lexer.Options.XmlTags = true;
			
			while (true)
			{
				node = lexer.GetToken(Lexer.IgnoreWhitespace);
				if (node == null)
				{
					break;
				}

				/* discard unexpected end tags */
				if (node.Type == Node.EndTag)
				{
					Report.Warning(lexer, null, node, Report.UNEXPECTED_ENDTAG);
					continue;
				}
				
				/* deal with comments etc. */
				if (Node.InsertMisc(document, node))
				{
					continue;
				}
				
				if (node.Type == Node.DocTypeTag)
				{
					if (doctype == null)
					{
						Node.InsertNodeAtEnd(document, node);
						doctype = node;
					}
					else
					{
						Report.Warning(lexer, document, node, Report.DISCARDING_UNEXPECTED);
					}
					// TODO
					continue;
				}
				
				/* if start tag then parse element's content */
				if (node.Type == Node.StartTag)
				{
					Node.InsertNodeAtEnd(document, node);
					parseXMLElement(lexer, node, Lexer.IgnoreWhitespace);
				}
			}
			
			if (doctype != null && !lexer.CheckDocTypeKeyWords(doctype))
			{
				Report.Warning(lexer, doctype, null, Report.DTYPE_NOT_UPPER_CASE);
			}
			
			/* ensure presence of initial <?XML version="1.0"?> */
			if (lexer.Options.XmlPi)
			{
				lexer.FixXmlPI(document);
			}
			
			return document;
		}
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:66,代码来源:ParserImpl.cs

示例2: parseDocument

		/*
		HTML is the top level element
		*/
		public static Node parseDocument(Lexer lexer)
		{
			Node node, document, html;
			Node doctype = null;
			TagTable tt = lexer.Options.tt;

			document = lexer.NewNode();
			document.Type = Node.RootNode;
			
			while (true)
			{
				node = lexer.GetToken(Lexer.IgnoreWhitespace);
				if (node == null)
				{
					break;
				}
				
				/* deal with comments etc. */
				if (Node.InsertMisc(document, node))
				{
					continue;
				}
				
				if (node.Type == Node.DocTypeTag)
				{
					if (doctype == null)
					{
						Node.InsertNodeAtEnd(document, node);
						doctype = node;
					}
					else
					{
						Report.Warning(lexer, document, node, Report.DISCARDING_UNEXPECTED);
					}
					continue;
				}
				
				if (node.Type == Node.EndTag)
				{
					Report.Warning(lexer, document, node, Report.DISCARDING_UNEXPECTED); //TODO?
					continue;
				}
				
				if (node.Type != Node.StartTag || node.Tag != tt.TagHtml)
				{
					lexer.UngetToken();
					html = lexer.InferredTag("html");
				}
				else
				{
					html = node;
				}
				
				Node.InsertNodeAtEnd(document, html);
				ParseHTML.Parse(lexer, html, (short) 0); // TODO?
				break;
			}
			
			return document;
		}
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:63,代码来源:ParserImpl.cs

示例3: parseXMLElement

		/*
		XML documents
		*/
		public static void  parseXMLElement(Lexer lexer, Node element, short mode)
		{
			Node node;
			
			/* Jeff Young's kludge for XSL docs */
			if (String.Compare(element.Element, "xsl:text") == 0)
			{
				return;
			}
			
			/* if node is pre or has xml:space="preserve" then do so */
			
			if (XMLPreserveWhiteSpace(element, lexer.Options.tt))
			{
				mode = Lexer.Preformatted;
			}
			
			while (true)
			{
				node = lexer.GetToken(mode);
				if (node == null)
				{
					break;
				}
				if (node.Type == Node.EndTag && node.Element.Equals(element.Element))
				{
					element.Closed = true;
					break;
				}
				
				/* discard unexpected end tags */
				if (node.Type == Node.EndTag)
				{
					Report.Error(lexer, element, node, Report.UNEXPECTED_ENDTAG);
					continue;
				}
				
				/* parse content on seeing start tag */
				if (node.Type == Node.StartTag)
				{
					parseXMLElement(lexer, node, mode);
				}
				
				Node.InsertNodeAtEnd(element, node);
			}
			
			/*
			if first child is text then trim initial space and
			delete text node if it is empty.
			*/
			
			node = element.Content;
			
			if (node != null && node.Type == Node.TextNode && mode != Lexer.Preformatted)
			{
				if (node.Textarray[node.Start] == (sbyte) ' ')
				{
					node.Start++;
					
					if (node.Start >= node.End)
					{
						Node.DiscardElement(node);
					}
				}
			}
			
			/*
			if last child is text then trim final space and
			delete the text node if it is empty
			*/
			
			node = element.Last;
			
			if (node != null && node.Type == Node.TextNode && mode != Lexer.Preformatted)
			{
				if (node.Textarray[node.End - 1] == (sbyte) ' ')
				{
					node.End--;
					
					if (node.Start >= node.End)
					{
						Node.DiscardElement(node);
					}
				}
			}
		}
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:89,代码来源:ParserImpl.cs

示例4: Parse

			public virtual void Parse(Lexer lexer, Node field, short mode)
			{
				Node node;
				TagTable tt = lexer.Options.tt;
				
				lexer.insert = - 1; /* defer implicit inline start tags */
				
				if (field.Tag == tt.TagTextarea)
					mode = Lexer.Preformatted;
				
				while (true)
				{
					node = lexer.GetToken(mode);
					if (node == null)
						break;
					if (node.Tag == field.Tag && node.Type == Node.EndTag)
					{
						field.Closed = true;
						Node.TrimSpaces(lexer, field);
						return;
					}
					
					/* deal with comments etc. */
					if (Node.InsertMisc(field, node))
						continue;
					
					if (node.Type == Node.TextNode)
					{
						/* only called for 1st child */
						if (field.Content == null && !((mode & Lexer.Preformatted) != 0))
							Node.TrimSpaces(lexer, field);
						
						if (node.Start >= node.End)
						{
							continue;
						}
						
						Node.InsertNodeAtEnd(field, node);
						continue;
					}
					
					if (node.Tag == tt.TagFont)
					{
						Report.Warning(lexer, field, node, Report.DISCARDING_UNEXPECTED);
						continue;
					}
					
					/* terminate element on other tags */
					if (!((field.Tag.Model & ContentModel.Opt) != 0))
						Report.Warning(lexer, field, node, Report.MISSING_ENDTAG_BEFORE);
					
					lexer.UngetToken();
					Node.TrimSpaces(lexer, field);
					return;
				}
				
				if (!((field.Tag.Model & ContentModel.Opt) != 0))
					Report.Warning(lexer, field, node, Report.MISSING_ENDTAG_FOR);
			}
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:59,代码来源:ParserImpl.cs


注:本文中的TidyNet.Lexer.GetToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。