本文整理汇总了C#中IParseContext类的典型用法代码示例。如果您正苦于以下问题:C# IParseContext类的具体用法?C# IParseContext怎么用?C# IParseContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IParseContext类属于命名空间,在下文中一共展示了IParseContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PushChar
public override State PushChar (char c, IParseContext context, ref string rollback)
{
if (context.CurrentStateLength == 1) {
context.Nodes.Push (new XProcessingInstruction (context.LocationMinus ("<?".Length)));
}
if (c == '?') {
if (context.StateTag == NOMATCH) {
context.StateTag = QUESTION;
return null;
}
} else if (c == '>' && context.StateTag == QUESTION) {
// if the '?' is followed by a '>', the state has ended
// so attach a node to the DOM and end the state
XProcessingInstruction xpi = (XProcessingInstruction) context.Nodes.Pop ();
if (context.BuildTree) {
xpi.End (context.Location);
((XContainer) context.Nodes.Peek ()).AddChildNode (xpi);
}
return Parent;
} else {
context.StateTag = NOMATCH;
}
return null;
}
示例2: PushChar
public override State PushChar (char c, IParseContext context, ref string rollback)
{
if (context.CurrentStateLength == 0)
context.StateTag = 0;
if (c == '<') {
if (context.StateTag == 0) {
context.StateTag++;
return null;
}
}
if (context.StateTag > 0) {
if (CLOSE[context.StateTag] == c) {
context.StateTag++;
if (context.StateTag == CLOSE.Length) {
var el = (XElement) context.Nodes.Pop ();
var closing = new XClosingTag (new XName ("script"), context.LocationMinus (CLOSE.Length));
closing.End (context.Location);
el.Close (closing);
return Parent;
}
} else {
context.StateTag = 0;
}
}
return null;
}
示例3: ParseMethodCall
protected override IParseContext ParseMethodCall(ExpressionParser parser, IParseContext parent, MethodCallExpression methodCall, SqlQuery sqlQuery)
{
var sequence = parser.ParseSequence(parent, methodCall.Arguments[0], sqlQuery);
var defaultValue = methodCall.Arguments.Count == 1 ? null : methodCall.Arguments[1].Unwrap();
return new DefaultIfEmptyContext(sequence, defaultValue);
}
示例4: PushChar
public override State PushChar (char c, IParseContext context, ref string rollback)
{
if (context.CurrentStateLength == 1) {
context.Nodes.Push (new XCData (context.LocationMinus ("<![CDATA[".Length + 1)));
}
if (c == ']') {
//make sure we know when there are two ']' chars together
if (context.StateTag == NOMATCH)
context.StateTag = SINGLE_BRACKET;
else
context.StateTag = DOUBLE_BRACKET;
} else if (c == '>' && context.StateTag == DOUBLE_BRACKET) {
// if the ']]' is followed by a '>', the state has ended
// so attach a node to the DOM and end the state
XCData cdata = (XCData) context.Nodes.Pop ();
if (context.BuildTree) {
cdata.End (context.Location);
((XContainer) context.Nodes.Peek ()).AddChildNode (cdata);
}
return Parent;
} else {
// not any part of a ']]>', so make sure matching is reset
context.StateTag = NOMATCH;
}
return null;
}
示例5: AddExpressionNode
internal static void AddExpressionNode (char c, IParseContext context)
{
Debug.Assert (c != '@' && c!= '-', "AspNetExpressionState should not be passed a directive or comment");
switch (c) {
//DATABINDING EXPRESSION <%#
case '#':
context.Nodes.Push (new AspNetDataBindingExpression (context.LocationMinus (3)));
break;
//RESOURCE EXPRESSION <%$
case '$':
context.Nodes.Push (new AspNetResourceExpression (context.LocationMinus (3)));
break;
//RENDER EXPRESSION <%=
case '=':
context.Nodes.Push (new AspNetRenderExpression (context.LocationMinus (3)));
break;
//HTML ENCODED EXPRESSION <%:
case ':':
context.Nodes.Push (new AspNetHtmlEncodedExpression (context.LocationMinus (3)));
break;
// RENDER BLOCK
default:
context.Nodes.Push (new AspNetRenderBlock (context.LocationMinus (3)));
break;
}
}
示例6: PushChar
public override State PushChar (char c, IParseContext context, ref string rollback)
{
System.Diagnostics.Debug.Assert (((XAttribute) context.Nodes.Peek ()).Value == null);
if (c == '<') {
//the parent state should report the error
rollback = string.Empty;
return Parent;
}
if (context.CurrentStateLength == 1) {
if (c == '\'' || c == '"') {
context.StateTag = c;
return null;
}
context.StateTag = '\0';
} else if (context.StateTag == '\0') {
return BuildUnquotedValue (c, context, ref rollback);
}
if (c == context.StateTag) {
//ending the value
var att = (XAttribute) context.Nodes.Peek ();
att.Value = context.KeywordBuilder.ToString ();
return Parent;
}
context.KeywordBuilder.Append (c);
return null;
}
示例7: PushChar
public override State PushChar (char c, IParseContext context, ref string rollback)
{
if (context.CurrentStateLength == 1) {
AddExpressionNode (c, context);
}
else if (c == '%') {
context.StateTag = PERCENT;
}
else if (c == '>') {
if (context.StateTag == PERCENT) {
XNode expr = (XNode) context.Nodes.Pop ();
expr.End (context.Location);
if (context.BuildTree) {
XObject ob = context.Nodes.Peek ();
var xc = ob as XContainer;
if (xc != null) {
xc.AddChildNode (expr);
}
//FIXME: add to other kinds of node, e.g. if used within a tag
}
return Parent;
} else {
context.StateTag = NONE;
}
}
return null;
}
示例8: PushChar
public override State PushChar (char c, IParseContext context, ref string rollback)
{
System.Diagnostics.Debug.Assert (((XAttribute) context.Nodes.Peek ()).Value == null);
if (c == '<') {
//the parent state should report the error
rollback = string.Empty;
return Parent;
} else if (c == '>' && context.KeywordBuilder.Length > 0) {
string fullName = ((XAttribute) context.Nodes.Peek ()).Name.FullName;
context.LogError ("The value of attribute '" + fullName + "' ended unexpectedly.");
rollback = string.Empty;
return Parent;
} else if (char.IsLetterOrDigit (c) || c == '_' || c == '.') {
context.KeywordBuilder.Append (c);
return null;
} else if (char.IsWhiteSpace (c) || c == '>' || c == '\\') {
//ending the value
XAttribute att = (XAttribute) context.Nodes.Peek ();
att.Value = context.KeywordBuilder.ToString ();
} else {
//MalformedTagState handles error reporting
//context.LogWarning ("Unexpected character '" + c + "' getting attribute value");
return MalformedTagState;
}
rollback = string.Empty;
return Parent;
}
示例9: PushChar
public override State PushChar (char c, IParseContext context, ref string rollback)
{
//NOTE: This is (mostly) duplicated in HtmlTagState
//handle inline tags implicitly closed by block-level elements
if (context.CurrentStateLength == 1 && context.PreviousState is XmlNameState)
{
XClosingTag ct = (XClosingTag) context.Nodes.Peek ();
if (!ct.Name.HasPrefix && ct.Name.IsValid) {
//Note: the node stack will always be at least 1 deep due to the XDocument
var parent = context.Nodes.Peek (1) as XElement;
//if it's not a matching closing tag
if (parent != null && !string.Equals (ct.Name.Name, parent.Name.Name, StringComparison.OrdinalIgnoreCase)) {
//attempt to implicitly close the parents
while (parent != null && parent.ValidAndNoPrefix () && parent.IsImplicitlyClosedBy (ct)) {
context.Nodes.Pop ();
context.Nodes.Pop ();
if (warnAutoClose) {
context.LogWarning (string.Format ("Tag '{0}' implicitly closed by closing tag '{1}'.",
parent.Name.Name, ct.Name.Name), parent.Region);
}
//parent.Region.End = element.Region.Start;
//parent.Region.EndColumn = Math.Max (parent.Region.EndColumn - 1, 1);
parent.Close (parent);
context.Nodes.Push (ct);
parent = context.Nodes.Peek (1) as XElement;
}
}
}
}
return base.PushChar (c, context, ref rollback);
}
示例10: ParseSkip
static void ParseSkip(ExpressionParser parser, IParseContext sequence, ISqlExpression prevSkipValue, ISqlExpression expr)
{
var sql = sequence.SqlQuery;
parser.SqlProvider.SqlQuery = sql;
sql.Select.Skip(expr);
parser.SqlProvider.SqlQuery = sql;
if (sql.Select.TakeValue != null)
{
if (parser.SqlProvider.IsSkipSupported || !parser.SqlProvider.IsTakeSupported)
sql.Select.Take(parser.Convert(
sequence,
new SqlBinaryExpression(typeof(int), sql.Select.TakeValue, "-", sql.Select.SkipValue, Precedence.Additive)));
if (prevSkipValue != null)
sql.Select.Skip(parser.Convert(
sequence,
new SqlBinaryExpression(typeof(int), prevSkipValue, "+", sql.Select.SkipValue, Precedence.Additive)));
}
if (!parser.SqlProvider.TakeAcceptsParameter)
{
var p = sql.Select.SkipValue as SqlParameter;
if (p != null)
p.IsQueryParameter = false;
}
}
示例11: CanParse
public override bool CanParse(IParseContext context)
{
var fileExtensions = " " + context.Configuration.GetString(Constants.Configuration.BuildProjectContentFiles) + " ";
var extension = " " + Path.GetExtension(context.Snapshot.SourceFile.AbsoluteFileName) + " ";
return fileExtensions.IndexOf(extension, StringComparison.OrdinalIgnoreCase) >= 0;
}
示例12: CanParse
public override bool CanParse(IParseContext context)
{
var extension = Path.GetExtension(context.Snapshot.SourceFile.AbsoluteFileName).TrimStart('.').ToLowerInvariant();
var templateIdOrPath = context.Configuration.Get(Constants.Configuration.BuildProjectMediaTemplate + ":" + extension);
return templateIdOrPath != null;
}
示例13: PushChar
public override State PushChar (char c, IParseContext context, ref string rollback)
{
if (c == '<') {
}
return base.PushChar (c, context, ref rollback);
}
示例14: PushChar
public override State PushChar (char c, IParseContext context, ref string rollback)
{
if (c == '@' && context.StateTag == FREE) {
context.StateTag = TRANSITION;
return null;
} else if (context.StateTag == TRANSITION) {
rollback = String.Empty;
switch (c) {
case '{': // Code block @{
return CodeBlockState;
case '*': // Comment @*
return ServerCommentState;
case '(': // Explicit expression @(
return ExpressionState;
default:
// If char preceding @ was a letter or a digit, don't switch to expression, e.g. [email protected]
if (context.CurrentStateLength <= 2 || (!Char.IsLetterOrDigit (previousChar)
&& (Char.IsLetter (c) || c == '_'))) // Statement, directive or implicit expression
return SpeculativeState;
else
context.StateTag = FREE;
break;
}
}
previousChar = c;
return base.PushChar (c, context, ref rollback);
}
示例15: ValidateSchema
public override bool ValidateSchema(IParseContext context)
{
if (string.IsNullOrEmpty(SchemaFileName) || string.IsNullOrEmpty(SchemaNamespace))
{
return true;
}
var doc = RootElement?.Document;
if (doc == null)
{
return true;
}
XmlSchemaSet schema;
if (!Schemas.TryGetValue(SchemaNamespace, out schema))
{
schema = GetSchema(context, SchemaFileName, SchemaNamespace);
Schemas[SchemaNamespace] = schema;
}
if (schema == null)
{
return true;
}
var isValid = true;
ValidationEventHandler validateHandler = delegate(object sender, ValidationEventArgs args)
{
var length = 0;
var element = sender as XElement;
if (element != null)
{
length = element.Name.LocalName.Length;
}
switch (args.Severity)
{
case XmlSeverityType.Error:
context.Trace.TraceError(Msg.P1001, args.Message, SourceFile.AbsoluteFileName, new TextSpan(args.Exception.LineNumber, args.Exception.LinePosition, length));
isValid = false;
break;
case XmlSeverityType.Warning:
context.Trace.TraceWarning(Msg.P1002, args.Message, SourceFile.AbsoluteFileName, new TextSpan(args.Exception.LineNumber, args.Exception.LinePosition, length));
break;
}
};
try
{
doc.Validate(schema, validateHandler);
}
catch (Exception ex)
{
context.Trace.TraceError(Msg.P1003, Texts.The_file_does_not_contain_valid_XML, context.Snapshot.SourceFile.AbsoluteFileName, TextSpan.Empty, ex.Message);
}
return isValid;
}