本文整理汇总了C#中TokenStream.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# TokenStream.Peek方法的具体用法?C# TokenStream.Peek怎么用?C# TokenStream.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TokenStream
的用法示例。
在下文中一共展示了TokenStream.Peek方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTokenOutliningAction
public override void GetTokenOutliningAction(TokenStream tokenStream, ref string outliningKey, ref OutliningNodeAction tokenAction)
{
string str = tokenStream.Peek().get_Key();
switch (str)
{
case null:
break;
case "OpenCurlyBraceToken":
outliningKey = "CodeBlock";
tokenAction = 1;
break;
case "CloseCurlyBraceToken":
outliningKey = "CodeBlock";
tokenAction = 2;
break;
default:
if (!(str == "MultiLineCommentStartToken"))
{
if (str == "MultiLineCommentEndToken")
{
outliningKey = "MultiLineComment";
tokenAction = 2;
}
}
else
{
outliningKey = "MultiLineComment";
tokenAction = 1;
}
break;
}
}
示例2: GetTokenOutliningAction
public override void GetTokenOutliningAction(TokenStream tokenStream, ref string outliningKey, ref OutliningNodeAction tokenAction)
{
Token token = tokenStream.Peek();
if ((token.Key == "OpenCurlyBraceToken" || token.Key == "CloseCurlyBraceToken") && g.Config.b_Ed_CodeFold == false)
return;
switch (token.Key) {
case "OpenCurlyBraceToken":
outliningKey = "CodeBlock";
tokenAction = OutliningNodeAction.Start;
break;
case "CloseCurlyBraceToken":
outliningKey = "CodeBlock";
tokenAction = OutliningNodeAction.End;
break;
case "RegionStartToken":
outliningKey = "CodeRegion";
tokenAction = OutliningNodeAction.Start;
break;
case "RegionEndToken":
outliningKey = "CodeRegion";
tokenAction = OutliningNodeAction.End;
break;
}
}
示例3: GetTokenOutliningAction
/////////////////////////////////////////////////////////////////////////////////////////////////////
// PUBLIC PROCEDURES
/////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Returns token parsing information for automatic outlining that determines if the current <see cref="IToken"/>
/// in the <see cref="TokenStream"/> starts or ends an outlining node.
/// </summary>
/// <param name="tokenStream">A <see cref="TokenStream"/> that is positioned at the <see cref="IToken"/> requiring outlining data.</param>
/// <param name="outliningKey">Returns the outlining node key to assign. A <see langword="null"/> should be returned if the token doesn't start or end a node.</param>
/// <param name="tokenAction">Returns the <see cref="OutliningNodeAction"/> to take for the token.</param>
public override void GetTokenOutliningAction(TokenStream tokenStream, ref string outliningKey, ref OutliningNodeAction tokenAction)
{
// Get the token
IToken token = tokenStream.Peek();
// See if the token starts or ends an outlining node
switch (token.Key)
{
case "MultiLineCommentStartToken":
outliningKey = "MultiLineComment";
tokenAction = OutliningNodeAction.Start;
break;
case "MultiLineCommentEndToken":
outliningKey = "MultiLineComment";
tokenAction = OutliningNodeAction.End;
break;
case "RegionStartToken":
outliningKey = "Region";
tokenAction = OutliningNodeAction.Start;
break;
case "EndRegionStartToken":
outliningKey = "Region";
tokenAction = OutliningNodeAction.End;
break;
}
}
示例4: GetTokenOutliningAction
public override void GetTokenOutliningAction(TokenStream tokenStream, ref string outliningKey, ref OutliningNodeAction tokenAction)
{
switch (tokenStream.Peek().get_Key())
{
case "OpenCurlyBraceToken":
outliningKey = "CodeBlock";
tokenAction = 1;
break;
case "CloseCurlyBraceToken":
outliningKey = "CodeBlock";
tokenAction = 2;
break;
case "MultiLineCommentStartToken":
outliningKey = "MultiLineComment";
tokenAction = 1;
break;
case "MultiLineCommentEndToken":
outliningKey = "MultiLineComment";
tokenAction = 2;
break;
case "XMLCommentStartToken":
outliningKey = "XMLComment";
tokenAction = 1;
break;
case "XMLCommentEndToken":
outliningKey = "XMLComment";
tokenAction = 2;
break;
case "RegionPreProcessorDirectiveStartToken":
outliningKey = "RegionPreProcessorDirective";
tokenAction = 1;
break;
case "EndRegionPreProcessorDirectiveEndToken":
outliningKey = "RegionPreProcessorDirective";
tokenAction = 2;
break;
}
}
示例5: GetTokenOutliningAction
public override void GetTokenOutliningAction(TokenStream tokenStream, ref string outliningKey, ref OutliningNodeAction tokenAction)
{
IToken token = tokenStream.Peek();
if ((token.get_Key() == "StartTagStartToken") && (token.get_DeclaringLexicalState().get_Key() == "StartTagState"))
{
outliningKey = "Region";
tokenAction = 1;
}
else if (((token.get_Key() == "StartTagEndToken") && (token.get_DeclaringLexicalState().get_Key() == "StartTagState")) && (tokenStream.get_Document().GetSubstring(token.get_TextRange()) == "/>"))
{
outliningKey = "Region";
tokenAction = 2;
}
else if ((token.get_Key() == "EndTagEndToken") && (token.get_DeclaringLexicalState().get_Key() == "EndTagState"))
{
outliningKey = "Region";
tokenAction = 2;
}
}
示例6: GetTokenOutliningAction
public override void GetTokenOutliningAction(TokenStream tokenStream, ref string outliningKey, ref OutliningNodeAction tokenAction)
{
// Get the token
IToken token = tokenStream.Peek();
if (token == null)
return;
if (string.IsNullOrEmpty(token.Key))
return;
// See if the token starts or ends an outlining node
switch (token.Key)
{
//case "OpenCurlyBraceToken":
// outliningKey = "CodeBlock";
// tokenAction = OutliningNodeAction.Start;
// break;
//case "CloseCurlyBraceToken":
// outliningKey = "CodeBlock";
// tokenAction = OutliningNodeAction.End;
// break;
case ReservedWordToken:
{
string tokenString = token.AutoCaseCorrectText;
if (string.IsNullOrEmpty(tokenString))
return;
switch (tokenString)
{
case "do":
//case "while": // while's also contain "do"
//case "for": // for's also contain "do"
case "if":
case "repeat":
case "function":
outliningKey = "CodeBlock";
tokenAction = OutliningNodeAction.Start;
break;
case "until":
case "end":
outliningKey = "CodeBlock";
tokenAction = OutliningNodeAction.End;
break;
}
}
break;
case MultiLineCommentStartToken:
outliningKey = "MultiLineComment";
tokenAction = OutliningNodeAction.Start;
break;
case MultiLineCommentEndToken:
outliningKey = "MultiLineComment";
tokenAction = OutliningNodeAction.End;
break;
}
}
示例7: GetFirstNonWhitespaceToken
private static IToken GetFirstNonWhitespaceToken(TokenStream tokenStream)
{
if (!tokenStream.FindNonWhitespace(false))
return null;
return tokenStream.Peek();
}
示例8: FindPosition
private static void FindPosition(TokenStream tokenStream, int offset)
{
tokenStream.Position = 0;
if (offset < 0)
return;
while (tokenStream.Position < tokenStream.Length)
{
IToken currentToken = tokenStream.Peek();
if (currentToken.StartOffset <= offset && offset < currentToken.StartOffset + currentToken.Length)
break;
else
tokenStream.Read();
}
}
示例9: ParseBlock
// YOU LEFT OFF HERE
// You were about to go through and document exactly what each indention variable meant more clearly.
private IList<Executable> ParseBlock(TokenStream tokens, int ownerIndention, bool start)
{
int blockIndention = tokens.PeekIndention();
if (start)
{
if (blockIndention != 0)
{
throw new ParserException(tokens.Peek(), "Unexpected indention");
}
}
else
{
if (blockIndention == -1)
{
// This indicates the code is on the same line. Parse one line.
// def foo(): return 42
Executable exec = this.Parse(tokens, false, -1);
return new List<Executable>() { exec };
}
if (blockIndention <= ownerIndention)
{
// No indention was found. But it is required.
throw new ParserException(tokens.Peek(), "Expected: indention");
}
}
int requiredIndention = blockIndention;
List<Executable> code = new List<Executable>();
while (tokens.HasMore)
{
int currentIndention = tokens.PeekIndention();
// any new indention should be handled by a recursive call
if (currentIndention > requiredIndention) throw new ParserException(tokens.Peek(), "Unexpected indention");
// if it's indented less than the required but more than the previous, then that's not right
// e.g.
// def foo()
// x = 1
// return x # this is wrong
if (currentIndention < requiredIndention && currentIndention > ownerIndention) throw new ParserException(tokens.Peek(), "Unexpected indention");
// def foo()
// x = 42
// y = 3.14 # this is no longer part of foo()
// start is excluded because when start is true, the owner indention and current indention are the same.
if (!start && currentIndention <= ownerIndention) return code;
tokens.SkipWhitespace();
if (tokens.HasMore)
{
code.Add(this.Parse(tokens, true, currentIndention));
}
else
{
return code;
}
}
return code;
}
示例10: ParseRootEntity
private static Expression ParseRootEntity(TokenStream tokens)
{
tokens.SkipWhitespace();
string next = tokens.PeekValue();
if (next == "True" || next == "False")
{
Token token = tokens.Pop();
return new BooleanConstant(token, next == "True");
}
else if (next == "None")
{
Token token = tokens.Pop();
return new NullConstant(token);
}
else if (next.StartsWith("'") || next.StartsWith("\""))
{
Token token = tokens.Pop();
int quoteSize = next.StartsWith("'''") || next.StartsWith("\"\"\"") ? 3 : 1;
return new StringConstant(token, Util.RemoveEscapeSequences(token, next.Substring(quoteSize, next.Length - quoteSize * 2)));
}
else if (next.StartsWith("r'") || next.StartsWith("r\""))
{
Token token = tokens.Pop();
int quoteSize = next.StartsWith("r'''") || next.StartsWith("r\"\"\"") ? 3 : 1;
return new StringConstant(token, next.Substring(quoteSize + 1, next.Length - quoteSize * 2 - 1));
}
else if (next == "(")
{
// Tuples or parentehsis
Token parenthesisToken = tokens.Pop();
List<Expression> parenthesisExpressions = new List<Expression>();
bool nextAllowed = true;
while (!tokens.PopIfPresent(")"))
{
if (!nextAllowed) tokens.PopExpected(")"); // throws
parenthesisExpressions.Add(Parse(tokens));
nextAllowed = tokens.PopIfPresent(",");
tokens.SkipWhitespace();
}
if (parenthesisExpressions.Count > 1 || nextAllowed)
{
return new InlineTuple(parenthesisToken, parenthesisExpressions);
}
else
{
return new ParenthesisGroup(parenthesisToken, parenthesisExpressions[0]);
}
}
else if (next == "[")
{
Token bracketToken = tokens.Pop();
List<Expression> listItems = new List<Expression>();
bool nextAllowed = true;
while (!tokens.PopIfPresent("]"))
{
if (!nextAllowed) tokens.PopExpected("]"); // throws
listItems.Add(Parse(tokens));
nextAllowed = tokens.PopIfPresent(",");
tokens.SkipWhitespace();
}
return new InlineList(bracketToken, listItems);
}
else if (next == "{")
{
Token braceToken = tokens.Pop();
List<Expression> dictionaryKeys = new List<Expression>();
List<Expression> dictionaryValues = new List<Expression>();
bool nextAllowed = true;
while (!tokens.PopIfPresent("}"))
{
if (!nextAllowed) tokens.PopExpected("}"); // throws
dictionaryKeys.Add(Parse(tokens));
tokens.PopExpected(":");
dictionaryValues.Add(Parse(tokens));
nextAllowed = tokens.PopIfPresent(",");
tokens.SkipWhitespace();
}
return new InlineDictionary(braceToken, dictionaryKeys, dictionaryValues);
}
else if (next.StartsWith("0x") || next.StartsWith("0o") || next.StartsWith("0X") || next.StartsWith("0O"))
{
Token integerToken = tokens.Pop();
int radix = next.ToLowerInvariant().StartsWith("0x") ? 16 : 8;
string stringValue = next.Substring(2);
if (stringValue.Length == 0)
{
throw new ParserException(integerToken, "Invalid base " + radix + " constant.");
}
int value = Util.ParseNumber(integerToken, stringValue, radix);
return new IntegerConstant(integerToken, value);
}
else if (next[0] >= '0' && next[0] <= '9')
{
Token numberToken = tokens.Pop();
if (next.Contains('.') || next.Contains('e') || next.Contains('E'))
{
double value = Util.ParseDouble(numberToken);
return new FloatConstant(numberToken, value);
//.........这里部分代码省略.........
示例11: GetTokenOutliningAction
public override void GetTokenOutliningAction(TokenStream tokenStream, ref string outliningKey, ref OutliningNodeAction tokenAction)
{
IToken token = tokenStream.Peek();
switch ((token.get_Language().get_Key() + "_" + token.get_Key()))
{
case "CSS_PropertyStartToken":
outliningKey = "CSS_PropertyBlock";
tokenAction = 1;
break;
case "CSS_PropertyEndToken":
outliningKey = "CSS_PropertyBlock";
tokenAction = 2;
break;
case "CSS_CommentStartToken":
outliningKey = "CSS_Comment";
tokenAction = 1;
break;
case "CSS_CommentEndToken":
outliningKey = "CSS_Comment";
tokenAction = 2;
break;
case "JScript_OpenCurlyBraceToken":
outliningKey = "JScript_CodeBlock";
tokenAction = 1;
break;
case "JScript_CloseCurlyBraceToken":
outliningKey = "JScript_CodeBlock";
tokenAction = 2;
break;
case "JScript_MultiLineCommentStartToken":
outliningKey = "JScript_MultiLineComment";
tokenAction = 1;
break;
case "JScript_MultiLineCommentEndToken":
outliningKey = "JScript_MultiLineComment";
tokenAction = 2;
break;
default:
if (tokenAction != 0)
{
if (token.HasFlag(0x40))
{
if ((tokenStream.get_Position() > 0) && (tokenStream.ReadReverse().get_LexicalState().get_Key() == "ASPDirectiveResponseWriteState"))
{
outliningKey = null;
tokenAction = 0;
}
}
else if (token.HasFlag(0x80))
{
tokenStream.Read();
if (!tokenStream.get_IsDocumentEnd() && (tokenStream.Peek().get_LexicalState().get_Key() == "ASPDirectiveResponseWriteState"))
{
outliningKey = null;
tokenAction = 0;
}
}
}
break;
}
}
示例12: GetTokenOutliningAction
public override void GetTokenOutliningAction(TokenStream tokenStream, ref string outliningKey, ref OutliningNodeAction tokenAction)
{
switch (tokenStream.Peek().get_Key())
{
case "XMLCommentStartToken":
outliningKey = "XMLComment";
tokenAction = 1;
break;
case "XMLCommentEndToken":
outliningKey = "XMLComment";
tokenAction = 2;
break;
case "SubReservedWordToken":
outliningKey = "SubBlock";
tokenAction = 1;
break;
case "EndSubReservedWordToken":
outliningKey = "SubBlock";
tokenAction = 2;
break;
case "FunctionReservedWordToken":
outliningKey = "FunctionBlock";
tokenAction = 1;
break;
case "EndFunctionReservedWordToken":
outliningKey = "FunctionBlock";
tokenAction = 2;
break;
case "PropertyReservedWordToken":
outliningKey = "PropertyBlock";
tokenAction = 1;
break;
case "EndPropertyReservedWordToken":
outliningKey = "PropertyBlock";
tokenAction = 2;
break;
case "ClassReservedWordToken":
outliningKey = "ClassBlock";
tokenAction = 1;
break;
case "EndClassReservedWordToken":
outliningKey = "ClassBlock";
tokenAction = 2;
break;
case "InterfaceReservedWordToken":
outliningKey = "InterfaceBlock";
tokenAction = 1;
break;
case "EndInterfaceReservedWordToken":
outliningKey = "InterfaceBlock";
tokenAction = 2;
break;
case "EnumReservedWordToken":
outliningKey = "EnumBlock";
tokenAction = 1;
break;
case "EndEnumReservedWordToken":
outliningKey = "EnumBlock";
tokenAction = 2;
break;
case "StructureReservedWordToken":
outliningKey = "StructureBlock";
tokenAction = 1;
break;
case "EndStructureReservedWordToken":
outliningKey = "StructureBlock";
tokenAction = 2;
break;
case "ModuleReservedWordToken":
outliningKey = "ModuleBlock";
tokenAction = 1;
break;
case "EndModuleReservedWordToken":
outliningKey = "ModuleBlock";
tokenAction = 2;
break;
case "NamespaceReservedWordToken":
outliningKey = "NamespaceBlock";
tokenAction = 1;
break;
case "EndNamespaceReservedWordToken":
//.........这里部分代码省略.........