📄 sgmldtd.cs
字号:
namespace FreeTextBoxControls.Support.Sgml
{
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Xml;
public class SgmlDtd
{
static SgmlDtd()
{
SgmlDtd.WhiteSpace = " \r\n\t";
SgmlDtd.ngterm = " \r\n\t|,)";
SgmlDtd.dcterm = " \r\n\t>";
SgmlDtd.cmterm = " \r\n\t,&|()?+*";
SgmlDtd.peterm = " \t\r\n>";
}
public SgmlDtd(string name, XmlNameTable nt)
{
this.nameTable = nt;
this.Name = name;
this.elements = new Hashtable();
this.pentities = new Hashtable();
this.entities = new Hashtable();
this.sb = new StringBuilder();
}
public ElementDecl FindElement(string name)
{
return (ElementDecl) this.elements[name.ToUpper()];
}
public Entity FindEntity(string name)
{
return (Entity) this.entities[name];
}
private Entity GetParameterEntity(string name)
{
Entity entity1 = (Entity) this.pentities[name];
if (entity1 == null)
{
this.current.Error("Reference to undefined parameter entity '{0}'", name);
}
return entity1;
}
private void Parse()
{
bool flag1;
char ch1 = this.current.Lastchar;
goto Label_0112;
Label_00FD:
this.current.Error("Unexpected character '{0}'", ch1);
Label_0111:;
Label_0112:
flag1 = true;
char ch2 = ch1;
if (ch2 <= ' ')
{
switch (ch2)
{
case '\t':
case '\n':
case '\r':
case ' ':
ch1 = this.current.ReadChar();
goto Label_0111;
case '\v':
case '\f':
goto Label_00FD;
}
goto Label_00FD;
}
switch (ch2)
{
case '%':
{
Entity entity1 = this.ParseParameterEntity(SgmlDtd.WhiteSpace);
try
{
this.PushEntity(this.current.ResolvedUri, entity1);
}
catch (Exception exception1)
{
Console.WriteLine(exception1.Message + this.current.Context());
}
ch1 = this.current.Lastchar;
goto Label_0111;
}
case '<':
this.ParseMarkup();
ch1 = this.current.ReadChar();
goto Label_0111;
}
if (ch2 != 0xffff)
{
goto Label_00FD;
}
this.PopEntity();
if (this.current == null)
{
return;
}
ch1 = this.current.Lastchar;
goto Label_0111;
}
public static SgmlDtd Parse(Uri baseUri, string name, string pubid, TextReader input, string subset, string proxy, XmlNameTable nt)
{
SgmlDtd dtd1 = new SgmlDtd(name, nt);
dtd1.PushEntity(baseUri, new Entity(dtd1.Name, baseUri, input, proxy));
if ((subset != null) && (subset != ""))
{
dtd1.PushEntity(baseUri, new Entity(name, subset));
}
try
{
dtd1.Parse();
}
catch (Exception exception1)
{
throw new Exception(exception1.Message + dtd1.current.Context());
}
return dtd1;
}
public static SgmlDtd Parse(Uri baseUri, string name, string pubid, string url, string subset, string proxy, XmlNameTable nt)
{
SgmlDtd dtd1 = new SgmlDtd(name, nt);
if ((url != null) && (url != ""))
{
dtd1.PushEntity(baseUri, new Entity(dtd1.Name, pubid, url, proxy));
}
if ((subset != null) && (subset != ""))
{
dtd1.PushEntity(baseUri, new Entity(name, subset));
}
try
{
dtd1.Parse();
}
catch (Exception exception1)
{
throw new Exception(exception1.Message + dtd1.current.Context());
}
return dtd1;
}
private AttDef ParseAttDef(char ch)
{
ch = this.current.SkipWhitespace();
string text1 = this.ScanName(SgmlDtd.WhiteSpace);
text1 = text1.ToUpper();
text1 = this.nameTable.Add(text1);
AttDef def1 = new AttDef(text1);
ch = this.current.SkipWhitespace();
if (ch == '-')
{
ch = this.ParseDeclComments();
}
this.ParseAttType(ch, def1);
ch = this.current.SkipWhitespace();
if (ch == '-')
{
ch = this.ParseDeclComments();
}
this.ParseAttDefault(ch, def1);
ch = this.current.SkipWhitespace();
if (ch == '-')
{
ch = this.ParseDeclComments();
}
return def1;
}
private void ParseAttDefault(char ch, AttDef attdef)
{
if (ch == '%')
{
Entity entity1 = this.ParseParameterEntity(SgmlDtd.WhiteSpace);
this.PushEntity(this.current.ResolvedUri, entity1);
this.ParseAttDefault(this.current.Lastchar, attdef);
this.PopEntity();
ch = this.current.Lastchar;
}
else
{
bool flag1 = true;
if (ch == '#')
{
this.current.ReadChar();
string text1 = this.current.ScanToken(this.sb, SgmlDtd.WhiteSpace, true);
flag1 = attdef.SetPresence(text1);
ch = this.current.SkipWhitespace();
}
if (flag1)
{
if ((ch == '\'') || (ch == '"'))
{
string text2 = this.current.ScanLiteral(this.sb, ch);
attdef.Default = text2;
ch = this.current.SkipWhitespace();
}
else
{
string text3 = this.current.ScanToken(this.sb, SgmlDtd.WhiteSpace, false);
text3 = text3.ToUpper();
text3 = this.nameTable.Add(text3);
attdef.Default = text3;
ch = this.current.SkipWhitespace();
}
}
}
}
private void ParseAttList()
{
char ch1 = this.current.SkipWhitespace();
string[] textArray1 = this.ParseNameGroup(ch1, true);
AttList list1 = new AttList();
this.ParseAttList(list1, '>');
foreach (string text1 in textArray1)
{
ElementDecl decl1 = (ElementDecl) this.elements[text1];
if (decl1 == null)
{
this.current.Error("ATTLIST references undefined ELEMENT {0}", text1);
}
decl1.AddAttDefs(list1);
}
}
private void ParseAttList(AttList list, char term)
{
for (char ch1 = this.current.SkipWhitespace(); ch1 != term; ch1 = this.current.SkipWhitespace())
{
if (ch1 == '%')
{
Entity entity1 = this.ParseParameterEntity(SgmlDtd.peterm);
this.PushEntity(this.current.ResolvedUri, entity1);
this.ParseAttList(list, 0xffff);
this.PopEntity();
ch1 = this.current.SkipWhitespace();
}
else if (ch1 == '-')
{
ch1 = this.ParseDeclComments();
}
else
{
AttDef def1 = this.ParseAttDef(ch1);
list.Add(def1);
}
}
}
private void ParseAttType(char ch, AttDef attdef)
{
if (ch == '%')
{
Entity entity1 = this.ParseParameterEntity(SgmlDtd.WhiteSpace);
this.PushEntity(this.current.ResolvedUri, entity1);
this.ParseAttType(this.current.Lastchar, attdef);
this.PopEntity();
ch = this.current.Lastchar;
}
else if (ch == '(')
{
attdef.EnumValues = this.ParseNameGroup(ch, false);
attdef.Type = AttributeType.ENUMERATION;
}
else
{
string text1 = this.ScanName(SgmlDtd.WhiteSpace);
if (text1 == "NOTATION")
{
ch = this.current.SkipWhitespace();
if (ch != '(')
{
this.current.Error("Expecting name group '(', but found '{0}'", ch);
}
attdef.Type = AttributeType.NOTATION;
attdef.EnumValues = this.ParseNameGroup(ch, true);
}
else
{
attdef.SetType(text1);
}
}
}
private ContentModel ParseContentModel(char ch)
{
ContentModel model1 = new ContentModel();
if (ch == '(')
{
this.current.ReadChar();
this.ParseModel(')', model1);
ch = this.current.ReadChar();
if (((ch == '?') || (ch == '+')) || (ch == '*'))
{
model1.AddOccurrence(ch);
this.current.ReadChar();
}
return model1;
}
if (ch == '%')
{
Entity entity1 = this.ParseParameterEntity(SgmlDtd.dcterm);
this.PushEntity(this.current.ResolvedUri, entity1);
model1 = this.ParseContentModel(this.current.Lastchar);
this.PopEntity();
return model1;
}
string text1 = this.ScanName(SgmlDtd.dcterm);
model1.SetDeclaredContent(text1);
return model1;
}
private char ParseDeclComment(bool full)
{
int num1 = this.current.Line;
char ch1 = this.current.ReadChar();
if (full && (ch1 != '-'))
{
this.current.Error("Expecting comment delimiter '--' but found {0}", ch1);
}
this.current.ScanToEnd(this.sb, "Markup Comment", "--");
return this.current.SkipWhitespace();
}
private char ParseDeclComments()
{
char ch1 = this.current.Lastchar;
while (ch1 == '-')
{
ch1 = this.ParseDeclComment(true);
}
return ch1;
}
private void ParseElementDecl()
{
char ch1 = this.current.SkipWhitespace();
string[] textArray1 = this.ParseNameGroup(ch1, true);
bool flag1 = char.ToLower(this.current.SkipWhitespace()) == 'o';
this.current.ReadChar();
bool flag2 = char.ToLower(this.current.SkipWhitespace()) == 'o';
this.current.ReadChar();
ch1 = this.current.SkipWhitespace();
ContentModel model1 = this.ParseContentModel(ch1);
ch1 = this.current.SkipWhitespace();
string[] textArray2 = null;
string[] textArray3 = null;
if (ch1 == '-')
{
ch1 = this.current.ReadChar();
if (ch1 == '(')
{
textArray2 = this.ParseNameGroup(ch1, true);
ch1 = this.current.SkipWhitespace();
}
else if (ch1 == '-')
{
ch1 = this.ParseDeclComment(false);
}
else
{
this.current.Error("Invalid syntax at '{0}'", ch1);
}
}
if (ch1 == '-')
{
ch1 = this.ParseDeclComments();
}
if (ch1 == '+')
{
ch1 = this.current.ReadChar();
if (ch1 != '(')
{
this.current.Error("Expecting inclusions name group", ch1);
}
textArray3 = this.ParseNameGroup(ch1, true);
ch1 = this.current.SkipWhitespace();
}
if (ch1 == '-')
{
ch1 = this.ParseDeclComments();
}
if (ch1 != '>')
{
this.current.Error("Expecting end of ELEMENT declaration '>' but found '{0}'", ch1);
}
foreach (string text1 in textArray1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -