本文整理汇总了C#中ParseContext类的典型用法代码示例。如果您正苦于以下问题:C# ParseContext类的具体用法?C# ParseContext怎么用?C# ParseContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParseContext类属于命名空间,在下文中一共展示了ParseContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindDependency
private static void BindDependency(Type type, string dependencyName, string dependencyText, ParseContext parseContext)
{
var serviceConstructor = type.GetConstructor();
if (!serviceConstructor.isOk)
{
var message = string.Format("type [{0}] has ", type.FormatName());
throw new SimpleContainerException(message + serviceConstructor.errorMessage);
}
var formalParameter = serviceConstructor.value.GetParameters().SingleOrDefault(x => x.Name == dependencyName);
if (formalParameter == null)
{
const string message = "type [{0}] has no dependency [{1}]";
throw new SimpleContainerException(string.Format(message, type.FormatName(), dependencyName));
}
var targetType = formalParameter.ParameterType;
var underlyingType = Nullable.GetUnderlyingType(targetType);
if (underlyingType != null)
targetType = underlyingType;
IConvertible convertible = dependencyText;
object parsedValue;
try
{
parsedValue = convertible.ToType(targetType, CultureInfo.InvariantCulture);
}
catch (Exception e)
{
const string message = "can't parse [{0}.{1}] from [{2}] as [{3}]";
throw new SimpleContainerException(string.Format(message, type.FormatName(), dependencyName,
dependencyText, formalParameter.ParameterType.FormatName()), e);
}
parseContext.GetServiceBuilder(type).BindDependency(dependencyName, parsedValue);
}
示例2: Extract
public TextExtractionResult Extract(Func<Metadata, InputStream> streamFactory)
{
try
{
var parser = new AutoDetectParser();
var metadata = new Metadata();
var parseContext = new ParseContext();
//use the base class type for the key or parts of Tika won't find a usable parser
parseContext.set(typeof(Parser), parser);
var content = new System.IO.StringWriter();
var contentHandlerResult = new TextExtractorContentHandler(content);
using (var inputStream = streamFactory(metadata))
{
try
{
parser.parse(inputStream, contentHandlerResult, metadata, parseContext);
}
finally
{
inputStream.close();
}
}
return AssembleExtractionResult(content.ToString(), metadata);
}
catch (Exception ex)
{
throw new TextExtractionException("Extraction failed.", ex);
}
}
示例3: CreateScope
protected override IScope CreateScope(string name, IDictionary<string, string> data, ParseContext context)
{
var module = context.ModuleFactory.Create(name);
module.Load(data);
return new ModuleScope(module);
}
示例4: ParseNode
public override void ParseNode(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement)
{
XElement xElement = null;
HtmlAttribute htmlAttribute = htmlNode.Attributes["src"];
if (htmlAttribute != null)
{
MediaItem mediaItem = this.GetMediaItem(htmlAttribute.Value);
if (mediaItem != null)
{
string text;
string text2;
StyleParser.ParseDimensions(htmlNode, out text, out text2);
if (string.IsNullOrEmpty(text))
{
text = HtmlParseHelper.ParseDimensionValue(mediaItem.InnerItem["Width"], true);
}
if (string.IsNullOrEmpty(text2))
{
text2 = HtmlParseHelper.ParseDimensionValue(mediaItem.InnerItem["Height"], true);
}
xElement = this.CreateInlineElement(text, text2);
XElement content = this.CreateImageElement(htmlNode, mediaItem, parseContext, text, text2);
xElement.Add(content);
}
}
if (xElement != null)
{
resultElement.Add(xElement);
}
}
示例5: Main
static void Main(string[] args)
{
string[] IgnoreClassifiers = new string[] { "Whitespace"};
//var parser = DynamicParser.LoadFromMgx("M.mgx", "Microsoft.M.MParser");
var parser = DynamicParser.LoadFromMgx("Mg.mgx", "Microsoft.M.Grammar.MGrammar");
using (var sr = new StreamReader("rockfordauth.mg"))
using (var parseContext = new ParseContext(parser.Lexer,
parser.Parser,
parser.GraphBuilder,
ErrorReporter.Standard,
"test.M"))
{
var lexerReader = new LexerReader();
if (lexerReader.Open(parseContext, sr, true))
{
using (StreamWriter sw = new StreamWriter("output.html"))
{
sw.WriteLine("<html><head><style>body { background-color: #333333; color: white; font-family: Consolas; } .Delimiter { color: #ddd; } .Keyword { color: #6dcff6; font-weight: bold; } .Literal { color: #10cc20; }</style></head><body>");
bool eof = false;
while (true)
{
var tokens = lexerReader.Read();
foreach (var token in tokens)
{
object[] tokenInfos = parser.GetTokenInfo(token.Tag);
ClassificationAttribute classificationAttribute = null;
if (tokenInfos != null && tokenInfos.Length > 0)
{
classificationAttribute = tokenInfos[0] as ClassificationAttribute;
}
if (token.Description.Equals("EOF")) // TODO: Match against the EOF token if its public
{
eof = true;
break;
}
if (classificationAttribute != null &&
!IgnoreClassifiers.Contains(classificationAttribute.Classification))
{
sw.Write(string.Format("<span class=\"{0}\">{1}</span>",
classificationAttribute.Classification,
token.GetTextString()));
}
else
{
string output = token.GetTextString().Replace(" ", " ").Replace("\r", "<br />");
sw.Write(output);
}
}
if (eof)
break;
}
sw.WriteLine("</body></html>");
}
}
Console.WriteLine("Output generated.");
Console.ReadLine();
}
}
示例6: DoExecute
protected override void DoExecute(ParseContext context)
{
context.Input.Read(3);
context.UpdateCurrentChar();
OpenScope(new HorizontalRulerScope(), context);
CloseCurrentScope(context);
}
示例7: BinaryOperator
public BinaryOperator(Token Source, ParseContext.Operator Operator,
Node LHS, Node RHS)
: base(Source)
{
this.Operator = Operator;
this.LHS = LHS;
this.RHS = RHS;
}
示例8: DoExecute
protected override void DoExecute(ParseContext context)
{
if (!context.Scopes.ContainsType(ScopeTypeCache.DefinitionList)) {
OpenScope(new DefinitionListScope(), context);
}
OpenScope(new DefinitionTermScope(), context);
}
示例9: Token
public Token(TokenType type, string contents, int index, string text, ParseContext offset)
{
_type = type;
_contents = contents;
_index = index;
_text = text;
_offset = offset;
}
示例10: IsSatisfiedBy
public bool IsSatisfiedBy(ParseContext context)
{
if (chars.Length == 1) {
return chars[0] == context.CurrentChar;
}
return (char)context.CurrentChar + context.Input.Peek(chars.Length - 1) == chars;
}
示例11: CloseParagraphIfNecessary
protected void CloseParagraphIfNecessary(ParseContext context)
{
var scope = context.Scopes.PeekOrDefault();
if (scope == null || scope.GetType() != ScopeTypeCache.Paragraph) {
return;
}
CloseCurrentScope(context);
}
示例12: Select
public override void Select(StatementSink store) {
ParseContext context = new ParseContext();
context.source = new MyReader(sourcestream);
context.store = GetDupCheckSink(store);
context.namespaces = namespaces;
context.namedNode = new UriMap();
context.anonymous = new Hashtable();
context.meta = Meta;
while (ReadStatement(context)) { }
}
示例13: GetLanguage
protected string GetLanguage(ParseContext context)
{
var languageBuilder = new StringBuilder();
context.AdvanceInput();
while (context.CurrentChar != '\n' && context.CurrentChar != ButterflyStringReader.NoValue) {
languageBuilder.Append((char)context.CurrentChar);
context.AdvanceInput();
}
return languageBuilder.ToString();
}
示例14: Parse
public static Action<ContainerConfigurationBuilder> Parse(Type[] types, string fileName)
{
var parseItems = SplitWithTrim(File.ReadAllText(fileName).Replace("\r\n", "\n"), "\n").Select(Parse).ToArray();
var typesMap = types.ToLookup(x => x.Name);
return delegate(ContainerConfigurationBuilder builder)
{
var context = new ParseContext(builder.RegistryBuilder, typesMap);
foreach (var item in parseItems)
item(context);
};
}
示例15: Get
public ITagGroup Get(string group, ParseContext context=null)
{
if (_tags.ContainsKey(group))
{
return _tags[group];
}
if (context != null) {
throw TagException.UnkownTagGroup(group).Decorate(context);
}
return null;;
}