本文整理汇总了C#中Tokenizer.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# Tokenizer.Parse方法的具体用法?C# Tokenizer.Parse怎么用?C# Tokenizer.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer.Parse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MatchPatterns
public IList<TokenResult<WhoisRecord>> MatchPatterns(WhoisRecord record)
{
var results = new List<TokenResult<WhoisRecord>>();
var patterns = GetEmbeddedPatterns();
foreach (var pattern in patterns)
{
var tokenizer = new Tokenizer();
var clone = record.Clone() as WhoisRecord;
var result = tokenizer.Parse(clone, pattern, record.Text);
results.Add(result);
}
return results.OrderBy(r => r.Replacements.Count).ToList();
}
示例2: IsARedirectRecord
/// <summary>
/// Determines whether a WHOIS record is a redirect record to another WHOIS server.
/// </summary>
/// <param name="record">The record.</param>
/// <param name="redirect">The redirect.</param>
/// <returns></returns>
public bool IsARedirectRecord(WhoisRecord record, out WhoisRedirect redirect)
{
var isARedirectRecord = false;
redirect = null;
if (record.Text.Contains("many different competing registrars"))
{
var reader = new EmbeddedPatternReader();
var pattern = reader.Read(GetType().Assembly, "Whois.Patterns.Redirects.Iana.txt");
var tokenizer = new Tokenizer();
var text = record.Text;
var tokenResult = tokenizer.Parse<WhoisRedirect>(pattern, text);
redirect = tokenResult.Value;
isARedirectRecord = true;
}
return isARedirectRecord;
}
示例3: TestMapAndReduce
public void TestMapAndReduce()
{
string xml = @"
<MapReduce>
<Map>
<MapRule Type = 'MapRuleOnT1IfTrue' />
</Map>
<Reduce>
<ReduceRule Type = 'ReduceRuleOnT1' />
<ReduceRule Type = 'AssignRuleOnT1' />
</Reduce>
</MapReduce>";
XDocument _xDoc = _xDoc = XDocument.Parse(xml);
XElement source = _xDoc.Element("MapReduce");
IMatcher rule = new TerminalRuleMatcher(new Pattern("Rule", TokenType.RULE));
IMatcher mapRule = new TerminalRuleMatcher(new Pattern("MapRule", TokenType.MAPRULE));
IMatcher reduceRule = new TerminalRuleMatcher(new Pattern("ReduceRule", TokenType.REDUCERULE));
IMatcher map = new ProductionMatcher(new Pattern("Map", TokenType.MAP));
IMatcher reduce = new ProductionMatcher(new Pattern("Reduce", TokenType.REDUCE));
IMatcher mapReduce = new ProductionMatcher(new Pattern("MapReduce", TokenType.MAPREDUCE));
List<Token> results = new List<Token>();
var t = new Tokenizer(source, results, rule, mapRule, reduceRule, map, reduce, mapReduce);
t.Parse();
Assert.AreEqual(TokenType.MAPREDUCE, results[0].TokenType);
Assert.AreEqual(TokenType.MAP, results[1].TokenType);
Assert.AreEqual(TokenType.MAPRULE, results[2].TokenType);
Assert.AreEqual(TokenType.EOF, results[3].TokenType);
Assert.AreEqual(TokenType.REDUCE, results[4].TokenType);
Assert.AreEqual(TokenType.REDUCERULE, results[5].TokenType);
Assert.AreEqual(TokenType.REDUCERULE, results[6].TokenType);
Assert.AreEqual(TokenType.EOF, results[7].TokenType);
Assert.AreEqual(TokenType.EOF, results[8].TokenType);
}
示例4: TestRule
public void TestRule()
{
string xml = @"
<Rule Type = 'IninValueOnT2' />";
XDocument _xDoc = _xDoc = XDocument.Parse(xml);
XElement source = _xDoc.Element("Rule");
IMatcher rule = new TerminalRuleMatcher(new Pattern("Rule", TokenType.RULE));
List<Token> results = new List<Token>();
var t = new Tokenizer(source, results, rule);
t.Parse();
Assert.IsTrue(rule.IsMatch(t));
Assert.AreEqual(TokenType.RULE, results[0].TokenType);
}
示例5: TestReduce
public void TestReduce()
{
string xml = @"
<Reduce>
<ReduceRule Type = 'ReduceRuleOnT1' />
<ReduceRule Type = 'AssignRuleOnT1' />
</Reduce>";
XDocument _xDoc = _xDoc = XDocument.Parse(xml);
XElement source = _xDoc.Element("Reduce");
IMatcher reduceRule = new TerminalRuleMatcher(new Pattern("ReduceRule", TokenType.REDUCERULE));
IMatcher reduce = new ProductionMatcher(new Pattern("Reduce", TokenType.REDUCE));
List<Token> results = new List<Token>();
var t = new Tokenizer(source, results, reduceRule, reduce);
t.Parse();
Assert.AreEqual(TokenType.REDUCE, results[0].TokenType);
Assert.AreEqual(TokenType.REDUCERULE, results[1].TokenType);
Assert.AreEqual(TokenType.REDUCERULE, results[2].TokenType);
Assert.AreEqual(TokenType.EOF, results[3].TokenType);
}
示例6: TestMapRulesTwoRules
public void TestMapRulesTwoRules()
{
string xml = @"
<Map>
<Rule Type = 'IninValueOnT2' />
<Rule Type = 'IninValueOnT2Add' />
</Map>";
XDocument _xDoc = _xDoc = XDocument.Parse(xml); XElement source = _xDoc.Element("Map");
IMatcher rule = new TerminalRuleMatcher(new Pattern("Rule", TokenType.RULE));
IMatcher map = new ProductionMatcher(new Pattern("Map", TokenType.MAP));
List<Token> results = new List<Token>();
var t = new Tokenizer(source, results, rule, map);
t.Parse();
Assert.AreEqual(TokenType.MAP, results[0].TokenType);
Assert.AreEqual(TokenType.RULE, results[1].TokenType);
Assert.AreEqual(TokenType.RULE, results[2].TokenType);
Assert.AreEqual(TokenType.EOF, results[3].TokenType);
}
示例7: Lookup
/// <summary>
/// Lookups the WHOIS server for the specified domain.
/// </summary>
/// <param name="domain">The domain.</param>
/// <returns></returns>
public IWhoisServer Lookup(string domain)
{
var tld = GetTld(domain);
var text = GetWhoisServerResponse(tld);
var tokenizer = new Tokenizer();
tokenizer.Options.ThrowExceptionOnMissingProperty = true;
var record = tokenizer.Parse<WhoisServerRecord>(Pattern, text);
record.Value.RawResponse = text;
return record.Value;
}