用戶:A2569875-bot/Code/WikiParsingDatatype.cs
外觀
using System;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using WikiTemplateArgUtil;
namespace DotNetWikiBot
{
public class ParsedWikiText
{
public TreeNode<ParsingTreeNode> parsing_tree;
public string orginal_text;
public WikiText parsed_result;
public ParsedWikiText(string input)
{
orginal_text = input;
}
public void Parse()
{
parsing_tree = wikitext_util.ParseCode(orginal_text);
parsed_result = new WikiText(parsing_tree);
}
}
public class WikiTokenData
{
public String Value;
public String fullText;
public int token_pos;
public String TokenType;
public XElement XmlTokenData;
public WikiTokenData(String val, String tp)
{
Value = val;
TokenType = tp;
XmlTokenData = null;
}
public void check_xml()
{
try
{
XmlTokenData = XElement.Parse(Value);
}
catch
{
XmlTokenData = null;
}
}
public override string ToString()
{
return Value;
}
}
public class ParsingTreeNode
{
public bool is_terminal;
public TokenSymobl symbol;
public String Value;
public String fullText;
public int token_pos;
public ParsingTreeNode(TokenSymobl s)
{
is_terminal = false;
Value = "";
symbol = s;
}
public ParsingTreeNode(TokenSymobl s, string val)
{
is_terminal = true;
Value = val;
symbol = s;
}
public ParsingTreeNode(TokenSymobl s, WikiTokenData data)
{
is_terminal = true;
Value = data.Value;
fullText = data.fullText;
token_pos = data.token_pos;
symbol = s;
}
public override string ToString()
{
if (is_terminal) return Value;
else return symbol.ToString();
}
}
public class LR_StackItem
{
public bool is_symbol;
public int stack;
public TokenSymobl symbol;
string value;
public override string ToString()
{
if (is_symbol)
return symbol.ToString();
else
return stack.ToString();
}
public LR_StackItem(TokenSymobl s)
{
is_symbol = true;
stack = -1;
symbol = s;
value = "";
}
public LR_StackItem(WikiTokenData s)
{
is_symbol = true;
stack = -1;
value = s.Value;
symbol = new TokenSymobl(s);
}
public LR_StackItem(int s)
{
is_symbol = false;
stack = s;
symbol = null;
value = "";
}
public enum LR_Action
{
None,
Shift,
Reduce
}
}
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[Serializable]
public class ParsingException : Exception
{
/// <exclude/>
public ParsingException() { }
/// <exclude/>
public ParsingException(string msg) : base(msg)
{
}
/// <exclude/>
public ParsingException(string msg, System.Exception inner) : base(msg, inner) { }
/// <exclude/>
protected ParsingException(System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
/// <exclude/>
~ParsingException() { }
}