本文整理汇总了C#中Antlr.Runtime.CommonTokenStream.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# CommonTokenStream.Seek方法的具体用法?C# CommonTokenStream.Seek怎么用?C# CommonTokenStream.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr.Runtime.CommonTokenStream
的用法示例。
在下文中一共展示了CommonTokenStream.Seek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReParseImpl
protected override void ReParseImpl()
{
// lex the entire document to get the set of identifiers we'll need to process
ITextSnapshot snapshot = TextBuffer.CurrentSnapshot;
var input = new SnapshotCharStream(snapshot, new Span(0, snapshot.Length));
var lexer = new AlloyLexer(input);
var tokens = new CommonTokenStream(lexer);
tokens.Fill();
/* Want to collect information from the following:
* - module (name)
* Want to provide navigation info for the following types:
* - sig
* - enum
* Want to provide navigation info for the following members:
* - decl (within a sigBody)
* - fun
* - pred
* - nameList (within an enumBody)
* Eventually should consider the following:
* - cmdDecl
* - fact
* - assert
*/
List<IToken> navigationKeywords = new List<IToken>();
while (tokens.LA(1) != CharStreamConstants.EndOfFile)
{
switch (tokens.LA(1))
{
case AlloyLexer.KW_MODULE:
case AlloyLexer.KW_SIG:
case AlloyLexer.KW_ENUM:
case AlloyLexer.KW_FUN:
case AlloyLexer.KW_PRED:
//case AlloyLexer.KW_ASSERT:
//case AlloyLexer.KW_FACT:
navigationKeywords.Add(tokens.LT(1));
break;
case CharStreamConstants.EndOfFile:
goto doneLexing;
default:
break;
}
tokens.Consume();
}
doneLexing:
List<IEditorNavigationTarget> navigationTargets = new List<IEditorNavigationTarget>();
AstParserRuleReturnScope<CommonTree, IToken> moduleTree = null;
CommonTreeAdaptor treeAdaptor = new CommonTreeAdaptor();
foreach (var token in navigationKeywords)
{
tokens.Seek(token.TokenIndex);
tokens.Consume();
NetworkInterpreter interpreter = CreateNetworkInterpreter(tokens);
while (interpreter.TryStepBackward())
{
if (interpreter.Contexts.Count == 0)
break;
if (interpreter.Contexts.All(context => context.BoundedStart))
break;
}
interpreter.CombineBoundedStartContexts();
#if false // since we're using the AlloyParser, I don't think we need this.
while (interpreter.TryStepForward())
{
if (interpreter.Contexts.Count == 0)
break;
if (interpreter.Contexts.All(context => context.BoundedEnd))
break;
}
#endif
foreach (var context in interpreter.Contexts)
{
switch (token.Type)
{
case AlloyLexer.KW_MODULE:
{
InterpretTraceTransition firstMatch = context.Transitions.FirstOrDefault(i => i.TokenIndex != null);
if (firstMatch == null)
continue;
tokens.Seek(firstMatch.TokenIndex.Value);
AlloyParser parser = new AlloyParser(tokens);
AstParserRuleReturnScope<CommonTree, IToken> result = parser.module();
if (result == null || parser.NumberOfSyntaxErrors > 0)
continue;
//.........这里部分代码省略.........