本文整理汇总了C#中Lexer.Read方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.Read方法的具体用法?C# Lexer.Read怎么用?C# Lexer.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer
的用法示例。
在下文中一共展示了Lexer.Read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public override ParseTree Parse(Lexer lexer, ParserState state)
{
lexer.Whitespace(state.RuntimeState);
int start = lexer.Position;
state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), range.ToString());
char character = lexer.Peek();
if (!range.Contains(character))
{
lexer.ErrorStrings[start].Add(range.ToString());
state.RuntimeState.Runtime.ParseTrace.No(this,
lexer.SourceFrom(start), TextEscape.Quote(character));
return ParseTree.No;
}
lexer.Read();
state.RuntimeState.Runtime.ParseTrace.Yes(this,
lexer.SourceFrom(start), TextEscape.Quote(character));
if (state.BuildTextNodes)
return new ParseTree(Convert.ToString(character));
else
return ParseTree.Yes;
}
示例2: Parse
public override ParseTree Parse(Lexer lexer, ParserState state)
{
lexer.Whitespace(state.RuntimeState);
int start = lexer.Position;
state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "[]");
char character = lexer.Peek();
if (character == '\0')
{
state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start), "End of source");
return ParseTree.No;
}
lexer.Read();
state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start), TextEscape.Quote(character));
if (state.BuildTextNodes)
return new ParseTree(Convert.ToString(character));
else
return ParseTree.Yes;
}
示例3: Test
private void Test(string source, params Lexem[] expected)
{
using (var reader = new StringReader(source))
{
var lexer = new Lexer(reader);
var result = lexer.Read().ToList();
Assert.IsTrue(expected.SequenceEqual(result));
}
}
示例4: Main
//.........这里部分代码省略.........
//lexer.Steps.Add(new OneOfStep<LexerContext>("Article")
// .Add(new LexerStringStep("The"))
// .Add(new LexerStringStep("Th"))
// .Add(new LexerStringStep("A")))
// .Add(new LexerRegexStep("TestRegex", new Regex(@"[A-Za-z]")))
// //.Add(new OneOrMoreStep<LexerContext>("TestRegexes", lexer.Steps.NamedStep("TestRegex")))
// .Add(new ANotBStep<LexerContext>("NotC", lexer.Steps.NamedStep("TestRegex"), new LexerStringStep("c")))
// .Add(new OneOfStep<LexerContext>("TestRegexes")
// .Add(new SequenceStep<LexerContext>()
// .Add(lexer.Steps.NamedStep("TestRegexes"))
// .Add(lexer.Steps.NamedStep("NotC")))
// .Add(lexer.Steps.NamedStep("NotC")))
// .Add(new LexerRegexStep("SpaceCharacter", new Regex(@"\s")))
// .Add(new OneOrMoreStep<LexerContext>("SpaceCharacters", lexer.Steps.NamedStep("SpaceCharacter")))
// .Add(new SequenceStep<LexerContext>("QualifiedWord")
// .Add(lexer.Steps.NamedStep("Article"))
// .Add(lexer.Steps.NamedStep("SpaceCharacters"))
// .Add(lexer.Steps.NamedStep("TestRegexes")))
// .RootStepName = "QualifiedWord";
StringBuilder sb = new StringBuilder();
Console.WriteLine("Enter input lines ([email protected] to end):");
while (true) {
Console.Write("> ");
string line = Console.ReadLine();
if (line == "\0") break;
sb.AppendLine(line);
}
string input = sb.ToString();
Console.WriteLine($"Input: {input.ToLiteral()}");
Symbol[] symbols;
byte[] bytes = Encoding.Default.GetBytes(input);
using (Stream stream = new MemoryStream(bytes))
symbols = lexer.Read(stream);
Console.WriteLine($"Result: [{string.Join<Symbol>(", ", symbols)}]");
Console.WriteLine($"Compct: [{string.Join(", ", (from symbol in symbols select symbol.ToStringCompact()))}]");
Console.WriteLine("Multiline: " + string.Join(",\n", (from symbol in symbols
select symbol.ToStringMultiline())));
Console.WriteLine("--- Performance test ---");
Console.WriteLine("Enter test duration in seconds (0 to skip):");
double seconds;
while (true) {
Console.Write("> ");
bool success = double.TryParse(Console.ReadLine().Trim(), out seconds);
if (success) break;