本文整理汇总了C#中CharStream.PeekNext方法的典型用法代码示例。如果您正苦于以下问题:C# CharStream.PeekNext方法的具体用法?C# CharStream.PeekNext怎么用?C# CharStream.PeekNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CharStream
的用法示例。
在下文中一共展示了CharStream.PeekNext方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PeekAndParse
public static bool PeekAndParse(CharStream stream)
{
if (stream.PeekNext() != '/' || stream.PeekNext(1) != '*')
{
return false;
}
Comment.Parse(stream);
return true;
}
示例2: Parse
public static string Parse(CharStream stream)
{
var startingPos = stream.Position;
try
{
var output = "";
var quote = Quote.Parse(stream);
char c;
while ((c = stream.PeekNext()) != '\0')
{
if (c == '\\')
{
output += stream.ForceReadNext();
} else if (Quote.Peek(stream, quote))
{
break; // un-escaped quote means we're ending the string
}
output += stream.ForceReadNext();
}
Quote.Parse(stream, quote);
return output;
} catch (Exception e)
{
string msg = String.Format(
"something went wrong parsing an <string_value> starting at {0}",
stream.ComputeDetailedPosition(startingPos));
throw new Exceptions.ParseException(msg, e);
}
}
示例3: PeekAndParse
public static bool PeekAndParse(CharStream stream, out AST.INode index)
{
if (stream.PeekNext() != '[')
{
index = null;
return false;
}
index = Index.Parse(stream);
return true;
}
示例4: PeekAndParse
public static bool PeekAndParse(CharStream stream, out AST.INode expression)
{
if (stream.PeekNext() == '(' || Primary.Peek(stream))
{
expression = Parenthesis.Parse(stream);
return true;
}
expression = null;
return false;
}
示例5: PeekAndParse
public static bool PeekAndParse(CharStream stream, out AST.HashValue.Item item)
{
if (stream.PeekNext() == '*' || Identifier.Peek(stream))
{
item = HashItem.Parse(stream);
return true;
}
item = null;
return false;
}
示例6: PeekAndParse
public static bool PeekAndParse(
CharStream stream,
string identifier, Internal.LocaleContext.Builder builder)
{
if (stream.PeekNext() != '(')
{
return false;
}
Macro.Parse(stream, identifier, builder);
return true;
}
示例7: PeekAndParse
public static bool PeekAndParse(
CharStream stream, AST.INode member,
out AST.INode expression)
{
if (stream.PeekNext() == '(')
{
expression = Call.Parse(stream, member);
return true;
}
expression = null;
return false;
}
示例8: Peek
public static bool Peek(CharStream stream, Quote.Info quote = null)
{
if (quote != null)
{
var raw = quote.ToString();
var output = stream.PeekNextRange(raw.Length);
return raw == output;
}
char next = stream.PeekNext();
return next == '\'' || next == '\"';
}
示例9: Peek
public static bool Peek(CharStream stream)
{
return stream.PeekNext() == '$';
}
示例10: Parse
public static AST.INode Parse(CharStream stream)
{
var startingPos = stream.Position;
try
{
// Parse the quote and store that in the AST of the stringValue
var quote = Quote.Parse(stream);
var value = new AST.StringValue(quote);
AST.INode expression;
char c;
// Trim starting space
WhiteSpace.Parse(stream, true);
// as long as we have more characters left
// we'll keep reading, and break from within this loop body
// when we reached the same quote that started this entire parser logic.
while ((c = stream.PeekNext()) != '\0')
{
if (c == '\\')
{
// skip the escape character && read the next one
stream.Skip();
c = stream.PeekNext();
if (c == '\\' || c == '{' || c == '}' || c == '\'' || c == '"')
{
c = stream.ForceReadNext();
value.appendChar(c);
} else if (c == 'u')
{
// skip the starter character
stream.Skip();
// try to read unicode character
value.appendChar(ReadUnicodeCharacter(stream));
} else
{
var msg = String.Format(
"character \\{0} is not a valid escape character", c);
throw stream.CreateException(msg);
}
// unicode characters are also supported in the classical U+xxxxxx notation
} else if (c == 'U' && stream.PeekNext(1) == '+')
{
// skip the starter characters
stream.Skip(2);
// try to read unicode character
value.appendChar(ReadUnicodeCharacter(stream));
} else if (c == '\n' || c == '\r') // newlines get converted to a space
{
stream.Skip();
var lc = value.LastCharacter;
// we add this dummy character, such that we wouldn't add a space in
// languages that don't use a space in general, such as chinese.
if (!Char.IsWhiteSpace(lc) && lc != AST.StringValue.DummyNewlineWhitespaceCharacter)
value.appendChar(AST.StringValue.DummyNewlineWhitespaceCharacter);
} else
{
if (Quote.Peek(stream, quote))
{
break; // un-escaped quote means we're ending the string
} else if (Expander.PeekAndParse(stream, out expression))
{
value.appendExpression(expression);
} else
{
c = stream.ForceReadNext();
var lc = value.LastCharacter;
if(!Char.IsWhiteSpace(c)
|| (lc != AST.StringValue.DummyNewlineWhitespaceCharacter
&& !Char.IsWhiteSpace(lc)))
value.appendChar(c);
}
}
}
// Eventually we expect exactly the same string back
Quote.Parse(stream, quote);
return value;
} catch (Exception e)
{
string msg = String.Format(
"something went wrong parsing an <string_value> starting at {0}",
stream.ComputeDetailedPosition(startingPos));
throw new Exceptions.ParseException(msg, e);
}
}