本文整理汇总了C#中ParserContext.DefineDefaultCompilationErrorInfo方法的典型用法代码示例。如果您正苦于以下问题:C# ParserContext.DefineDefaultCompilationErrorInfo方法的具体用法?C# ParserContext.DefineDefaultCompilationErrorInfo怎么用?C# ParserContext.DefineDefaultCompilationErrorInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParserContext
的用法示例。
在下文中一共展示了ParserContext.DefineDefaultCompilationErrorInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParserFuncTest
public void ParserFuncTest()
{
Lexicon test = new Lexicon();
var ID = test.DefaultLexer.DefineToken(RE.Range('a', 'z').Concat(
(RE.Range('a', 'z') | RE.Range('0', '9')).Many()));
var NUM = test.DefaultLexer.DefineToken(RE.Range('0', '9').Many1());
var GREATER = test.DefaultLexer.DefineToken(RE.Symbol('>'));
var WHITESPACE = test.DefaultLexer.DefineToken(RE.Symbol(' ').Union(RE.Symbol('\t')));
var p1 = from i in ID
from g in GREATER
from g2 in GREATER.AsParser(true)
from n in NUM
select "A";
var p2 = from i in ID
from g in GREATER
from g2 in GREATER
from n in NUM
select "B";
var parser1 = p1 | p2;
var info = test.CreateScannerInfo();
ForkableScannerBuilder builder = new ForkableScannerBuilder(info);
builder.SetSkipTokens(WHITESPACE.Index);
var errorManager = new CompilationErrorManager();
var context = new ParserContext(errorManager, 1, 2);
context.DefineDefaultCompilationErrorInfo(0);
ParserRunner<string> runner = new ParserRunner<string>(parser1, context);
string source1 = "abc >> 123";
var sr1 = new SourceReader(new StringReader(source1));
ForkableScanner scanner1 = builder.Create(sr1);
var result1 = runner.Run(scanner1);
Assert.AreEqual("A", result1);
Assert.AreEqual(0, errorManager.Errors.Count);
string source2 = "abc > > 123";
var sr2 = new SourceReader(new StringReader(source2));
ForkableScanner scanner2 = builder.Create(sr2);
var result2 = runner.Run(scanner2);
Assert.AreEqual("B", result2);
Assert.AreEqual(0, errorManager.Errors.Count);
}
示例2: ParserCastTest
public void ParserCastTest()
{
Lexicon test = new Lexicon();
var ID = test.Lexer.DefineToken(RE.Range('a', 'z').Concat(
(RE.Range('a', 'z') | RE.Range('0', '9')).Many()));
var NUM = test.Lexer.DefineToken(RE.Range('0', '9').Many1());
var GREATER = test.Lexer.DefineToken(RE.Symbol('>'));
var WHITESPACE = test.Lexer.DefineToken(RE.Symbol(' ').Union(RE.Symbol('\t')));
var p1 = from i in ID
from g in GREATER
from g2 in GREATER
from n in NUM
select "hello";
var parser1 = p1.TryCast<object>();
var info = test.CreateScannerInfo();
ForkableScannerBuilder builder = new ForkableScannerBuilder(info);
builder.SetTriviaTokens(WHITESPACE.Index);
var errorManager = new CompilationErrorManager();
var context = new ParserContext(errorManager, 1, 2);
context.DefineDefaultCompilationErrorInfo(0);
var el = errorManager.CreateErrorList();
context.ErrorList = el;
ParserRunner<object> runner = new ParserRunner<object>(parser1, context);
string source1 = "abc >> 123";
var sr1 = new SourceReader(new StringReader(source1));
ForkableScanner scanner1 = builder.Create(sr1);
var result1 = runner.Run(scanner1);
Assert.AreEqual("hello", result1);
Assert.AreEqual(0, el.Count);
}