本文整理汇总了C#中StringParser.Char方法的典型用法代码示例。如果您正苦于以下问题:C# StringParser.Char方法的具体用法?C# StringParser.Char怎么用?C# StringParser.Char使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringParser
的用法示例。
在下文中一共展示了StringParser.Char方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Hello__World_StringParsing
public Hello__World_StringParsing()
{
var sp = new StringParser();
_parser = from hello in sp.String("Hello")
from comma in sp.Char(',')
from ws in sp.Whitespace()
from world in sp.String("World")
from period in sp.Char('.')
select hello;
}
示例2: CommandLineParser
public CommandLineParser()
{
var p = new StringParser();
Id = from ws in p.SkipWhitespace()
from c in p.Char(char.IsLetter)
from cs in p.Char(char.IsLetterOrDigit).ZeroOrMore()
select new string(c, 1) + new string(cs);
Key = from ws in p.SkipWhitespace()
from c in p.Char(char.IsLetter)
from cs in (p.Char(char.IsLetterOrDigit).Or(p.Char('.'))).ZeroOrMore()
select new string(c, 1) + new string(cs);
// Value = from v in (p.Char(x => !char.IsWhiteSpace(x))).ZeroOrMore()
// select new string(v);
Value = from v in (p.Char().Except(p.Whitespace())).ZeroOrMore()
select new string(v);
Definition = (from ws in p.SkipWhitespace()
from c in p.Char('-', '/')
from id in Id
from eq in p.Char(':', '=')
from v in Value
select new Definition(id, v));
}
示例3: Should_choose_the_greediest_one
public void Should_choose_the_greediest_one()
{
string subject = "Hello, World";
var p = new StringParser();
Parser<string, string> first = from x in p.String("Hello")
select x;
Assert.IsTrue(first.ParseString(subject).HasValue, "First did not match");
Parser<string, string> second = from x in p.String("Hello")
from y in p.Char(',')
from ws in p.Whitespace()
from z in p.String("World")
select x + z;
Assert.IsTrue(second.ParseString(subject).HasValue, "Second did not match");
Parser<string, string> parser = p.Longest(first, second);
Result<string, string> result = parser.ParseString(subject);
Assert.IsTrue(result.HasValue, "Neither matched");
Assert.AreEqual("HelloWorld", result.Value, "Longest parser should have matched");
}
示例4: Hello_StringParsing
public Hello_StringParsing()
{
var sp = new StringParser();
_parser = from x in sp.String("Hello")
from y in sp.Char(',')
select x;
}
示例5: Hello__StringParsing
public Hello__StringParsing()
{
var sp = new StringParser();
_parser = from x in sp.String("Hello")
from y in sp.Char(',')
from z in sp.Whitespace()
select x;
}
示例6: HelloOrHello_StringParsing
public HelloOrHello_StringParsing()
{
var sp = new StringParser();
_parser = (from hello in sp.String("Hello") select hello)
.Longest(from hello in sp.String("Hello")
from comma in sp.Char(',')
select hello);
}